Main Page | Directories | File List | Globals

Mutils.h

Go to the documentation of this file.
00001 #ifndef MATRIX_MUTILS_H
00002 #define MATRIX_MUTILS_H
00003 
00004 #ifdef __cplusplus
00005 extern "C" {
00006 #endif
00007 
00008 #include <Rdefines.h>
00009 #include <Rconfig.h>
00010 #include <R.h>  /* to include Rconfig.h */
00011 
00012 #ifdef ENABLE_NLS
00013 #include <libintl.h>
00014 #define _(String) dgettext ("Matrix", String)
00015 #else
00016 #define _(String) (String)
00017 #endif
00018 
00019 /* enum constants from cblas.h and some short forms */
00020 enum CBLAS_ORDER {CblasRowMajor=101, CblasColMajor=102};
00021 enum CBLAS_TRANSPOSE {CblasNoTrans=111, CblasTrans=112, CblasConjTrans=113};
00022 enum CBLAS_UPLO {CblasUpper=121, CblasLower=122};
00023 enum CBLAS_DIAG {CblasNonUnit=131, CblasUnit=132};
00024 enum CBLAS_SIDE {CblasLeft=141, CblasRight=142};
00025 #define RMJ CblasRowMajor
00026 #define CMJ CblasColMajor
00027 #define NTR CblasNoTrans
00028 #define TRN CblasTrans
00029 #define CTR CblasConjTrans
00030 #define UPP CblasUpper
00031 #define LOW CblasLower
00032 #define NUN CblasNonUnit
00033 #define UNT CblasUnit
00034 #define LFT CblasLeft
00035 #define RGT CblasRight
00036 
00037 char norm_type(char *typstr);
00038 char rcond_type(char *typstr);
00039 double get_double_by_name(SEXP obj, char *nm);
00040 SEXP set_double_by_name(SEXP obj, double val, char *nm);
00041 SEXP as_det_obj(double val, int log, int sign);
00042 SEXP get_factors(SEXP obj, char *nm);
00043 SEXP set_factors(SEXP obj, SEXP val, char *nm);
00044 SEXP dgCMatrix_set_Dim(SEXP x, int nrow);
00045 int csc_unsorted_columns(int ncol, const int p[], const int i[]);
00046 void csc_sort_columns(int ncol, const int p[], int i[], double x[]);
00047 SEXP triple_as_SEXP(int nrow, int ncol, int nz,
00048                     const int Ti [], const int Tj [], const double Tx [],
00049                     char *Rclass);
00050 SEXP csc_check_column_sorting(SEXP A);
00051 void csc_components_transpose(int m, int n, int nnz,
00052                               const int xp[], const int xi[],
00053                               const double xx[],
00054                               int ap[], int ai[], double ax[]);
00055 void ssc_symbolic_permute(int n, int upper, const int perm[],
00056                           int Ap[], int Ai[]);
00057 double *nlme_symmetrize(double *a, const int nc);
00058 void nlme_check_Lapack_error(int info, const char *laName);
00059 SEXP nlme_replaceSlot(SEXP obj, SEXP names, SEXP value);
00060 SEXP nlme_weight_matrix_list(SEXP MLin, SEXP wts, SEXP adjst, SEXP MLout);
00061 SEXP Matrix_make_named(int TYP, char **names);
00062                                 /* stored pointers to symbols */
00063                                 /* initialized in R_init_Matrix */
00064 extern
00065 #include "Syms.h"
00066 
00067 /* zero an array */
00068 #define AZERO(x, n) {int _I_, _SZ_ = (n); for(_I_ = 0; _I_ < _SZ_; _I_++) (x)[_I_] = 0;}
00069 
00085 static R_INLINE
00086 SEXP ALLOC_SLOT(SEXP obj, SEXP nm, SEXPTYPE type, int length)
00087 {
00088     SEXP val = allocVector(type, length);
00089 
00090     SET_SLOT(obj, nm, val);
00091     return val;
00092 }
00093 
00104 static R_INLINE
00105 int* expand_column_pointers(int ncol, const int mp[], int mj[])
00106 {
00107     int j;
00108     for (j = 0; j < ncol; j++) {
00109         int j2 = mp[j+1], jj;
00110         for (jj = mp[j]; jj < j2; jj++) mj[jj] = j;
00111     }
00112     return mj;
00113 }
00114 
00115 
00131 static R_INLINE int
00132 check_csc_index(const int p[], const int i[], int row, int col, int missing)
00133 {
00134     int k, k2 = p[col + 1];
00135                                 /* linear search - perhaps replace by bsearch */
00136     for (k = p[col]; k < k2; k++) if (i[k] == row) return k;
00137     if (!missing)
00138         error("row %d and column %d not defined in rowind and colptr",
00139               row, col);
00140     return missing;
00141 }
00142 
00143 SEXP alloc3Darray(SEXPTYPE mode, int nrow, int ncol, int nface);
00144 
00154 static R_INLINE
00155 int Lind(int k, int i)
00156 {
00157     if (k < i) error("Lind(k = %d, i = %d) must have k >= i", k, i);
00158     return (k * (k + 1))/2 + i;
00159 }
00160 
00169 static R_INLINE
00170 int match_mat_dims(const int xd[], const int yd[])
00171 {
00172     return xd[0] == yd[0] && xd[1] == yd[1];
00173 }
00174 
00175 double *expand_csc_column(double *dest, int m, int j,
00176                           const int Ap[], const int Ai[], const double Ax[]);
00177 
00185 static R_INLINE void
00186 int_permute(int i[], int n, const int perm[])
00187 {
00188     int j;
00189     for (j = 0; j < n; j++) i[j] = perm[i[j]];
00190 }
00191 
00199 static R_INLINE void
00200 make_upper_triangular(int i[], int j[], int nnz)
00201 {
00202     int k;
00203     for (k = 0; k < nnz; k++) {
00204         if (i[k] > j[k]) {
00205             int tmp = i[k];
00206             i[k] = j[k];
00207             j[k] = tmp;
00208         }
00209     }
00210 }
00211 
00212 void make_array_triangular(double *x, SEXP from);
00213 
00214 #ifdef __cplusplus
00215 }
00216 #endif
00217 
00218 #endif /* MATRIX_MUTILS_H_ */

Generated on Tue Mar 1 16:58:10 2005 for Matrix by  doxygen 1.4.1