From henrik.alsing.pedersen at mosek.com Mon Feb 21 14:38:12 2011 From: henrik.alsing.pedersen at mosek.com (Henrik Alsing Pedersen) Date: Mon, 21 Feb 2011 14:38:12 +0100 Subject: [Matrix-commits] Using the Package Matrix In-Reply-To: References: Message-ID: I thought I would give the mailing list a try, since there hasn't been much activity on the project homepage https://r-forge.r-project.org/projects/matrix/ This mail will summarize my findings in a more digestible form. ************************************ I am writing a package and want my users to be able to input double-typed matrices from the Matrix package, in either the triplet or column-compressed format. However, the Matrix package currently offers no way to test if a certain SEXP object qualifies as either of the two formats. Thus I suggest -- see Feature Requests, thread #1263 -- to construct an externally available function along the lines bool Matrix_isclass_csparse(SEXP x) { ? ?return Matrix_check_class_etc(x, csparse_CLASSES) >= 0; } where csparse_CLASSES would currently be the following char array const char *csparse_CLASSES[] = {"dgCMatrix", "dsCMatrix", "dtCMatrix", ?"lgCMatrix", "lsCMatrix", "ltCMatrix", ?"ngCMatrix", "nsCMatrix", "ntCMatrix", ?"zgCMatrix", "zsCMatrix", "ztCMatrix", ""}; Notice that this is no different than what is already done internally, e.g. "as_cholmod_sparse", line 221-227 in chm_common.c. With this function I would have the opportunity to test a SEXP object, with no hardcoded knowledge of the supported types of the Matrix package, and see whether I should make a call to "as_cholmod_sparse" or "as_cholmod_triplet". If I just went ahead and called any one of these functions directly, a wrong guess would give rise to an Rf_error terminating the process. Notice also the bug pointed out in "as_cholmod_triplet" in that thread.. Another bug I found -- see Bugs, thread #1283 -- concerns what I think is a portability problem. In the function "as_cholmod_sparse", line 235 in chm_common.c, the Matrix package assumes that a 'long' has the same size as a 'int', as it defines the choldmod itype as CHOLMOD_LONG independently of the actual data. In that thread I give an example of what happens when I interpret that data as type 'long' giving erroneous output. Kind regards Henrik