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 1960, Fri Jul 6 16:54:43 2007 UTC revision 2583, Sun Jul 25 01:11:09 2010 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    #undef Matrix_with_SPQR
5    
6  #ifdef __cplusplus  #ifdef __cplusplus
7  extern "C" {  extern "C" {
8  #endif  #endif
9    
10  #include <Rdefines.h> /* Rinternals.h + GET_SLOT etc */  #include <ctype.h>
11  #include <R.h>  /* includes Rconfig.h */  #include <R.h>  /* includes Rconfig.h */
12    #include <Rversion.h>
13    #include <Rdefines.h> /* Rinternals.h + GET_SLOT etc */
14    
15  #ifdef ENABLE_NLS  #ifdef ENABLE_NLS
16  #include <libintl.h>  #include <libintl.h>
17  #define _(String) dgettext ("Matrix", String)  #define _(String) dgettext ("Matrix", String)
18  #else  #else
19  #define _(String) (String)  #define _(String) (String)
20    /* Note that this is not yet supported (for Windows, e.g.) in R 2.9.0 : */
21    #define dngettext(pkg, String, StringP, N) (N > 1 ? StringP : String)
22    #endif
23    
24    #ifdef __GNUC__
25    # undef alloca
26    # define alloca(x) __builtin_alloca((x))
27    #elif defined(__sun) || defined(_AIX)
28    /* this is necessary (and sufficient) for Solaris 10 and AIX 6: */
29    # include <alloca.h>
30  #endif  #endif
31    
32  #define Alloca(n, t)   (t *) alloca( (size_t) ( (n) * sizeof(t) ) )  #define Alloca(n, t)   (t *) alloca( (size_t) ( (n) * sizeof(t) ) )
# Line 39  Line 53 
53  #define LFT CblasLeft  #define LFT CblasLeft
54  #define RGT CblasRight  #define RGT CblasRight
55    
56  char norm_type(const char *typstr);  #if !defined(R_VERSION) || R_VERSION < R_Version(2, 7, 0)
57  char rcond_type(const char *typstr);  char La_norm_type(const char *typstr);
58    char La_rcond_type(const char *typstr);
59    #endif
60    
61  double get_double_by_name(SEXP obj, char *nm);  double get_double_by_name(SEXP obj, char *nm);
62  SEXP set_double_by_name(SEXP obj, double val, char *nm);  SEXP set_double_by_name(SEXP obj, double val, char *nm);
63  SEXP as_det_obj(double val, int log, int sign);  SEXP as_det_obj(double val, int log, int sign);
64  SEXP get_factors(SEXP obj, char *nm);  SEXP get_factors(SEXP obj, char *nm);
65  SEXP set_factors(SEXP obj, SEXP val, char *nm);  SEXP set_factors(SEXP obj, SEXP val, char *nm);
66    
67    #if 0
68  SEXP dgCMatrix_set_Dim(SEXP x, int nrow);  SEXP dgCMatrix_set_Dim(SEXP x, int nrow);
69    #endif  /* unused */
70    
71  /* int csc_unsorted_columns(int ncol, const int p[], const int i[]); */  /* int csc_unsorted_columns(int ncol, const int p[], const int i[]); */
72  /* 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[]); */
73  /* SEXP csc_check_column_sorting(SEXP A); */  /* SEXP csc_check_column_sorting(SEXP A); */
74  SEXP Matrix_make_named(int TYP, char **names);  #if R_VERSION < R_Version(2, 10, 0)
75    SEXP Matrix_make_named(int TYP, const char **names);
76    #else
77    # define Matrix_make_named Rf_mkNamed
78    #endif
79    
80  SEXP check_scalar_string(SEXP sP, char *vals, char *nm);  SEXP check_scalar_string(SEXP sP, char *vals, char *nm);
81    Rboolean equal_string_vectors(SEXP s1, SEXP s2);
82    
83  void d_packed_getDiag(double *dest, SEXP x, int n);  void d_packed_getDiag(double *dest, SEXP x, int n);
84  void l_packed_getDiag(   int *dest, SEXP x, int n);  void l_packed_getDiag(   int *dest, SEXP x, int n);
85  void tr_d_packed_getDiag(double *dest, SEXP x);  void tr_d_packed_getDiag(double *dest, SEXP x);
# Line 85  Line 112 
112  #define PACKED_LENGTH(n)   ((n) * ((n) + 1))/2  #define PACKED_LENGTH(n)   ((n) * ((n) + 1))/2
113    
114  /* duplicate the slot with name given by sym from src to dest */  /* duplicate the slot with name given by sym from src to dest */
115  /* FIXME: is not yet used */  
116  #define slot_dup(dest, src, sym)  SET_SLOT(dest, sym, duplicate(GET_SLOT(src, sym)))  #define slot_dup(dest, src, sym)  SET_SLOT(dest, sym, duplicate(GET_SLOT(src, sym)))
117    
118    /* is not yet used: */
119  #define slot_nonNull_dup(dest, src, sym)                        \  #define slot_nonNull_dup(dest, src, sym)                        \
120      if(GET_SLOT(src, sym) != R_NilValue)                        \      if(GET_SLOT(src, sym) != R_NilValue)                        \
121          SET_SLOT(dest, sym, duplicate(GET_SLOT(src, sym)))          SET_SLOT(dest, sym, duplicate(GET_SLOT(src, sym)))
# Line 104  Line 132 
132  /* should also work for "matrix" matrices: */  /* should also work for "matrix" matrices: */
133  #define Real_KIND(_x_)  (IS_S4_OBJECT(_x_) ? Real_kind(_x_) : \  #define Real_KIND(_x_)  (IS_S4_OBJECT(_x_) ? Real_kind(_x_) : \
134                           (isReal(_x_) ? 0 : (isLogical(_x_) ? 1 : -1)))                           (isReal(_x_) ? 0 : (isLogical(_x_) ? 1 : -1)))
135    /* This one gives '0' also for integer "matrix" :*/
136    #define Real_KIND2(_x_) (IS_S4_OBJECT(_x_) ? Real_kind(_x_) : \
137                             (isLogical(_x_) ? 1 : 0))
138    
139  /* requires 'x' slot: */  /* requires 'x' slot: */
140  #define Real_kind(_x_)  (isReal(GET_SLOT(_x_, Matrix_xSym)) ? 0 :       \  #define Real_kind(_x_)  (isReal(GET_SLOT(_x_, Matrix_xSym)) ? 0 :       \
141                           (isLogical(GET_SLOT(_x_, Matrix_xSym)) ? 1 : -1))                           (isLogical(GET_SLOT(_x_, Matrix_xSym)) ? 1 : -1))
142    
143    #define DECLARE_AND_GET_X_SLOT(__C_TYPE, __SEXP)        \
144        __C_TYPE *xx = __SEXP(GET_SLOT(x, Matrix_xSym))
145    
146    
147  /**  /**
148   * Check for valid length of a packed triangular array and return the   * Check for valid length of a packed triangular array and return the
# Line 177  Line 211 
211      return mj;      return mj;
212  }  }
213    
214    /**
215     * Check if slot(obj, "x") contains any NA (or NaN).
216     *
217     * @param obj   a 'Matrix' object with an 'x' slot.
218     *
219     * @return Rboolean :== any(is.na(slot(obj, "x") )
220     */
221    static R_INLINE
222    Rboolean any_NA_in_x(SEXP obj)
223    {
224        double *x = REAL(GET_SLOT(obj, Matrix_xSym));
225        int i, n = LENGTH(GET_SLOT(obj, Matrix_xSym));
226        for(i=0; i < n; i++)
227            if(ISNAN(x[i])) return TRUE;
228        /* else */
229        return FALSE;
230    }
231    
232    
233  void make_d_matrix_triangular(double *x, SEXP from);  void make_d_matrix_triangular(double *x, SEXP from);
234  void make_i_matrix_triangular(   int *x, SEXP from);  void make_i_matrix_triangular(   int *x, SEXP from);
235    
# Line 189  Line 242 
242  SEXP dup_mMatrix_as_geMatrix (SEXP A);  SEXP dup_mMatrix_as_geMatrix (SEXP A);
243    
244  SEXP new_dgeMatrix(int nrow, int ncol);  SEXP new_dgeMatrix(int nrow, int ncol);
245    SEXP m_encodeInd (SEXP ij, SEXP di, SEXP chk_bnds);
246    SEXP m_encodeInd2(SEXP i, SEXP j, SEXP di, SEXP chk_bnds);
247    
248    
249  static R_INLINE SEXP  static R_INLINE SEXP
250  mMatrix_as_dgeMatrix(SEXP A)  mMatrix_as_dgeMatrix(SEXP A)
# Line 206  Line 262 
262   * Return the 0-based index of a string match in a vector of strings   * Return the 0-based index of a string match in a vector of strings
263   * terminated by an empty string.  Returns -1 for no match.   * terminated by an empty string.  Returns -1 for no match.
264   *   *
265   * @param dest class string to match   * @param class string to match
266   * @param valid vector of possible matches terminated by an empty string   * @param valid vector of possible matches terminated by an empty string
267   *   *
268   * @return index of match or -1 for no match   * @return index of match or -1 for no match
# Line 221  Line 277 
277      }      }
278  }  }
279    
280    int Matrix_check_class_etc(SEXP x, char **valid);
281    int Matrix_check_class_and_super(SEXP x, char **valid, SEXP rho);
282    
283  #ifdef __cplusplus  #ifdef __cplusplus
284  }  }
285  #endif  #endif

Legend:
Removed from v.1960  
changed lines
  Added in v.2583

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