00001 #ifndef MATRIX_MUTILS_H
00002 #define MATRIX_MUTILS_H
00003
00004 #include <Rdefines.h>
00005 #include <Rconfig.h>
00006 #include "cblas.h"
00007
00008
00009 #define RMJ CblasRowMajor
00010 #define CMJ CblasColMajor
00011 #define NTR CblasNoTrans
00012 #define TRN CblasTrans
00013 #define CTR CblasConjTrans
00014 #define UPP CblasUpper
00015 #define LOW CblasLower
00016 #define NUN CblasNonUnit
00017 #define UNT CblasUnit
00018 #define LFT CblasLeft
00019 #define RGT CblasRight
00020
00021 char norm_type(char *typstr);
00022 char rcond_type(char *typstr);
00023 double get_double_by_name(SEXP obj, char *nm);
00024 SEXP set_double_by_name(SEXP obj, double val, char *nm);
00025 SEXP as_det_obj(double val, int log, int sign);
00026 SEXP get_factors(SEXP obj, char *nm);
00027 SEXP set_factors(SEXP obj, SEXP val, char *nm);
00028 SEXP dgCMatrix_set_Dim(SEXP x, int nrow);
00029 int csc_unsorted_columns(int ncol, const int p[], const int i[]);
00030 void csc_sort_columns(int ncol, const int p[], int i[], double x[]);
00031 SEXP triple_as_SEXP(int nrow, int ncol, int nz,
00032 const int Ti [], const int Tj [], const double Tx [],
00033 char *Rclass);
00034 SEXP csc_check_column_sorting(SEXP A);
00035 void csc_components_transpose(int m, int n, int nnz,
00036 const int xp[], const int xi[],
00037 const double xx[],
00038 int ap[], int ai[], double ax[]);
00039 void ssc_symbolic_permute(int n, int upper, const int perm[],
00040 int Ap[], int Ai[]);
00041 double *nlme_symmetrize(double *a, const int nc);
00042 void nlme_check_Lapack_error(int info, const char *laName);
00043 SEXP nlme_replaceSlot(SEXP obj, SEXP names, SEXP value);
00044 SEXP nlme_weight_matrix_list(SEXP MLin, SEXP wts, SEXP adjst, SEXP MLout);
00045 SEXP Matrix_make_named(int TYP, char **names);
00046
00047
00048 extern
00049 #include "Syms.h"
00050
00051
00052 #define AZERO(x, n) {int _I_, _SZ_ = (n); for(_I_ = 0; _I_ < _SZ_; _I_++) (x)[_I_] = 0;}
00053
00069 static R_INLINE
00070 SEXP ALLOC_SLOT(SEXP obj, SEXP nm, SEXPTYPE type, int length)
00071 {
00072 SEXP val = allocVector(type, length);
00073
00074 SET_SLOT(obj, nm, val);
00075 return val;
00076 }
00077
00088 static R_INLINE
00089 int* expand_column_pointers(int ncol, const int mp[], int mj[])
00090 {
00091 int j;
00092 for (j = 0; j < ncol; j++) {
00093 int j2 = mp[j+1], jj;
00094 for (jj = mp[j]; jj < j2; jj++) mj[jj] = j;
00095 }
00096 return mj;
00097 }
00098
00099
00115 static R_INLINE int
00116 check_csc_index(const int p[], const int i[], int row, int col, int missing)
00117 {
00118 int k, k2 = p[col + 1];
00119
00120 for (k = p[col]; k < k2; k++) if (i[k] == row) return k;
00121 if (!missing)
00122 error("row %d and column %d not defined in rowind and colptr",
00123 row, col);
00124 return missing;
00125 }
00126
00127 SEXP alloc3Darray(SEXPTYPE mode, int nrow, int ncol, int nface);
00128
00138 static R_INLINE
00139 int Lind(int k, int i)
00140 {
00141 if (k < i) error("Lind(k = %d, i = %d) must have k >= i", k, i);
00142 return (k * (k + 1))/2 + i;
00143 }
00144
00153 static R_INLINE
00154 int match_mat_dims(const int xd[], const int yd[])
00155 {
00156 return xd[0] == yd[0] && xd[1] == yd[1];
00157 }
00158
00159 double *expand_csc_column(double *dest, int m, int j,
00160 const int Ap[], const int Ai[], const double Ax[]);
00161
00162 #endif
00163