Sha256: 31ef2800c504821196457660addb05cef26820e3c08bfa4598c3ec80c05f113b

Contents?: true

Size: 955 Bytes

Versions: 10

Compression:

Stored size: 955 Bytes

Contents

/*
  Cast object to Numo::<%=class_name%>.
  @overload [](elements)
  @overload <%=method%>(array)
  @param [Numeric,Array] elements
  @param [Array] array
  @return [Numo::<%=class_name%>]
*/
static VALUE
<%=c_func%>(VALUE type, VALUE obj)
{
    VALUE v;
    narray_t *na;
    dtype x;

    if (CLASS_OF(obj)==cT) {
        return obj;
    }
    if (RTEST(rb_obj_is_kind_of(obj,rb_cNumeric))) {
        x = m_num_to_data(obj);
        return numo_<%=tp%>_new_dim0(x);
    }
    if (RTEST(rb_obj_is_kind_of(obj,rb_cArray))) {
        return <%=find_tmpl("cast_array").c_func%>(obj);
    }
    if (IsNArray(obj)) {
        GetNArray(obj,na);
        v = rb_narray_new(cT, NA_NDIM(na), NA_SHAPE(na));
        if (NA_SIZE(na) > 0) {
            <%=find_tmpl("allocate").c_func%>(v);
            <%=find_tmpl("store").c_func%>(v,obj);
        }
        return v;
    }
    rb_raise(nary_eCastError,"cannot cast to %s",rb_class2name(type));
    return Qnil;
}

Version data entries

10 entries across 7 versions & 1 rubygems

Version Path
numo-narray-0.9.0.4 ext/numo/narray/gen/tmpl_bit/cast.c
numo-narray-0.9.0.3-x86-mingw32 ext/numo/narray/gen/tmpl/cast.c
numo-narray-0.9.0.3-x86-mingw32 ext/numo/narray/gen/tmpl_bit/cast.c
numo-narray-0.9.0.3-x64-mingw32 ext/numo/narray/gen/tmpl/cast.c
numo-narray-0.9.0.3-x64-mingw32 ext/numo/narray/gen/tmpl_bit/cast.c
numo-narray-0.9.0.3 ext/numo/narray/gen/tmpl/cast.c
numo-narray-0.9.0.3 ext/numo/narray/gen/tmpl_bit/cast.c
numo-narray-0.9.0.1-x64-mingw32 ext/numo/narray/gen/tmpl/cast.c
numo-narray-0.9.0.1 ext/numo/narray/gen/tmpl/cast.c
numo-narray-0.9.0.1-x86-mingw32 ext/numo/narray/gen/tmpl/cast.c