SCM

SCM Repository

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

Annotation of /pkg/Matrix/src/Mutils.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 565 - (view) (download) (as text)
Original Path: pkg/src/Mutils.h

1 : bates 10 #ifndef MATRIX_MUTILS_H
2 :     #define MATRIX_MUTILS_H
3 :    
4 :     #include <Rdefines.h>
5 : bates 268 #include <Rconfig.h>
6 : bates 441 #include "cblas.h"
7 : bates 10
8 : bates 447 /* 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 : bates 10 char norm_type(char *typstr);
22 :     char rcond_type(char *typstr);
23 :     double get_double_by_name(SEXP obj, char *nm);
24 :     SEXP set_double_by_name(SEXP obj, double val, char *nm);
25 :     SEXP as_det_obj(double val, int log, int sign);
26 : bates 476 SEXP get_factors(SEXP obj, char *nm);
27 :     SEXP set_factors(SEXP obj, SEXP val, char *nm);
28 : bates 478 SEXP dgCMatrix_set_Dim(SEXP x, int nrow);
29 : bates 10 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[]);
31 :     SEXP triple_as_SEXP(int nrow, int ncol, int nz,
32 :     const int Ti [], const int Tj [], const double Tx [],
33 :     char *Rclass);
34 :     SEXP csc_check_column_sorting(SEXP A);
35 :     void csc_components_transpose(int m, int n, int nnz,
36 :     const int xp[], const int xi[],
37 :     const double xx[],
38 :     int ap[], int ai[], double ax[]);
39 :     void ssc_symbolic_permute(int n, int upper, const int perm[],
40 :     int Ap[], int Ai[]);
41 :     double *nlme_symmetrize(double *a, const int nc);
42 :     void nlme_check_Lapack_error(int info, const char *laName);
43 : bates 164 SEXP nlme_replaceSlot(SEXP obj, SEXP names, SEXP value);
44 :     SEXP nlme_weight_matrix_list(SEXP MLin, SEXP wts, SEXP adjst, SEXP MLout);
45 : bates 493 SEXP Matrix_make_named(int TYP, char **names);
46 : bates 10 /* stored pointers to symbols */
47 : bates 296 /* initialized in R_init_Matrix */
48 : bates 329 extern
49 :     #include "Syms.h"
50 : bates 10
51 : bates 432 /* zero an array */
52 : bates 441 #define AZERO(x, n) {int _I_, _SZ_ = (n); for(_I_ = 0; _I_ < _SZ_; _I_++) (x)[_I_] = 0;}
53 : bates 432
54 : bates 536 /**
55 :     * Allocate an SEXP of given type and length, assign it as slot nm in
56 :     * the object, and return the SEXP. The validity of this function
57 :     * depends on SET_SLOT not duplicating val when NAMED(val) == 0. If
58 :     * this behavior changes then ALLOC_SLOT must use SET_SLOT followed by
59 :     * GET_SLOT to ensure that the value returned is indeed the SEXP in
60 :     * the slot.
61 :     *
62 :     * @param obj object in which to assign the slot
63 :     * @param nm name of the slot, as an R name object
64 :     * @param type type of SEXP to allocate
65 :     * @param length length of SEXP to allocate
66 :     *
67 :     * @return SEXP of given type and length assigned as slot nm in obj
68 :     */
69 :     static R_INLINE
70 :     SEXP ALLOC_SLOT(SEXP obj, SEXP nm, SEXPTYPE type, int length)
71 :     {
72 :     SEXP val = allocVector(type, length);
73 : bates 441
74 : bates 536 SET_SLOT(obj, nm, val);
75 :     return val;
76 :     }
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 :    
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 : bates 10 #endif
163 :    
164 : bates 565
165 :     /**
166 :     * Apply a permutation to an integer vector
167 :     *
168 :     * @param i vector of 0-based indices
169 :     * @param n length of vector i
170 :     * @param perm 0-based permutation vector of length max(i) + 1
171 :     */
172 :     static R_INLINE void
173 :     int_permute(int i[], int n, const int perm[])
174 :     {
175 :     int j;
176 :     for (j = 0; j < n; j++) i[j] = perm[i[j]];
177 :     }
178 :    
179 :     /**
180 :     * Force index pairs to be in the upper triangle of a matrix
181 :     *
182 :     * @param i vector of 0-based row indices
183 :     * @param j vector of 0-based column indices
184 :     * @param nnz length of index vectors
185 :     */
186 :     static R_INLINE void
187 :     make_upper_triangular(int i[], int j[], int nnz)
188 :     {
189 :     int k;
190 :     for (k = 0; k < nnz; k++) {
191 :     if (i[k] > j[k]) {
192 :     int tmp = i[k];
193 :     i[k] = j[k];
194 :     j[k] = tmp;
195 :     }
196 :     }
197 :     }

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