Sha256: e537e3200193924145f45eae957770ce6bcab6fcea201092c6cb297eb461b4b5

Contents?: true

Size: 1.9 KB

Versions: 6

Compression:

Stored size: 1.9 KB

Contents

static void
<%=c_iter%>(na_loop_t *const lp)
{
    size_t i, n;
    size_t i1, n1;
    VALUE  v1, *ptr;
    char   *p2;
    size_t s2, *idx2;
    VALUE  x;
    double y;
    dtype  z;
    size_t len, c;
    double beg, step;

    v1 = lp->args[0].value;
    ptr = &v1;
    INIT_COUNTER(lp, n);
    INIT_PTR_IDX(lp, 1, p2, s2, idx2);

    switch(TYPE(v1)) {
    case T_ARRAY:
        n1 = RARRAY_LEN(v1);
        ptr = RARRAY_PTR(v1);
        break;
    case T_NIL:
        n1 = 0;
        break;
    default:
        n1 = 1;
    }
    if (idx2) {
        <% ["SET_DATA_INDEX(p2, idx2, dtype, z)",
            "SET_DATA_STRIDE(p2, s2, dtype, z)"].each_with_index do |x,i| %>
        for (i=i1=0; i1<n1 && i<n; i++,i1++) {
            x = ptr[i1];
            if (rb_obj_is_kind_of(x, rb_cRange) || rb_obj_is_kind_of(x, na_cStep)) {
                nary_step_sequence(x,&len,&beg,&step);
                for (c=0; c<len && i<n; c++,i++) {
                    y = beg + step * c;
                    z = m_from_double(y);
                    <%= x %>
                }
            }
            else if (TYPE(x) != T_ARRAY) {
                if (x == Qnil) x = INT2FIX(0);
                z = m_num_to_data(x);
                <%= x %>
            }
        }
        z = m_zero;
        for (; i<n; i++) {
            <%= x %>
        }
        <% if i<1 %>
    } else {
        <% end
        end %>
    }
}

static VALUE
<%=c_func%>(VALUE rary)
{
    volatile VALUE vnc, nary;
    narray_t *na;
    na_compose_t *nc;
    ndfunc_arg_in_t ain[2] = {{rb_cArray,0},{Qnil,0}};
    ndfunc_t ndf = { <%=c_iter%>, FULL_LOOP, 2, 0, ain, 0 };

    vnc = na_ary_composition(rary);
    Data_Get_Struct(vnc, na_compose_t, nc);
    nary = rb_narray_new(cT, nc->ndim, nc->shape);
    GetNArray(nary,na);
    if (na->size > 0) {
        <%=find_tmpl("allocate").c_func%>(nary);
        na_ndloop_cast_rarray_to_narray(&ndf, rary, nary);
    }
    return nary;
}

Version data entries

6 entries across 6 versions & 1 rubygems

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