Sha256: 09677ce38fd4e977ad73b1e8bc92caa47b5fa8f624cad0e91c672468253b7e18

Contents?: true

Size: 1.33 KB

Versions: 7

Compression:

Stored size: 1.33 KB

Contents

static VALUE
format_<%=tp%>(VALUE fmt, dtype* x)
{
    // fix-me
    char s[48];
    int n;

    if (NIL_P(fmt)) {
        n = m_sprintf(s,*x);
        return rb_str_new(s,n);
    }
    return rb_funcall(fmt, '%', 1, m_data_to_num(*x));
}

static void
<%=c_iter%>(na_loop_t *const lp)
{
    size_t  i;
    char   *p1, *p2;
    ssize_t s1, s2;
    size_t *idx1;
    dtype *x;
    VALUE y;
    VALUE fmt = lp->option;
    INIT_COUNTER(lp, i);
    INIT_PTR_IDX(lp, 0, p1, s1, idx1);
    INIT_PTR(lp, 1, p2, s2);
    if (idx1) {
        for (; i--;) {
            x = (dtype*)(p1+*idx1); idx1++;
            y = format_<%=tp%>(fmt, x);
            SET_DATA_STRIDE(p2, s2, VALUE, y);
        }
    } else {
        for (; i--;) {
            x = (dtype*)p1;         p1+=s1;
            y = format_<%=tp%>(fmt, x);
            SET_DATA_STRIDE(p2, s2, VALUE, y);
        }
    }
}

/*
  Format elements into strings.
  @overload <%=method%> format
  @param [String] format
  @return [Numo::RObject] array of formated strings.
*/
static VALUE
<%=c_func%>(int argc, VALUE *argv, VALUE self)
{
    VALUE fmt=Qnil;

    ndfunc_arg_in_t ain[2] = {{Qnil,0},{sym_option}};
    ndfunc_arg_out_t aout[1] = {{numo_cRObject,0}};
    ndfunc_t ndf = { <%=c_iter%>, FULL_LOOP_NIP, 2, 1, ain, aout };

    rb_scan_args(argc, argv, "01", &fmt);
    return na_ndloop(&ndf, 2, self, fmt);
}

Version data entries

7 entries across 7 versions & 1 rubygems

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