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:



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'ext/numo/narray/math.c', line 77

static 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, id_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, id_extract, 0);
    }
    return ans;
  }
  rb_raise(rb_eArgError, "argument or method missing");
  return Qnil;
}