Module: Cumo::NMath

Defined in:
ext/cumo/narray/math.c

Constant Summary collapse

DISPATCH =
hCast

Class Method Summary collapse

Class Method Details

.method_missing(name, x, ...) ⇒ NArray

Dispatches method to Math module of upcasted type, eg, Cumo::DFloat::Math.

Parameters:

  • name (Symbol)

    method name.

  • x (NArray, Numeric)

    input array.

Returns:



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'ext/cumo/narray/math.c', line 80

static VALUE cumo_na_math_method_missing(int argc, VALUE *argv, VALUE mod)
{
    VALUE type, ans, typemod, hash;
    if (argc>1) {
  type = cumo_na_mathcast(argc-1,argv+1);

  hash = rb_const_get(mod, cumo_id_DISPATCH);
  typemod = rb_hash_aref( hash, type );
  if (NIL_P(typemod)) {
      rb_raise(rb_eTypeError,"%s is unknown for Cumo::NMath",
         rb_class2name(type));
  }

  ans = rb_funcall2(typemod,cumo_id_send,argc,argv);

  if (!RTEST(rb_class_inherited_p(type,cNArray)) &&
      CumoIsNArray(ans) ) {
      ans = rb_funcall(ans,cumo_id_extract,0);
  }
  return ans;
    }
    rb_raise(rb_eArgError,"argument or method missing");
    return Qnil;
}