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

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

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