SCM

SCM Repository

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

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

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

revision 493, Thu Feb 3 18:47:20 2005 UTC revision 536, Thu Feb 10 08:15:12 2005 UTC
# Line 51  Line 51 
51  /* zero an array */  /* zero an array */
52  #define AZERO(x, n) {int _I_, _SZ_ = (n); for(_I_ = 0; _I_ < _SZ_; _I_++) (x)[_I_] = 0;}  #define AZERO(x, n) {int _I_, _SZ_ = (n); for(_I_ = 0; _I_ < _SZ_; _I_++) (x)[_I_] = 0;}
53    
54    /**
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    
74        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  #endif  #endif
163    

Legend:
Removed from v.493  
changed lines
  Added in v.536

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