Skip to content

Commit

Permalink
Renamed some macros to prevent C namespace conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
translunar committed Aug 20, 2012
1 parent 8547cb8 commit ec279ae
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 26 deletions.
3 changes: 3 additions & 0 deletions ext/nmatrix/data/data.h
Expand Up @@ -234,6 +234,9 @@ static ret (*(name)[NUM_DTYPES][NUM_ITYPES])(__VA_ARGS__) = { \
* Data
*/

const size_t NUM_DTYPES = NM_NUM_DTYPES;
const size_t NUM_ITYPES = NM_NUM_ITYPES;

// regular data types
extern const char* const DTYPE_NAMES[NUM_DTYPES];
extern const size_t DTYPE_SIZES[NUM_DTYPES];
Expand Down
18 changes: 9 additions & 9 deletions ext/nmatrix/nmatrix.cpp
Expand Up @@ -273,11 +273,11 @@ static VALUE nm_capacity(VALUE self) {
break;

case DENSE_STORE:
cap = UINT2NUM(storage_count_max_elements( NM_DENSE_STORAGE(self) ));
cap = UINT2NUM(storage_count_max_elements( NM_STORAGE_DENSE(self) ));
break;

case LIST_STORE:
cap = UINT2NUM(list_storage_count_elements( NM_LIST_STORAGE(self) ));
cap = UINT2NUM(list_storage_count_elements( NM_STORAGE_LIST(self) ));
break;

default:
Expand Down Expand Up @@ -372,7 +372,7 @@ static VALUE nm_upcast(VALUE self, VALUE t1, VALUE t2) {
* containing other types of data.
*/
static VALUE nm_each_dense(VALUE nmatrix) {
DENSE_STORAGE* s = NM_DENSE_STORAGE(nmatrix);
DENSE_STORAGE* s = NM_STORAGE_DENSE(nmatrix);
VALUE v;
size_t i;

Expand Down Expand Up @@ -716,12 +716,12 @@ static VALUE nm_complex_conjugate_bang(VALUE self) {
if (m->stype == DENSE_STORE) {

size = storage_count_max_elements(NM_STORAGE(self));
elem = NM_DENSE_STORAGE(self)->elements;
elem = NM_STORAGE_DENSE(self)->elements;

} else if (m->stype == YALE_STORE) {

size = yale_storage_get_size(NM_YALE_STORAGE(self));
elem = NM_YALE_STORAGE(self)->a;
size = yale_storage_get_size(NM_STORAGE_YALE(self));
elem = NM_STORAGE_YALE(self)->a;

} else {
rb_raise(rb_eNotImpError, "please cast to yale or dense (complex) first");
Expand Down Expand Up @@ -1062,7 +1062,7 @@ static VALUE nm_mset(int argc, VALUE* argv, VALUE self) {
break;
case LIST_STORE:
// Remove if it's a zero, insert otherwise
if (!memcmp(value, NM_LIST_STORAGE(self)->default_val, DTYPE_SIZES[NM_DTYPE(self)])) {
if (!memcmp(value, NM_STORAGE_LIST(self)->default_val, DTYPE_SIZES[NM_DTYPE(self)])) {
free(value);
value = list_storage_remove(NM_STORAGE(self), slice);
free(value);
Expand Down Expand Up @@ -1194,7 +1194,7 @@ static VALUE nm_xslice(int argc, VALUE* argv, void* (*slice_func)(STORAGE*, SLIC
fprintf(stderr, "\n");
*/

//DENSE_STORAGE* s = NM_DENSE_STORAGE(self);
//DENSE_STORAGE* s = NM_STORAGE_DENSE(self);

if (NM_DTYPE(self) == RUBYOBJ) result = *reinterpret_cast<VALUE*>( ttable[NM_STYPE(self)](NM_STORAGE(self), slice) );
else result = rubyobj_from_cval( ttable[NM_STYPE(self)](NM_STORAGE(self), slice), NM_DTYPE(self) ).rval;
Expand Down Expand Up @@ -1678,7 +1678,7 @@ static VALUE nm_det_exact(VALUE self) {

// Calculate the determinant and then assign it to the return value
void* result = ALLOCA_N(char, DTYPE_SIZES[NM_DTYPE(self)]);
det_exact(NM_SHAPE0(self), NM_DENSE_STORAGE(self)->elements, NM_SHAPE0(self), NM_DTYPE(self), result);
det_exact(NM_SHAPE0(self), NM_STORAGE_DENSE(self)->elements, NM_SHAPE0(self), NM_DTYPE(self), result);

return rubyobj_from_cval(result, NM_DTYPE(self)).rval;
}
Expand Down
34 changes: 25 additions & 9 deletions ext/nmatrix/nmatrix.h
Expand Up @@ -178,8 +178,15 @@
/*
* Types
*/
#define NUM_DTYPES 13
#define NUM_ITYPES 4

#define NM_NUM_DTYPES 13
#define NM_NUM_ITYPES 4

#ifndef __cplusplus
//namespace nm {
#else

#endif

/* Storage Type -- Dense or Sparse */
NM_DEF_ENUM(stype_t, DENSE_STORE = 0,
Expand Down Expand Up @@ -257,22 +264,29 @@ NM_DEF_STRUCT_POST(NMATRIX); // };

#define UnwrapNMatrix(obj,var) Data_Get_Struct(obj, NMATRIX, var)

#define NM_STRUCT(val) ((struct NMATRIX*)(DATA_PTR(val)))
#define NM_STORAGE(val) (NM_STRUCT(val)->storage)
#define NM_LIST_STORAGE(val) ((struct LIST_STORAGE*)(NM_STORAGE(val)))
#define NM_YALE_STORAGE(val) ((struct YALE_STORAGE*)(NM_STORAGE(val)))
#define NM_DENSE_STORAGE(val) ((struct DENSE_STORAGE*)(NM_STORAGE(val)))
#ifdef __cplusplus
#define NM_STRUCT(val) ((NMATRIX*)(DATA_PTR(val)))
#define NM_STORAGE_LIST(val) ((LIST_STORAGE*)(NM_STORAGE(val)))
#define NM_STORAGE_YALE(val) ((YALE_STORAGE*)(NM_STORAGE(val)))
#define NM_STORAGE_DENSE(val) ((DENSE_STORAGE*)(NM_STORAGE(val)))
#else
#define NM_STRUCT(val) ((struct NM_NMATRIX*)(DATA_PTR(val)))
#define NM_STORAGE_LIST(val) ((struct NM_LIST_STORAGE*)(NM_STORAGE(val)))
#define NM_STORAGE_YALE(val) ((struct NM_YALE_STORAGE*)(NM_STORAGE(val)))
#define NM_STORAGE_DENSE(val) ((struct NM_DENSE_STORAGE*)(NM_STORAGE(val)))
#endif

#define NM_DENSE_SRC(val) (NM_DENSE_STORAGE(val)->src)
#define NM_DENSE_SRC(val) (NM_STORAGE_DENSE(val)->src)
#define NM_RANK(val) (NM_STORAGE(val)->rank)
#define NM_DTYPE(val) (NM_STORAGE(val)->dtype)
#define NM_ITYPE(val) (NM_YALE_STORAGE(val)->itype)
#define NM_ITYPE(val) (NM_STORAGE_YALE(val)->itype)
#define NM_STYPE(val) (NM_STRUCT(val)->stype)
#define NM_SHAPE(val,i) (NM_STORAGE(val)->shape[(i)])
#define NM_SHAPE0(val) (NM_STORAGE(val)->shape[0])
#define NM_SHAPE1(val) (NM_STORAGE(val)->shape[1])

#define NM_DENSE_COUNT(val) (storage_count_max_elements(NM_DENSE_STORAGE(val)))
#define NM_DENSE_COUNT(val) (storage_count_max_elements(NM_STORAGE_DENSE(val)))
#define NM_SIZEOF_DTYPE(val) (DTYPE_SIZES[NM_DTYPE(val)])
#define NM_REF(val,slice) (RefFuncs[NM_STYPE(val)]( NM_STORAGE(val), slice, NM_SIZEOF_DTYPE(val) ))

Expand All @@ -293,6 +307,8 @@ NM_DEF_STRUCT_POST(NMATRIX); // };

#ifdef __cplusplus
typedef VALUE (*METHOD)(...);

//}; // end of namespace nm
#endif

/*
Expand Down
12 changes: 6 additions & 6 deletions ext/nmatrix/storage/yale.cpp
Expand Up @@ -1039,7 +1039,7 @@ static VALUE nm_yale_size(VALUE self) {
* Get the A array of a Yale matrix (which stores the diagonal and the LU portions of the matrix).
*/
static VALUE nm_yale_a(VALUE self) {
YALE_STORAGE* s = NM_YALE_STORAGE(self);
YALE_STORAGE* s = NM_STORAGE_YALE(self);

size_t size = yale_storage_get_size(s);
VALUE* vals = ALLOCA_N(VALUE, size);
Expand All @@ -1060,7 +1060,7 @@ static VALUE nm_yale_a(VALUE self) {
* Get the diagonal ("D") portion of the A array of a Yale matrix.
*/
static VALUE nm_yale_d(VALUE self) {
YALE_STORAGE* s = NM_YALE_STORAGE(self);
YALE_STORAGE* s = NM_STORAGE_YALE(self);

VALUE* vals = ALLOCA_N(VALUE, s->shape[0]);

Expand All @@ -1075,7 +1075,7 @@ static VALUE nm_yale_d(VALUE self) {
* Get the non-diagonal ("LU") portion of the A array of a Yale matrix.
*/
static VALUE nm_yale_lu(VALUE self) {
YALE_STORAGE* s = NM_YALE_STORAGE(self);
YALE_STORAGE* s = NM_STORAGE_YALE(self);

size_t size = yale_storage_get_size(s);

Expand All @@ -1099,7 +1099,7 @@ static VALUE nm_yale_lu(VALUE self) {
* JA and LU portions of the IJA and A arrays, respectively.
*/
static VALUE nm_yale_ia(VALUE self) {
YALE_STORAGE* s = NM_YALE_STORAGE(self);
YALE_STORAGE* s = NM_STORAGE_YALE(self);

VALUE* vals = ALLOCA_N(VALUE, s->capacity - s->shape[0]);

Expand All @@ -1116,7 +1116,7 @@ static VALUE nm_yale_ia(VALUE self) {
* positions in the LU portion of the A array.
*/
static VALUE nm_yale_ja(VALUE self) {
YALE_STORAGE* s = NM_YALE_STORAGE(self);
YALE_STORAGE* s = NM_STORAGE_YALE(self);

size_t size = yale_storage_get_size(s);

Expand All @@ -1139,7 +1139,7 @@ static VALUE nm_yale_ja(VALUE self) {
* Get the IJA array of a Yale matrix.
*/
static VALUE nm_yale_ija(VALUE self) {
YALE_STORAGE* s = NM_YALE_STORAGE(self);
YALE_STORAGE* s = NM_STORAGE_YALE(self);

size_t size = yale_storage_get_size(s);

Expand Down
4 changes: 2 additions & 2 deletions ext/nmatrix/util/math.cpp
Expand Up @@ -183,7 +183,7 @@ static VALUE nm_cblas_gemm(VALUE self,
rubyval_to_cval(alpha, dtype, pAlpha);
rubyval_to_cval(beta, dtype, pBeta);

return ttable[dtype](dtype, gemm_op_sym(trans_a), gemm_op_sym(trans_b), FIX2INT(m), FIX2INT(n), FIX2INT(k), pAlpha, NM_DENSE_STORAGE(a)->elements, FIX2INT(lda), NM_DENSE_STORAGE(b)->elements, FIX2INT(ldb), pBeta, NM_DENSE_STORAGE(c)->elements, FIX2INT(ldc)) ? Qtrue : Qfalse;
return ttable[dtype](dtype, gemm_op_sym(trans_a), gemm_op_sym(trans_b), FIX2INT(m), FIX2INT(n), FIX2INT(k), pAlpha, NM_STORAGE_DENSE(a)->elements, FIX2INT(lda), NM_STORAGE_DENSE(b)->elements, FIX2INT(ldb), pBeta, NM_STORAGE_DENSE(c)->elements, FIX2INT(ldc)) ? Qtrue : Qfalse;
}


Expand Down Expand Up @@ -243,7 +243,7 @@ static VALUE nm_cblas_gemv(VALUE self,
rubyval_to_cval(alpha, dtype, pAlpha);
rubyval_to_cval(beta, dtype, pBeta);

return ttable[dtype](dtype, gemm_op_sym(trans_a), FIX2INT(m), FIX2INT(n), pAlpha, NM_DENSE_STORAGE(a)->elements, FIX2INT(lda), NM_DENSE_STORAGE(x)->elements, FIX2INT(incx), pBeta, NM_DENSE_STORAGE(y)->elements, FIX2INT(incy)) ? Qtrue : Qfalse;
return ttable[dtype](dtype, gemm_op_sym(trans_a), FIX2INT(m), FIX2INT(n), pAlpha, NM_STORAGE_DENSE(a)->elements, FIX2INT(lda), NM_STORAGE_DENSE(x)->elements, FIX2INT(incx), pBeta, NM_STORAGE_DENSE(y)->elements, FIX2INT(incy)) ? Qtrue : Qfalse;
}


Expand Down

0 comments on commit ec279ae

Please sign in to comment.