Sha256: b6439399ab3553d5d683a1ea2e8ee8a23c2366ed897597a11b7fdd91d3e689a4

Contents?: true

Size: 1.02 KB

Versions: 4

Compression:

Stored size: 1.02 KB

Contents

<% children.each do |c|%>
<%= c.result %>

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

    if (rb_obj_class(obj)==cT) {
        return obj;
    }
    if (RTEST(rb_obj_is_kind_of(obj,rb_cNumeric))) {
        x = m_num_to_data(obj);
        return <%=type_name%>_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 = nary_new(cT, NA_NDIM(na), NA_SHAPE(na));
        if (NA_SIZE(na) > 0) {
            <%=find_tmpl("store").c_func%>(v,obj);
        }
        return v;
    }
    <% if is_object %>
    return robject_new_dim0(obj);
    <% else %>
    rb_raise(nary_eCastError,"cannot cast to %s",rb_class2name(type));
    return Qnil;
    <% end %>
}

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
numo-narray-0.9.1.6 ext/numo/narray/gen/tmpl/cast.c
numo-narray-0.9.1.5 ext/numo/narray/gen/tmpl/cast.c
numo-narray-0.9.1.4 ext/numo/narray/gen/tmpl/cast.c
numo-narray-0.9.1.3 ext/numo/narray/gen/tmpl/cast.c