Module: Numo::NMath

Defined in:
ext/numo/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, Numo::DFloat::Math.

Parameters:

  • name (Symbol)

    method name.

  • x (NArray, Numeric)

    input array.

Returns:



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

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

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

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

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