ext/nmatrix/data/data.cpp in nmatrix-0.0.8 vs ext/nmatrix/data/data.cpp in nmatrix-0.0.9
- old
+ new
@@ -113,10 +113,11 @@
default:
rb_raise(rb_eTypeError, "not sure how to convert this type of VALUE to a rational");
}
}
+
} // end of namespace nm
extern "C" {
const char* const DTYPE_NAMES[nm::NUM_DTYPES] = {
"byte",
@@ -132,18 +133,11 @@
"rational64",
"rational128",
"object"
};
-const char* const ITYPE_NAMES[nm::NUM_ITYPES] = {
- "uint8",
- "uint16",
- "uint32",
- "uint64"
-};
-
const size_t DTYPE_SIZES[nm::NUM_DTYPES] = {
sizeof(uint8_t),
sizeof(int8_t),
sizeof(int16_t),
sizeof(int32_t),
@@ -156,16 +150,10 @@
sizeof(nm::Rational64),
sizeof(nm::Rational128),
sizeof(nm::RubyObject)
};
-const size_t ITYPE_SIZES[nm::NUM_ITYPES] = {
- sizeof(uint8_t),
- sizeof(uint16_t),
- sizeof(uint32_t),
- sizeof(uint64_t),
-};
const nm::dtype_t Upcast[nm::NUM_DTYPES][nm::NUM_DTYPES] = {
{ nm::BYTE, nm::INT16, nm::INT16, nm::INT32, nm::INT64, nm::FLOAT32, nm::FLOAT64, nm::COMPLEX64, nm::COMPLEX128, nm::RATIONAL32, nm::RATIONAL64, nm::RATIONAL128, nm::RUBYOBJ},
{ nm::INT16, nm::INT8, nm::INT16, nm::INT32, nm::INT64, nm::FLOAT32, nm::FLOAT64, nm::COMPLEX64, nm::COMPLEX128, nm::RATIONAL32, nm::RATIONAL64, nm::RATIONAL128, nm::RUBYOBJ},
{ nm::INT16, nm::INT16, nm::INT16, nm::INT32, nm::INT64, nm::FLOAT32, nm::FLOAT64, nm::COMPLEX64, nm::COMPLEX128, nm::RATIONAL32, nm::RATIONAL64, nm::RATIONAL128, nm::RUBYOBJ},
@@ -304,35 +292,11 @@
}
return Qnil;
}
-/*
- * Convert from itype instead of dtype
- */
-nm::RubyObject rubyobj_from_cval_by_itype(void* val, nm::itype_t itype) {
- using namespace nm;
- switch (itype) {
- case UINT8:
- return RubyObject(*reinterpret_cast<uint8_t*>(val));
- case UINT16:
- return RubyObject((int16_t)(*reinterpret_cast<uint16_t*>(val)));
-
- case UINT32:
- return RubyObject((int32_t)(*reinterpret_cast<uint32_t*>(val)));
-
- case UINT64:
- return RubyObject((int64_t)(*reinterpret_cast<uint64_t*>(val)));
-
- default:
- rb_raise(nm_eDataTypeError, "Conversion to RubyObject requested from unknown data type");
- }
- return Qnil;
-}
-
-
/*
* Allocate and return a piece of data of the correct dtype, converted from a
* given RubyObject.
*/
void* rubyobj_to_cval(VALUE val, nm::dtype_t dtype) {
@@ -341,9 +305,10 @@
rubyval_to_cval(val, dtype, ret_val);
return ret_val;
}
+
void nm_init_data() {
nm::RubyObject obj(INT2FIX(1));
nm::Rational32 x(obj);
nm::Rational64 y(obj);