Sha256: 80ecb5c9c9ca97d199027c8634bdcee9e91f0ec99f191b23ad1256c108d30466

Contents?: true

Size: 1.59 KB

Versions: 19

Compression:

Stored size: 1.59 KB

Contents

static VALUE
format_<%=type_name%>(VALUE fmt, dtype x)
{
    if (NIL_P(fmt)) {
        char s[4];
        int n;
        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%>(cumo_na_loop_t *const lp)
{
    size_t  i;
    CUMO_BIT_DIGIT *a1, x=0;
    size_t     p1;
    char      *p2;
    ssize_t    s1, s2;
    size_t    *idx1;
    VALUE  y;
    VALUE  fmt = lp->option;

    CUMO_SHOW_SYNCHRONIZE_WARNING_ONCE("<%=name%>", "<%=type_name%>");
    cumo_cuda_runtime_check_status(cudaDeviceSynchronize());

    CUMO_INIT_COUNTER(lp, i);
    CUMO_INIT_PTR_BIT_IDX(lp, 0, a1, p1, s1, idx1);
    CUMO_INIT_PTR(lp, 1, p2, s2);

    if (idx1) {
        for (; i--;) {
            CUMO_LOAD_BIT(a1, p1+*idx1, x); idx1++;
            y = format_<%=type_name%>(fmt, x);
            CUMO_SET_DATA_STRIDE(p2, s2, VALUE, y);
        }
    } else {
        for (; i--;) {
            CUMO_LOAD_BIT(a1, p1, x); p1+=s1;
            y = format_<%=type_name%>(fmt, x);
            CUMO_SET_DATA_STRIDE(p2, s2, VALUE, y);
        }
    }
}

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

    cumo_ndfunc_arg_in_t ain[2] = {{Qnil,0},{cumo_sym_option}};
    cumo_ndfunc_arg_out_t aout[1] = {{cumo_cRObject,0}};
    cumo_ndfunc_t ndf = {<%=c_iter%>, CUMO_FULL_LOOP_NIP, 2,1, ain,aout};

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

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
cumo-0.4.3 ext/cumo/narray/gen/tmpl_bit/format.c
cumo-0.4.2 ext/cumo/narray/gen/tmpl_bit/format.c
cumo-0.4.1 ext/cumo/narray/gen/tmpl_bit/format.c
cumo-0.4.0 ext/cumo/narray/gen/tmpl_bit/format.c
cumo-0.3.5 ext/cumo/narray/gen/tmpl_bit/format.c
cumo-0.3.4 ext/cumo/narray/gen/tmpl_bit/format.c
cumo-0.3.3 ext/cumo/narray/gen/tmpl_bit/format.c
cumo-0.3.2 ext/cumo/narray/gen/tmpl_bit/format.c
cumo-0.3.1 ext/cumo/narray/gen/tmpl_bit/format.c
cumo-0.3.0 ext/cumo/narray/gen/tmpl_bit/format.c
cumo-0.3.0.pre1 ext/cumo/narray/gen/tmpl_bit/format.c
cumo-0.2.5 ext/cumo/narray/gen/tmpl_bit/format.c
cumo-0.2.4 ext/cumo/narray/gen/tmpl_bit/format.c
cumo-0.2.3 ext/cumo/narray/gen/tmpl_bit/format.c
cumo-0.2.2 ext/cumo/narray/gen/tmpl_bit/format.c
cumo-0.2.1 ext/cumo/narray/gen/tmpl_bit/format.c
cumo-0.2.0 ext/cumo/narray/gen/tmpl_bit/format.c
cumo-0.1.2 ext/cumo/narray/gen/tmpl_bit/format.c
cumo-0.1.1 ext/cumo/narray/gen/tmpl_bit/format.c