SCM

SCM Repository

[matrix] Diff of /pkg/src/Mutils.h
ViewVC logotype

Diff of /pkg/src/Mutils.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 164, Fri May 14 21:00:04 2004 UTC revision 572, Fri Feb 25 14:11:54 2005 UTC
# Line 2  Line 2 
2  #define MATRIX_MUTILS_H  #define MATRIX_MUTILS_H
3    
4  #include <Rdefines.h>  #include <Rdefines.h>
5    #include <Rconfig.h>
6    #include "cblas.h"
7    
8    /* short forms of some enum constants from cblas.h */
9    #define RMJ CblasRowMajor
10    #define CMJ CblasColMajor
11    #define NTR CblasNoTrans
12    #define TRN CblasTrans
13    #define CTR CblasConjTrans
14    #define UPP CblasUpper
15    #define LOW CblasLower
16    #define NUN CblasNonUnit
17    #define UNT CblasUnit
18    #define LFT CblasLeft
19    #define RGT CblasRight
20    
21  char norm_type(char *typstr);  char norm_type(char *typstr);
22  char rcond_type(char *typstr);  char rcond_type(char *typstr);
23  double get_double_by_name(SEXP obj, char *nm);  double get_double_by_name(SEXP obj, char *nm);
24  SEXP set_double_by_name(SEXP obj, double val, char *nm);  SEXP set_double_by_name(SEXP obj, double val, char *nm);
25  SEXP as_det_obj(double val, int log, int sign);  SEXP as_det_obj(double val, int log, int sign);
26  SEXP get_factorization(SEXP obj, char *nm);  SEXP get_factors(SEXP obj, char *nm);
27  SEXP set_factorization(SEXP obj, SEXP val, char *nm);  SEXP set_factors(SEXP obj, SEXP val, char *nm);
28  SEXP cscMatrix_set_Dim(SEXP x, int nrow);  SEXP dgCMatrix_set_Dim(SEXP x, int nrow);
29  int csc_unsorted_columns(int ncol, const int p[], const int i[]);  int csc_unsorted_columns(int ncol, const int p[], const int i[]);
30  void csc_sort_columns(int ncol, const int p[], int i[], double x[]);  void csc_sort_columns(int ncol, const int p[], int i[], double x[]);
31  SEXP triple_as_SEXP(int nrow, int ncol, int nz,  SEXP triple_as_SEXP(int nrow, int ncol, int nz,
# Line 21  Line 36 
36                                const int xp[], const int xi[],                                const int xp[], const int xi[],
37                                const double xx[],                                const double xx[],
38                                int ap[], int ai[], double ax[]);                                int ap[], int ai[], double ax[]);
 void triplet_to_col(int nrow, int ncol, int nz,  
                     const int Ti [], const int Tj [], const double Tx [],  
                     int Ap [], int Ai [], double Ax []);  
39  void ssc_symbolic_permute(int n, int upper, const int perm[],  void ssc_symbolic_permute(int n, int upper, const int perm[],
40                            int Ap[], int Ai[]);                            int Ap[], int Ai[]);
41  double *nlme_symmetrize(double *a, const int nc);  double *nlme_symmetrize(double *a, const int nc);
42  void nlme_check_Lapack_error(int info, const char *laName);  void nlme_check_Lapack_error(int info, const char *laName);
 double *  
 LMEgradient(const double* factor, const double* A, const int nlev,  
             const int nc, const double* pdgradient, const int plen,  
             double* value);  
43  SEXP nlme_replaceSlot(SEXP obj, SEXP names, SEXP value);  SEXP nlme_replaceSlot(SEXP obj, SEXP names, SEXP value);
44  SEXP nlme_weight_matrix_list(SEXP MLin, SEXP wts, SEXP adjst, SEXP MLout);  SEXP nlme_weight_matrix_list(SEXP MLin, SEXP wts, SEXP adjst, SEXP MLout);
45    SEXP Matrix_make_named(int TYP, char **names);
46                                  /* stored pointers to symbols */                                  /* stored pointers to symbols */
47                                  /* initialized in Matrix_init */                                  /* initialized in R_init_Matrix */
48  extern SEXP  extern
49      Matrix_DSym,  #include "Syms.h"
50      Matrix_DIsqrtSym,  
51      Matrix_DimSym,  /* zero an array */
52      Matrix_GpSym,  #define AZERO(x, n) {int _I_, _SZ_ = (n); for(_I_ = 0; _I_ < _SZ_; _I_++) (x)[_I_] = 0;}
53      Matrix_LiSym,  
54      Matrix_LpSym,  /**
55      Matrix_LxSym,   * Allocate an SEXP of given type and length, assign it as slot nm in
56      Matrix_OmegaSym,   * the object, and return the SEXP.  The validity of this function
57      Matrix_ParentSym,   * depends on SET_SLOT not duplicating val when NAMED(val) == 0.  If
58      Matrix_RXXSym,   * this behavior changes then ALLOC_SLOT must use SET_SLOT followed by
59      Matrix_RZXSym,   * GET_SLOT to ensure that the value returned is indeed the SEXP in
60      Matrix_XtXSym,   * the slot.
61      Matrix_ZtXSym,   *
62      Matrix_bVarSym,   * @param obj object in which to assign the slot
63      Matrix_devianceSym,   * @param nm name of the slot, as an R name object
64      Matrix_devCompSym,   * @param type type of SEXP to allocate
65      Matrix_diagSym,   * @param length length of SEXP to allocate
66      Matrix_iSym,   *
67      Matrix_ipermSym,   * @return SEXP of given type and length assigned as slot nm in obj
68      Matrix_jSym,   */
69      Matrix_matSym,  static R_INLINE
70      Matrix_ncSym,  SEXP ALLOC_SLOT(SEXP obj, SEXP nm, SEXPTYPE type, int length)
71      Matrix_pSym,  {
72      Matrix_permSym,      SEXP val = allocVector(type, length);
73      Matrix_statusSym,  
74      Matrix_uploSym,      SET_SLOT(obj, nm, val);
75      Matrix_xSym,      return val;
76      Matrix_zSym;  }
77    
78    /**
79     * Expand the column pointers in the array mp into a full set of column indices
80     * in the array mj.
81     *
82     * @param ncol number of columns
83     * @param mp column pointer vector of length ncol + 1
84     * @param mj vector of length mp[ncol] - 1 to hold the result
85     *
86     * @return mj
87     */
88    static R_INLINE
89    int* expand_column_pointers(int ncol, const int mp[], int mj[])
90    {
91        int j;
92        for (j = 0; j < ncol; j++) {
93            int j2 = mp[j+1], jj;
94            for (jj = mp[j]; jj < j2; jj++) mj[jj] = j;
95        }
96        return mj;
97    }
98    
 #endif  
99    
100    /**
101     * Return the linear index of the (row, col) entry in a csc structure.
102     * If the entry is not found and missing is 0 an error is signaled;
103     * otherwise the missing value is returned.
104     *
105     * @param p vector of column pointers
106     * @param i vector of row indices
107     * @param row row index
108     * @param col column index
109     * @param missing the value to return is the row, col entry does not
110     * exist.  If this is zero and the row, col entry does not exist an
111     * error is signaled.
112     *
113     * @return index of element at (row, col) if it exists, otherwise missing
114     */
115    static R_INLINE int
116    check_csc_index(const int p[], const int i[], int row, int col, int missing)
117    {
118        int k, k2 = p[col + 1];
119                                    /* linear search - perhaps replace by bsearch */
120        for (k = p[col]; k < k2; k++) if (i[k] == row) return k;
121        if (!missing)
122            error("row %d and column %d not defined in rowind and colptr",
123                  row, col);
124        return missing;
125    }
126    
127    SEXP alloc3Darray(SEXPTYPE mode, int nrow, int ncol, int nface);
128    
129    /**
130     * Calculate the zero-based index in a row-wise packed lower triangular matrix.
131     * This is used for the arrays of blocked sparse matrices.
132     *
133     * @param i column number (zero-based)
134     * @param k row number (zero-based)
135     *
136     * @return The index of the (k,i) element of a packed lower triangular matrix
137     */
138    static R_INLINE
139    int Lind(int k, int i)
140    {
141        if (k < i) error("Lind(k = %d, i = %d) must have k >= i", k, i);
142        return (k * (k + 1))/2 + i;
143    }
144    
145    /**
146     * Check for a complete match on matrix dimensions
147     *
148     * @param xd dimensions of first matrix
149     * @param yd dimensions of second matrix
150     *
151     * @return 1 if dimensions match, otherwise 0
152     */
153    static R_INLINE
154    int match_mat_dims(const int xd[], const int yd[])
155    {
156        return xd[0] == yd[0] && xd[1] == yd[1];
157    }
158    
159    double *expand_csc_column(double *dest, int m, int j,
160                              const int Ap[], const int Ai[], const double Ax[]);
161    
162    /**
163     * Apply a permutation to an integer vector
164     *
165     * @param i vector of 0-based indices
166     * @param n length of vector i
167     * @param perm 0-based permutation vector of length max(i) + 1
168     */
169    static R_INLINE void
170    int_permute(int i[], int n, const int perm[])
171    {
172        int j;
173        for (j = 0; j < n; j++) i[j] = perm[i[j]];
174    }
175    
176    /**
177     * Force index pairs to be in the upper triangle of a matrix
178     *
179     * @param i vector of 0-based row indices
180     * @param j vector of 0-based column indices
181     * @param nnz length of index vectors
182     */
183    static R_INLINE void
184    make_upper_triangular(int i[], int j[], int nnz)
185    {
186        int k;
187        for (k = 0; k < nnz; k++) {
188            if (i[k] > j[k]) {
189                int tmp = i[k];
190                i[k] = j[k];
191                j[k] = tmp;
192            }
193        }
194    }
195    
196    #endif

Legend:
Removed from v.164  
changed lines
  Added in v.572

root@r-forge.r-project.org
ViewVC Help
Powered by ViewVC 1.0.0  
Thanks to:
Vienna University of Economics and Business Powered By FusionForge