ext/nmatrix/data/data.cpp in nmatrix-0.0.9 vs ext/nmatrix/data/data.cpp in nmatrix-0.1.0.rc1

- old
+ new

@@ -7,12 +7,12 @@ // NMatrix was originally inspired by and derived from NArray, by // Masahiro Tanaka: http://narray.rubyforge.org // // == Copyright Information // -// SciRuby is Copyright (c) 2010 - 2013, Ruby Science Foundation -// NMatrix is Copyright (c) 2013, Ruby Science Foundation +// SciRuby is Copyright (c) 2010 - 2014, Ruby Science Foundation +// NMatrix is Copyright (c) 2012 - 2014, John Woods and the Ruby Science Foundation // // Please see LICENSE.txt for additional copyright notices. // // == Contributing // @@ -71,54 +71,28 @@ "gt", "leq", "geq" }; + const std::string NONCOM_EWOP_NAMES[nm::NUM_NONCOM_EWOPS] = { + "atan2", + "ldexp", + "hypot" + }; - template <typename Type> - Complex<Type>::Complex(const RubyObject& other) { - switch(TYPE(other.rval)) { - case T_COMPLEX: - r = NUM2DBL(rb_funcall(other.rval, rb_intern("real"), 0)); - i = NUM2DBL(rb_funcall(other.rval, rb_intern("imag"), 0)); - break; - case T_FLOAT: - case T_RATIONAL: - case T_FIXNUM: - case T_BIGNUM: - r = NUM2DBL(other.rval); - i = 0.0; - break; - default: - rb_raise(rb_eTypeError, "not sure how to convert this type of VALUE to a complex"); - } - } + const std::string UNARYOPS[nm::NUM_UNARYOPS] = { + "sin", "cos", "tan", + "asin", "acos", "atan", + "sinh", "cosh", "tanh", + "asinh", "acosh", "atanh", + "exp", "log2", + "log10", "sqrt", "erf", + "erfc", "cbrt", "gamma" + }; - - template <typename Type> - Rational<Type>::Rational(const RubyObject& other) { - switch (TYPE(other.rval)) { - case T_RATIONAL: - n = NUM2LONG(rb_funcall(other.rval, rb_intern("numerator"), 0)); - d = NUM2LONG(rb_funcall(other.rval, rb_intern("denominator"), 0)); - break; - case T_FIXNUM: - case T_BIGNUM: - n = NUM2LONG(other.rval); - d = 1; - break; - case T_COMPLEX: - case T_FLOAT: - rb_raise(rb_eTypeError, "cannot convert float to a rational"); - break; - 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", "int8", @@ -299,24 +273,26 @@ * 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) { size_t size = DTYPE_SIZES[dtype]; - void* ret_val = ALLOC_N(char, size); + NM_CONSERVATIVE(nm_register_value(val)); + void* ret_val = NM_ALLOC_N(char, size); rubyval_to_cval(val, dtype, ret_val); - + NM_CONSERVATIVE(nm_unregister_value(val)); return ret_val; } void nm_init_data() { - nm::RubyObject obj(INT2FIX(1)); - nm::Rational32 x(obj); - nm::Rational64 y(obj); - nm::Rational128 z(obj); - nm::Complex64 a(obj); - nm::Complex128 b(obj); + volatile VALUE t = INT2FIX(1); + volatile nm::RubyObject obj(t); + volatile nm::Rational32 x(const_cast<nm::RubyObject&>(obj)); + volatile nm::Rational64 y(const_cast<nm::RubyObject&>(obj)); + volatile nm::Rational128 z(const_cast<nm::RubyObject&>(obj)); + volatile nm::Complex64 a(const_cast<nm::RubyObject&>(obj)); + volatile nm::Complex128 b(const_cast<nm::RubyObject&>(obj)); } } // end of extern "C" block