Class: Numo::DFloat

Inherits:
NArray show all
Defined in:
ext/numo/narray/types/dfloat.c

Defined Under Namespace

Modules: Math

Constant Summary

UPCAST =
hCast

Constants inherited from NArray

NArray::VERSION

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from NArray

#==, array_type, byte_size, #byte_size, #byte_swapped?, #cast_to, #check_axis, #coerce, #column_major?, concatenate, #concatenate, #contiguous?, debug=, #debug_info, #diagonal, #dot, #dsplit, dstack, #empty?, #expand_dims, eye, #flatten, from_binary, #host_order?, #hsplit, hstack, #initialize, #initialize_copy, #inplace, #inplace!, #inplace?, inspect_cols, inspect_cols=, inspect_rows, inspect_rows=, linspace, logspace, #marshal_dump, #marshal_load, #ndim, ones, #out_of_place!, profile, profile=, #repeat, #reshape, #reverse, #row_major?, #shape, #size, #split, srand, #store_binary, #swap_byte, #tile, #to_binary, #to_host, #to_network, #to_swapped, #to_vacs, #transpose, upcast, #view, #vsplit, vstack, zeros

Constructor Details

This class inherits a constructor from Numo::NArray

Class Method Details

.[](elements) ⇒ Numo::DFloat .cast(array) ⇒ Numo::DFloat

Cast object to Numo::DFloat.

Parameters:

  • elements (Numeric, Array)
  • array (Array)

Returns:



1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
# File 'ext/numo/narray/types/dfloat.c', line 1066

static VALUE
numo_dfloat_s_cast(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_dfloat_new_dim0(x);
    }
    if (RTEST(rb_obj_is_kind_of(obj,rb_cArray))) {
        return numo_dfloat_cast_array(obj);
    }
    if (IsNArray(obj)) {
        GetNArray(obj,na);
        v = rb_narray_new(cT, NA_NDIM(na), NA_SHAPE(na));
        if (NA_SIZE(na) > 0) {
            numo_dfloat_allocate(v);
            numo_dfloat_store(v,obj);
        }
        return v;
    }
    
#line 38 "/home/masa/numo/narray/ext/numo/narray/gen/tmpl/cast.c"
    rb_raise(nary_eCastError,"cannot cast to %s",rb_class2name(type));
    return Qnil;
    
}

.[](elements) ⇒ Numo::DFloat .cast(array) ⇒ Numo::DFloat

Cast object to Numo::DFloat.

Parameters:

  • elements (Numeric, Array)
  • array (Array)

Returns:



1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
# File 'ext/numo/narray/types/dfloat.c', line 1066

static VALUE
numo_dfloat_s_cast(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_dfloat_new_dim0(x);
    }
    if (RTEST(rb_obj_is_kind_of(obj,rb_cArray))) {
        return numo_dfloat_cast_array(obj);
    }
    if (IsNArray(obj)) {
        GetNArray(obj,na);
        v = rb_narray_new(cT, NA_NDIM(na), NA_SHAPE(na));
        if (NA_SIZE(na) > 0) {
            numo_dfloat_allocate(v);
            numo_dfloat_store(v,obj);
        }
        return v;
    }
    
#line 38 "/home/masa/numo/narray/ext/numo/narray/gen/tmpl/cast.c"
    rb_raise(nary_eCastError,"cannot cast to %s",rb_class2name(type));
    return Qnil;
    
}

Instance Method Details

#%(other) ⇒ Numo::NArray

Binary mod.

Parameters:

Returns:



2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
# File 'ext/numo/narray/types/dfloat.c', line 2055

static VALUE
numo_dfloat_mod(VALUE self, VALUE other)
{
    
#line 48 "/home/masa/numo/narray/ext/numo/narray/gen/tmpl/binary.c"
    VALUE klass, v;
    klass = na_upcast(CLASS_OF(self),CLASS_OF(other));
    if (klass==cT) {
        return numo_dfloat_mod_self(self, other);
    } else {
        v = rb_funcall(klass, id_cast, 1, self);
        return rb_funcall(v, '%', 1, other);
    }
    
}

#*(other) ⇒ Numo::NArray

Binary mul.

Parameters:

Returns:



1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
# File 'ext/numo/narray/types/dfloat.c', line 1945

static VALUE
numo_dfloat_mul(VALUE self, VALUE other)
{
    
#line 48 "/home/masa/numo/narray/ext/numo/narray/gen/tmpl/binary.c"
    VALUE klass, v;
    klass = na_upcast(CLASS_OF(self),CLASS_OF(other));
    if (klass==cT) {
        return numo_dfloat_mul_self(self, other);
    } else {
        v = rb_funcall(klass, id_cast, 1, self);
        return rb_funcall(v, '*', 1, other);
    }
    
}

#**(other) ⇒ Numo::NArray

Binary power.

Parameters:

Returns:



2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
# File 'ext/numo/narray/types/dfloat.c', line 2193

static VALUE
numo_dfloat_pow(VALUE self, VALUE other)
{
    
#line 69 "/home/masa/numo/narray/ext/numo/narray/gen/tmpl/pow.c"
    VALUE klass, v;
    klass = na_upcast(CLASS_OF(self),CLASS_OF(other));
    if (klass==cT) {
        return numo_dfloat_pow_self(self,other);
    } else {
        v = rb_funcall(klass, id_cast, 1, self);
        return rb_funcall(v, id_pow, 1, other);
    }
    
}

#+(other) ⇒ Numo::NArray

Binary add.

Parameters:

Returns:



1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
# File 'ext/numo/narray/types/dfloat.c', line 1835

static VALUE
numo_dfloat_add(VALUE self, VALUE other)
{
    
#line 48 "/home/masa/numo/narray/ext/numo/narray/gen/tmpl/binary.c"
    VALUE klass, v;
    klass = na_upcast(CLASS_OF(self),CLASS_OF(other));
    if (klass==cT) {
        return numo_dfloat_add_self(self, other);
    } else {
        v = rb_funcall(klass, id_cast, 1, self);
        return rb_funcall(v, '+', 1, other);
    }
    
}

#-(other) ⇒ Numo::NArray

Binary sub.

Parameters:

Returns:



1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
# File 'ext/numo/narray/types/dfloat.c', line 1890

static VALUE
numo_dfloat_sub(VALUE self, VALUE other)
{
    
#line 48 "/home/masa/numo/narray/ext/numo/narray/gen/tmpl/binary.c"
    VALUE klass, v;
    klass = na_upcast(CLASS_OF(self),CLASS_OF(other));
    if (klass==cT) {
        return numo_dfloat_sub_self(self, other);
    } else {
        v = rb_funcall(klass, id_cast, 1, self);
        return rb_funcall(v, '-', 1, other);
    }
    
}

#-@Numo::DFloat

Unary minus.

Returns:



2261
2262
2263
2264
2265
2266
2267
2268
2269
# File 'ext/numo/narray/types/dfloat.c', line 2261

static VALUE
numo_dfloat_minus(VALUE self)
{
    ndfunc_arg_in_t ain[1] = {{cT,0}};
    ndfunc_arg_out_t aout[1] = {{cT,0}};
    ndfunc_t ndf = {iter_dfloat_minus, FULL_LOOP, 1,1, ain,aout};

    return na_ndloop(&ndf, 1, self);
}

#/(other) ⇒ Numo::NArray

Binary div.

Parameters:

Returns:



2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
# File 'ext/numo/narray/types/dfloat.c', line 2000

static VALUE
numo_dfloat_div(VALUE self, VALUE other)
{
    
#line 48 "/home/masa/numo/narray/ext/numo/narray/gen/tmpl/binary.c"
    VALUE klass, v;
    klass = na_upcast(CLASS_OF(self),CLASS_OF(other));
    if (klass==cT) {
        return numo_dfloat_div_self(self, other);
    } else {
        v = rb_funcall(klass, id_cast, 1, self);
        return rb_funcall(v, '/', 1, other);
    }
    
}

#[](dim0, ..., dimL) ⇒ Numeric, NArray::DFloat

Array element referenece or slice view. — Returns the element at dim0, dim1, … are Numeric indices for each dimension, or returns a NArray View as a sliced subarray if dim0, dim1, … includes other than Numeric index, e.g., Range or Array or true.

Examples:

a = Numo::DFloat.new(4,5).seq
=> Numo::DFloat#shape=[4,5]
[[0, 1, 2, 3, 4],
 [5, 6, 7, 8, 9],
 [10, 11, 12, 13, 14],
 [15, 16, 17, 18, 19]]

a[1,1]
=> 6.0

a[1..3,1]
=> Numo::DFloat#shape=[3]
[6, 11, 16]

a[1,[1,3,4]]
=> Numo::DFloat#shape=[3]
[6, 8, 9]

a[true,2].fill(99)
a
=> Numo::DFloat#shape=[4,5]
[[0, 1, 99, 3, 4],
 [5, 6, 99, 8, 9],
 [10, 11, 99, 13, 14],
 [15, 16, 99, 18, 19]]

Parameters:

  • dim0,...,dimL (Numeric, Range, etc)

    Multi-dimensional Index.

Returns:

  • (Numeric, NArray::DFloat)

    Element object or NArray view.



1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
# File 'ext/numo/narray/types/dfloat.c', line 1140

static VALUE
numo_dfloat_aref(int argc, VALUE *argv, VALUE self)
{
    int nd;
    size_t pos;
    char *ptr;

    nd = na_get_result_dimension(self, argc, argv, sizeof(dtype), &pos);
    if (nd) {
        return na_aref_main(argc, argv, self, 0, nd);
    } else {
        ptr = na_get_pointer_for_read(self) + pos;
        return m_extract(ptr);
    }
}

#[]=(dim0, .., dimL, val) ⇒ Numeric

Array element(s) set. — Replace element(s) at dim0, dim1, … (index/range/array/true for each dimention). Broadcasting mechanism is applied.

Examples:

a = Numo::DFloat.new(3,4).seq
=> Numo::DFloat#shape=[3,4]
[[0, 1, 2, 3],
 [4, 5, 6, 7],
 [8, 9, 10, 11]]

a[1,2]=99
a
=> Numo::DFloat#shape=[3,4]
[[0, 1, 2, 3],
 [4, 5, 99, 7],
 [8, 9, 10, 11]]

a[1,[0,2]] = [101,102]
a
=> Numo::DFloat#shape=[3,4]
[[0, 1, 2, 3],
 [101, 5, 102, 7],
 [8, 9, 10, 11]]

a[1,true]=99
a
=> Numo::DFloat#shape=[3,4]
[[0, 1, 2, 3],
 [99, 99, 99, 99],
 [8, 9, 10, 11]]

Parameters:

  • dim0,..,dimL (Numeric, Range, etc)

    Multi-dimensional Index.

  • val (Numeric, Numo::NArray, etc)

    Value(s) to be set to self.

Returns:

  • (Numeric)

    returns val (last argument).



1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
# File 'ext/numo/narray/types/dfloat.c', line 1198

static VALUE
numo_dfloat_aset(int argc, VALUE *argv, VALUE self)
{
    int nd;
    size_t pos;
    char *ptr;
    VALUE a;

    argc--;
    if (argc==0) {
        numo_dfloat_store(self, argv[argc]);
    } else {
        nd = na_get_result_dimension(self, argc, argv, sizeof(dtype), &pos);
        if (nd) {
            a = na_aref_main(argc, argv, self, 0, nd);
            numo_dfloat_store(a, argv[argc]);
        } else {
            ptr = na_get_pointer_for_read_write(self) + pos;
            *(dtype*)ptr = m_num_to_data(argv[argc]);
        }

    }
    return argv[argc];
}

#absNumo::DFloat

abs of self.

Returns:



1786
1787
1788
1789
1790
1791
1792
1793
1794
# File 'ext/numo/narray/types/dfloat.c', line 1786

static VALUE
numo_dfloat_abs(VALUE self)
{
    ndfunc_arg_in_t ain[1] = {{cT,0}};
    ndfunc_arg_out_t aout[1] = {{cRT,0}};
    ndfunc_t ndf = { iter_dfloat_abs, FULL_LOOP, 1, 1, ain, aout };

    return na_ndloop(&ndf, 1, self);
}

#allocateObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'ext/numo/narray/types/dfloat.c', line 42

static VALUE
numo_dfloat_allocate(VALUE self)
{
    narray_t *na;
    char *ptr;

    GetNArray(self,na);

    switch(NA_TYPE(na)) {
    case NARRAY_DATA_T:
        ptr = NA_DATA_PTR(na);
        if (na->size > 0 && ptr == NULL) {
            ptr = xmalloc(sizeof(dtype) * na->size);
            
#line 22 "/home/masa/numo/narray/ext/numo/narray/gen/tmpl/allocate.c"
            NA_DATA_PTR(na) = ptr;
        }
        break;
    case NARRAY_VIEW_T:
        rb_funcall(NA_VIEW_DATA(na), rb_intern("allocate"), 0);
        break;
    case NARRAY_FILEMAP_T:
        //ptr = ((narray_filemap_t*)na)->ptr;
        // to be implemented
    default:
        rb_bug("invalid narray type : %d",NA_TYPE(na));
    }
    return self;
}

#ceilNumo::DFloat

Unary ceil.

Returns:



2745
2746
2747
2748
2749
2750
2751
2752
2753
# File 'ext/numo/narray/types/dfloat.c', line 2745

static VALUE
numo_dfloat_ceil(VALUE self)
{
    ndfunc_arg_in_t ain[1] = {{cT,0}};
    ndfunc_arg_out_t aout[1] = {{cT,0}};
    ndfunc_t ndf = {iter_dfloat_ceil, FULL_LOOP, 1,1, ain,aout};

    return na_ndloop(&ndf, 1, self);
}

#coerce_cast(type) ⇒ nil

Returns:

  • (nil)


1229
1230
1231
1232
1233
# File 'ext/numo/narray/types/dfloat.c', line 1229

static VALUE
numo_dfloat_coerce_cast(VALUE value, VALUE type)
{
    return Qnil;
}

#copysign(other) ⇒ Numo::NArray

Binary copysign.

Parameters:

Returns:



2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
# File 'ext/numo/narray/types/dfloat.c', line 2918

static VALUE
numo_dfloat_copysign(VALUE self, VALUE other)
{
    
#line 48 "/home/masa/numo/narray/ext/numo/narray/gen/tmpl/binary.c"
    VALUE klass, v;
    klass = na_upcast(CLASS_OF(self),CLASS_OF(other));
    if (klass==cT) {
        return numo_dfloat_copysign_self(self, other);
    } else {
        v = rb_funcall(klass, id_cast, 1, self);
        return rb_funcall(v, id_copysign, 1, other);
    }
    
}

#cumprod(*args) ⇒ Numo::DFloat

Cumprod of self.

Parameters:

  • args (Array of Numeric, Range)

    Affected dimensions.

Returns:



3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
# File 'ext/numo/narray/types/dfloat.c', line 3947

static VALUE
numo_dfloat_cumprod(int argc, VALUE *argv, VALUE self)
{
    VALUE reduce;
    ndfunc_arg_in_t ain[2] = {{cT,0},{sym_reduce,0}};
    ndfunc_arg_out_t aout[1] = {{cT,0}};
    ndfunc_t ndf = { iter_dfloat_cumprod, STRIDE_LOOP_NIP|NDF_INPLACE|NDF_FLAT_REDUCE|NDF_CUM,
                     2, 1, ain, aout };

    reduce = na_reduce_dimension(argc, argv, 1, &self);
    return na_ndloop(&ndf, 2, self, reduce);
}

#cumsum(*args) ⇒ Numo::DFloat

Cumsum of self.

Parameters:

  • args (Array of Numeric, Range)

    Affected dimensions.

Returns:



3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
# File 'ext/numo/narray/types/dfloat.c', line 3901

static VALUE
numo_dfloat_cumsum(int argc, VALUE *argv, VALUE self)
{
    VALUE reduce;
    ndfunc_arg_in_t ain[2] = {{cT,0},{sym_reduce,0}};
    ndfunc_arg_out_t aout[1] = {{cT,0}};
    ndfunc_t ndf = { iter_dfloat_cumsum, STRIDE_LOOP_NIP|NDF_INPLACE|NDF_FLAT_REDUCE|NDF_CUM,
                     2, 1, ain, aout };

    reduce = na_reduce_dimension(argc, argv, 1, &self);
    return na_ndloop(&ndf, 2, self, reduce);
}

#divmod(other) ⇒ Numo::NArray

Binary divmod.

Parameters:

Returns:



2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
# File 'ext/numo/narray/types/dfloat.c', line 2112

static VALUE
numo_dfloat_divmod(VALUE self, VALUE other)
{
    
#line 50 "/home/masa/numo/narray/ext/numo/narray/gen/tmpl/binary2.c"
    VALUE klass, v;
    klass = na_upcast(CLASS_OF(self),CLASS_OF(other));
    if (klass==cT) {
        return numo_dfloat_divmod_self(self, other);
    } else {
        v = rb_funcall(klass, id_cast, 1, self);
        return rb_funcall(v, id_divmod, 1, other);
    }
    
}

#eachNumo::NArray

Calls the given block once for each element in self, passing that element as a parameter. For a block {|x| … }

Yields:

  • (x)

    x is element of NArray.

Returns:



1496
1497
1498
1499
1500
1501
1502
1503
1504
# File 'ext/numo/narray/types/dfloat.c', line 1496

static VALUE
numo_dfloat_each(VALUE self)
{
    ndfunc_arg_in_t ain[1] = {{Qnil,0}};
    ndfunc_t ndf = {iter_dfloat_each, FULL_LOOP_NIP, 1,0, ain,0};

    na_ndloop(&ndf, 1, self);
    return self;
}

#each_with_indexNumo::NArray

Invokes the given block once for each element of self, passing that element and indices along each axis as parameters. For a block {|x,i,j,…| … }

Yields:

  • (x, i, j, ...)

    x is an element, i,j,… are multidimensional indices.

Returns:



1626
1627
1628
1629
1630
1631
1632
1633
1634
# File 'ext/numo/narray/types/dfloat.c', line 1626

static VALUE
numo_dfloat_each_with_index(VALUE self)
{
    ndfunc_arg_in_t ain[1] = {{Qnil,0}};
    ndfunc_t ndf = {iter_dfloat_each_with_index, FULL_LOOP_NIP, 1,0, ain,0};

    na_ndloop_with_index(&ndf, 1, self);
    return self;
}

#eq(other) ⇒ Numo::Bit

Comparison eq other.

Parameters:

Returns:



2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
# File 'ext/numo/narray/types/dfloat.c', line 2437

static VALUE
numo_dfloat_eq(VALUE self, VALUE other)
{
    
#line 46 "/home/masa/numo/narray/ext/numo/narray/gen/tmpl/cond_binary.c"
    VALUE klass, v;
    klass = na_upcast(CLASS_OF(self),CLASS_OF(other));
    if (klass==cT) {
        return numo_dfloat_eq_self(self, other);
    } else {
        v = rb_funcall(klass, id_cast, 1, self);
        return rb_funcall(v, id_eq, 1, other);
    }
    
}

#extractNumeric, Numo::NArray

Extract an element only if self is a dimensionless NArray. — Extract element value as Ruby Object if self is a dimensionless NArray, otherwise returns self.

Returns:



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'ext/numo/narray/types/dfloat.c', line 82

VALUE
numo_dfloat_extract(VALUE self)
{
    volatile VALUE v;
    char *ptr;
    narray_t *na;
    GetNArray(self,na);

    if (na->ndim==0) {
        ptr = na_get_pointer_for_read(self) + na_get_offset(self);
        v = m_extract(ptr);
        na_release_lock(self);
        return v;
    }
    return self;
}

#eye([element,offset]) ⇒ Numo::DFloat

Eye: Set a value to diagonal components, set 0 to non-diagonal components.

Parameters:

  • element (Numeric)

    Diagonal element to be stored. Default is 1.

  • offset (Integer)

    Diagonal offset from the main diagonal. The default is 0. k>0 for diagonals above the main diagonal, and k<0 for diagonals below the main diagonal.

Returns:



4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
# File 'ext/numo/narray/types/dfloat.c', line 4261

static VALUE
numo_dfloat_eye(int argc, VALUE *argv, VALUE self)
{
    ndfunc_arg_in_t ain[1] = {{OVERWRITE,2}};
    ndfunc_t ndf = {iter_dfloat_eye, NO_LOOP, 1,0, ain,0};
    ssize_t kofs;
    dtype data;
    char *g;
    int nd;
    narray_t *na;

    // check arguments
    if (argc > 2) {
        rb_raise(rb_eArgError,"too many arguments (%d for 0..2)",argc);
    } else if (argc == 2) {
        data = m_num_to_data(argv[0]);
        kofs = NUM2SSIZET(argv[1]);
    } else if (argc == 1) {
        data = m_num_to_data(argv[0]);
        kofs = 0;
    } else {
        data = m_one;
        kofs = 0;
    }

    GetNArray(self,na);
    nd = na->ndim;
    if (nd < 2) {
        rb_raise(nary_eDimensionError,"less than 2-d array");
    }

    // Diagonal offset from the main diagonal.
    if (kofs >= 0) {
        if ((size_t)(kofs) >= na->shape[nd-1]) {
            rb_raise(rb_eArgError,"invalid diagonal offset(%"SZF"d) for "
                     "last dimension size(%"SZF"d)",kofs,na->shape[nd-1]);
        }
    } else {
        if ((size_t)(-kofs) >= na->shape[nd-2]) {
            rb_raise(rb_eArgError,"invalid diagonal offset(%"SZF"d) for "
                     "last-1 dimension size(%"SZF"d)",kofs,na->shape[nd-2]);
        }
    }

    g = ALLOCA_N(char,sizeof(ssize_t)+sizeof(dtype));
    *(ssize_t*)g = kofs;
    *(dtype*)(g+sizeof(ssize_t)) = data;

    na_ndloop3(&ndf, g, 1, self);
    return self;
}

#fill(other) ⇒ Numo::DFloat

Fill elements with other.

Parameters:

  • other (Numeric)

Returns:



1312
1313
1314
1315
1316
1317
1318
1319
1320
# File 'ext/numo/narray/types/dfloat.c', line 1312

static VALUE
numo_dfloat_fill(VALUE self, VALUE val)
{
    ndfunc_arg_in_t ain[2] = {{OVERWRITE,0},{sym_option}};
    ndfunc_t ndf = { iter_dfloat_fill, FULL_LOOP, 2, 0, ain, 0 };

    na_ndloop(&ndf, 2, self, val);
    return self;
}

#floorNumo::DFloat

Unary floor.

Returns:



2621
2622
2623
2624
2625
2626
2627
2628
2629
# File 'ext/numo/narray/types/dfloat.c', line 2621

static VALUE
numo_dfloat_floor(VALUE self)
{
    ndfunc_arg_in_t ain[1] = {{cT,0}};
    ndfunc_arg_out_t aout[1] = {{cT,0}};
    ndfunc_t ndf = {iter_dfloat_floor, FULL_LOOP, 1,1, ain,aout};

    return na_ndloop(&ndf, 1, self);
}

#format(format) ⇒ Numo::RObject

Format elements into strings.

Parameters:

  • format (String)

Returns:



1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
# File 'ext/numo/narray/types/dfloat.c', line 1373

static VALUE
numo_dfloat_format(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 = { iter_dfloat_format, FULL_LOOP_NIP, 2, 1, ain, aout };

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

#format_to_a(format) ⇒ Array

Format elements into strings.

Parameters:

  • format (String)

Returns:

  • (Array)

    array of formated strings.



1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
# File 'ext/numo/narray/types/dfloat.c', line 1425

static VALUE
numo_dfloat_format_to_a(int argc, VALUE *argv, VALUE self)
{
    volatile VALUE fmt=Qnil;
    ndfunc_arg_in_t ain[3] = {{Qnil,0},{sym_loop_opt},{sym_option}};
    ndfunc_arg_out_t aout[1] = {{rb_cArray,0}}; // dummy?
    ndfunc_t ndf = { iter_dfloat_format_to_a, FULL_LOOP_NIP, 3, 1, ain, aout };

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

#ge(other) ⇒ Numo::Bit Also known as: >=

Comparison ge other.

Parameters:

Returns:



3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
# File 'ext/numo/narray/types/dfloat.c', line 3034

static VALUE
numo_dfloat_ge(VALUE self, VALUE other)
{
    
#line 46 "/home/masa/numo/narray/ext/numo/narray/gen/tmpl/cond_binary.c"
    VALUE klass, v;
    klass = na_upcast(CLASS_OF(self),CLASS_OF(other));
    if (klass==cT) {
        return numo_dfloat_ge_self(self, other);
    } else {
        v = rb_funcall(klass, id_cast, 1, self);
        return rb_funcall(v, id_ge, 1, other);
    }
    
}

#gt(other) ⇒ Numo::Bit Also known as: >

Comparison gt other.

Parameters:

Returns:



2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
# File 'ext/numo/narray/types/dfloat.c', line 2976

static VALUE
numo_dfloat_gt(VALUE self, VALUE other)
{
    
#line 46 "/home/masa/numo/narray/ext/numo/narray/gen/tmpl/cond_binary.c"
    VALUE klass, v;
    klass = na_upcast(CLASS_OF(self),CLASS_OF(other));
    if (klass==cT) {
        return numo_dfloat_gt_self(self, other);
    } else {
        v = rb_funcall(klass, id_cast, 1, self);
        return rb_funcall(v, id_gt, 1, other);
    }
    
}

#inspectString

Returns a string containing a human-readable representation of NArray.

Returns:

  • (String)


1453
1454
1455
1456
1457
# File 'ext/numo/narray/types/dfloat.c', line 1453

VALUE
numo_dfloat_inspect(VALUE ary)
{
    return na_ndloop_inspect(ary, iter_dfloat_inspect, Qnil);
}

#isfiniteNumo::Bit

Condition of isfinite.

Returns:



3303
3304
3305
3306
3307
3308
3309
3310
3311
# File 'ext/numo/narray/types/dfloat.c', line 3303

static VALUE
numo_dfloat_isfinite(VALUE self)
{
    ndfunc_arg_in_t ain[1] = {{cT,0}};
    ndfunc_arg_out_t aout[1] = {{numo_cBit,0}};
    ndfunc_t ndf = { iter_dfloat_isfinite, FULL_LOOP, 1, 1, ain, aout };

    return na_ndloop(&ndf, 1, self);
}

#isinfNumo::Bit

Condition of isinf.

Returns:



3254
3255
3256
3257
3258
3259
3260
3261
3262
# File 'ext/numo/narray/types/dfloat.c', line 3254

static VALUE
numo_dfloat_isinf(VALUE self)
{
    ndfunc_arg_in_t ain[1] = {{cT,0}};
    ndfunc_arg_out_t aout[1] = {{numo_cBit,0}};
    ndfunc_t ndf = { iter_dfloat_isinf, FULL_LOOP, 1, 1, ain, aout };

    return na_ndloop(&ndf, 1, self);
}

#isnanNumo::Bit

Condition of isnan.

Returns:



3205
3206
3207
3208
3209
3210
3211
3212
3213
# File 'ext/numo/narray/types/dfloat.c', line 3205

static VALUE
numo_dfloat_isnan(VALUE self)
{
    ndfunc_arg_in_t ain[1] = {{cT,0}};
    ndfunc_arg_out_t aout[1] = {{numo_cBit,0}};
    ndfunc_t ndf = { iter_dfloat_isnan, FULL_LOOP, 1, 1, ain, aout };

    return na_ndloop(&ndf, 1, self);
}

#kahan_sum(*args) ⇒ Numo::DFloat

Kahan_sum of self.

Parameters:

  • args (Array of Numeric, Range)

    Affected dimensions.

Returns:



3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
# File 'ext/numo/narray/types/dfloat.c', line 3412

static VALUE
numo_dfloat_kahan_sum(int argc, VALUE *argv, VALUE self)
{
    VALUE v, reduce;
    ndfunc_arg_in_t ain[2] = {{cT,0},{sym_reduce,0}};
    ndfunc_arg_out_t aout[1] = {{cT,0}};
    ndfunc_t ndf = { iter_dfloat_kahan_sum, STRIDE_LOOP_NIP|NDF_FLAT_REDUCE, 2, 1, ain, aout };

    reduce = na_reduce_dimension(argc, argv, 1, &self);
    v =  na_ndloop(&ndf, 2, self, reduce);
#line 32 "/home/masa/numo/narray/ext/numo/narray/gen/tmpl/accum.c"
    return numo_dfloat_extract(v);
#line 36 "/home/masa/numo/narray/ext/numo/narray/gen/tmpl/accum.c"
}

#le(other) ⇒ Numo::Bit Also known as: <=

Comparison le other.

Parameters:

Returns:



3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
# File 'ext/numo/narray/types/dfloat.c', line 3150

static VALUE
numo_dfloat_le(VALUE self, VALUE other)
{
    
#line 46 "/home/masa/numo/narray/ext/numo/narray/gen/tmpl/cond_binary.c"
    VALUE klass, v;
    klass = na_upcast(CLASS_OF(self),CLASS_OF(other));
    if (klass==cT) {
        return numo_dfloat_le_self(self, other);
    } else {
        v = rb_funcall(klass, id_cast, 1, self);
        return rb_funcall(v, id_le, 1, other);
    }
    
}

#logseq(beg, step, [base]) ⇒ Numo::DFloat

Set logarithmic sequence of numbers to self. The sequence is obtained from

base**(beg+i*step)

where i is 1-dimensional index. Applicable classes: DFloat, SFloat, DComplex, SCopmplex.

Examples:

Numo::DFloat.new(5).logseq(4,-1,2)
=> Numo::DFloat#shape=[5]
  [16, 8, 4, 2, 1]
Numo::DComplex.new(5).logseq(0,1i*Math::PI/3,Math::E)
=> Numo::DComplex#shape=[5]
  [1+7.26156e-310i, 0.5+0.866025i, -0.5+0.866025i, -1+1.22465e-16i, ...]

Parameters:

  • beg (Numeric)

    The begining of sequence.

  • step (Numeric)

    The step of sequence.

  • base (Numeric)

    The base of log space. (default=10)

Returns:



4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
# File 'ext/numo/narray/types/dfloat.c', line 4197

static VALUE
numo_dfloat_logseq(int argc, VALUE *args, VALUE self)
{
    logseq_opt_t *g;
    VALUE vbeg, vstep, vbase;
    ndfunc_arg_in_t ain[1] = {{OVERWRITE,0}};
    ndfunc_t ndf = {iter_dfloat_logseq, FULL_LOOP, 1,0, ain,0};

    g = ALLOCA_N(logseq_opt_t,1);
    rb_scan_args(argc, args, "21", &vbeg, &vstep, &vbase);
    g->beg = m_num_to_data(vbeg);
    g->step = m_num_to_data(vstep);
    if (vbase==Qnil) {
        g->base = m_from_real(10);
    } else {
        g->base = m_num_to_data(vbase);
    }
    na_ndloop3(&ndf, g, 1, self);
    return self;
}

#lt(other) ⇒ Numo::Bit Also known as: <

Comparison lt other.

Parameters:

Returns:



3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
# File 'ext/numo/narray/types/dfloat.c', line 3092

static VALUE
numo_dfloat_lt(VALUE self, VALUE other)
{
    
#line 46 "/home/masa/numo/narray/ext/numo/narray/gen/tmpl/cond_binary.c"
    VALUE klass, v;
    klass = na_upcast(CLASS_OF(self),CLASS_OF(other));
    if (klass==cT) {
        return numo_dfloat_lt_self(self, other);
    } else {
        v = rb_funcall(klass, id_cast, 1, self);
        return rb_funcall(v, id_lt, 1, other);
    }
    
}

#mapNumo::DFloat

Unary map.

Returns:



1558
1559
1560
1561
1562
1563
1564
1565
1566
# File 'ext/numo/narray/types/dfloat.c', line 1558

static VALUE
numo_dfloat_map(VALUE self)
{
    ndfunc_arg_in_t ain[1] = {{cT,0}};
    ndfunc_arg_out_t aout[1] = {{cT,0}};
    ndfunc_t ndf = {iter_dfloat_map, FULL_LOOP, 1,1, ain,aout};

    return na_ndloop(&ndf, 1, self);
}

#map_with_indexNumo::NArray

Invokes the given block once for each element of self, passing that element and indices along each axis as parameters. Creates a new NArray containing the values returned by the block. Inplace option is allowed, i.e., `nary.inplace.map` overwrites `nary`.

For a block {|x,i,j,…| … }

Yields:

  • (x, i, j, ...)

    x is an element, i,j,… are multidimensional indices.

Returns:



1724
1725
1726
1727
1728
1729
1730
1731
1732
# File 'ext/numo/narray/types/dfloat.c', line 1724

static VALUE
numo_dfloat_map_with_index(VALUE self)
{
    ndfunc_arg_in_t ain[1] = {{Qnil,0}};
    ndfunc_arg_out_t aout[1] = {{cT,0}};
    ndfunc_t ndf = {iter_dfloat_map_with_index, FULL_LOOP, 1,1, ain,aout};

    return na_ndloop_with_index(&ndf, 1, self);
}

#max(*args) ⇒ Numo::DFloat

Max of self.

Parameters:

  • args (Array of Numeric, Range)

    Affected dimensions.

Returns:



3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
# File 'ext/numo/narray/types/dfloat.c', line 3640

static VALUE
numo_dfloat_max(int argc, VALUE *argv, VALUE self)
{
    VALUE v, reduce;
    ndfunc_arg_in_t ain[2] = {{cT,0},{sym_reduce,0}};
    ndfunc_arg_out_t aout[1] = {{cT,0}};
    ndfunc_t ndf = { iter_dfloat_max, STRIDE_LOOP_NIP|NDF_FLAT_REDUCE, 2, 1, ain, aout };

    reduce = na_reduce_dimension(argc, argv, 1, &self);
    v =  na_ndloop(&ndf, 2, self, reduce);
#line 32 "/home/masa/numo/narray/ext/numo/narray/gen/tmpl/accum.c"
    return numo_dfloat_extract(v);
#line 36 "/home/masa/numo/narray/ext/numo/narray/gen/tmpl/accum.c"
}

#max_indexInteger #max_index(dim0, dim1, ..) ⇒ Integer, Numo::Int32/64

Return an index of result.

Numo::NArray[3,4,1,2].min_index => 3

Overloads:

  • #max_indexInteger

    Returns:

    • (Integer)
  • #max_index(dim0, dim1, ..) ⇒ Integer, Numo::Int32/64

    Returns:



3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
# File 'ext/numo/narray/types/dfloat.c', line 3707

static VALUE
numo_dfloat_max_index(int argc, VALUE *argv, VALUE self)
{
    narray_t *na;
    VALUE idx, reduce;
    ndfunc_arg_in_t ain[3] = {{Qnil,0},{Qnil,0},{sym_reduce,0}};
    ndfunc_arg_out_t aout[1] = {{0,0,0}};
    ndfunc_t ndf = {0, STRIDE_LOOP_NIP|NDF_FLAT_REDUCE|NDF_EXTRACT, 3,1, ain,aout};

    GetNArray(self,na);
    if (na->ndim==0) {
        return INT2FIX(0);
    }
    if (na->size > (~(u_int32_t)0)) {
        aout[0].type = numo_cInt64;
        idx = rb_narray_new(numo_cInt64, na->ndim, na->shape);
        ndf.func = iter_dfloat_max_index_index64;
    } else {
        aout[0].type = numo_cInt32;
        idx = rb_narray_new(numo_cInt32, na->ndim, na->shape);
        ndf.func = iter_dfloat_max_index_index32;
    }
    rb_funcall(idx, rb_intern("seq"), 0);

    reduce = na_reduce_dimension(argc, argv, 1, &self);

    return na_ndloop(&ndf, 3, self, idx, reduce);
}

#mean(*args) ⇒ Numo::DFloat

Mean of self.

Parameters:

  • args (Array of Numeric, Range)

    Affected dimensions.

Returns:



3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
# File 'ext/numo/narray/types/dfloat.c', line 3450

static VALUE
numo_dfloat_mean(int argc, VALUE *argv, VALUE self)
{
    VALUE v, reduce;
    ndfunc_arg_in_t ain[2] = {{cT,0},{sym_reduce,0}};
    ndfunc_arg_out_t aout[1] = {{cT,0}};
    ndfunc_t ndf = { iter_dfloat_mean, STRIDE_LOOP_NIP|NDF_FLAT_REDUCE, 2, 1, ain, aout };

    reduce = na_reduce_dimension(argc, argv, 1, &self);
    v =  na_ndloop(&ndf, 2, self, reduce);
#line 32 "/home/masa/numo/narray/ext/numo/narray/gen/tmpl/accum.c"
    return numo_dfloat_extract(v);
#line 36 "/home/masa/numo/narray/ext/numo/narray/gen/tmpl/accum.c"
}

#median(*args) ⇒ Object



5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
# File 'ext/numo/narray/types/dfloat.c', line 5070

static VALUE
numo_dfloat_median(int argc, VALUE *argv, VALUE self)
{
    VALUE reduce;
    ndfunc_arg_in_t ain[2] = {{cT,0},{sym_reduce,0}};
    ndfunc_arg_out_t aout[1] = {{INT2FIX(0),0}};
    ndfunc_t ndf = {iter_dfloat_median, STRIDE_LOOP_NIP|NDF_FLAT_REDUCE, 2,1, ain,aout};

    self = na_copy(self);
    reduce = na_reduce_dimension(argc, argv, 1, &self); // v[0] = self

    return na_ndloop(&ndf, 2, self, reduce);
}

#min(*args) ⇒ Numo::DFloat

Min of self.

Parameters:

  • args (Array of Numeric, Range)

    Affected dimensions.

Returns:



3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
# File 'ext/numo/narray/types/dfloat.c', line 3602

static VALUE
numo_dfloat_min(int argc, VALUE *argv, VALUE self)
{
    VALUE v, reduce;
    ndfunc_arg_in_t ain[2] = {{cT,0},{sym_reduce,0}};
    ndfunc_arg_out_t aout[1] = {{cT,0}};
    ndfunc_t ndf = { iter_dfloat_min, STRIDE_LOOP_NIP|NDF_FLAT_REDUCE, 2, 1, ain, aout };

    reduce = na_reduce_dimension(argc, argv, 1, &self);
    v =  na_ndloop(&ndf, 2, self, reduce);
#line 32 "/home/masa/numo/narray/ext/numo/narray/gen/tmpl/accum.c"
    return numo_dfloat_extract(v);
#line 36 "/home/masa/numo/narray/ext/numo/narray/gen/tmpl/accum.c"
}

#min_indexInteger #min_index(dim0, dim1, ..) ⇒ Integer, Numo::Int32/64

Return an index of result.

Numo::NArray[3,4,1,2].min_index => 3

Overloads:

  • #min_indexInteger

    Returns:

    • (Integer)
  • #min_index(dim0, dim1, ..) ⇒ Integer, Numo::Int32/64

    Returns:



3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
# File 'ext/numo/narray/types/dfloat.c', line 3788

static VALUE
numo_dfloat_min_index(int argc, VALUE *argv, VALUE self)
{
    narray_t *na;
    VALUE idx, reduce;
    ndfunc_arg_in_t ain[3] = {{Qnil,0},{Qnil,0},{sym_reduce,0}};
    ndfunc_arg_out_t aout[1] = {{0,0,0}};
    ndfunc_t ndf = {0, STRIDE_LOOP_NIP|NDF_FLAT_REDUCE|NDF_EXTRACT, 3,1, ain,aout};

    GetNArray(self,na);
    if (na->ndim==0) {
        return INT2FIX(0);
    }
    if (na->size > (~(u_int32_t)0)) {
        aout[0].type = numo_cInt64;
        idx = rb_narray_new(numo_cInt64, na->ndim, na->shape);
        ndf.func = iter_dfloat_min_index_index64;
    } else {
        aout[0].type = numo_cInt32;
        idx = rb_narray_new(numo_cInt32, na->ndim, na->shape);
        ndf.func = iter_dfloat_min_index_index32;
    }
    rb_funcall(idx, rb_intern("seq"), 0);

    reduce = na_reduce_dimension(argc, argv, 1, &self);

    return na_ndloop(&ndf, 3, self, idx, reduce);
}

#minmax(*args) ⇒ Numo::DFloat

Minmax of self.

Parameters:

  • args (Array of Numeric, Range)

    Affected dimensions.

Returns:



3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
# File 'ext/numo/narray/types/dfloat.c', line 3856

static VALUE
numo_dfloat_minmax(int argc, VALUE *argv, VALUE self)
{
    VALUE reduce;
    ndfunc_arg_in_t ain[2] = {{cT,0},{sym_reduce,0}};
    ndfunc_arg_out_t aout[2] = {{cT,0},{cT,0}};
    ndfunc_t ndf = {iter_dfloat_minmax, STRIDE_LOOP_NIP|NDF_FLAT_REDUCE|NDF_EXTRACT, 2,2, ain,aout};

    reduce = na_reduce_dimension(argc, argv, 1, &self);
    return na_ndloop(&ndf, 2, self, reduce);
}

#mulsum(other) ⇒ Numo::NArray

Binary mulsum.

Parameters:

Returns:



4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
# File 'ext/numo/narray/types/dfloat.c', line 4023

static VALUE
numo_dfloat_mulsum(int argc, VALUE *argv, VALUE self)
{
    
    VALUE klass, v;
    
    if (argc < 1) {
        rb_raise(rb_eArgError,"wrong number of arguments (%d for >=1)",argc);
    }
    
#line 73 "/home/masa/numo/narray/ext/numo/narray/gen/tmpl/accum_binary.c"
    klass = na_upcast(CLASS_OF(self),CLASS_OF(argv[0]));
    if (klass==cT) {
        return numo_dfloat_mulsum_self(argc, argv, self);
    } else {
        v = rb_funcall(klass, id_cast, 1, self);
        return rb_funcall2(v, rb_intern("mulsum"), argc, argv);
    }
    
}

#ne(other) ⇒ Numo::Bit

Comparison ne other.

Parameters:

Returns:



2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
# File 'ext/numo/narray/types/dfloat.c', line 2495

static VALUE
numo_dfloat_ne(VALUE self, VALUE other)
{
    
#line 46 "/home/masa/numo/narray/ext/numo/narray/gen/tmpl/cond_binary.c"
    VALUE klass, v;
    klass = na_upcast(CLASS_OF(self),CLASS_OF(other));
    if (klass==cT) {
        return numo_dfloat_ne_self(self, other);
    } else {
        v = rb_funcall(klass, id_cast, 1, self);
        return rb_funcall(v, id_ne, 1, other);
    }
    
}

#nearly_eq(other) ⇒ Numo::Bit Also known as: close_to

Comparison nearly_eq other.

Parameters:

Returns:

  • (Numo::Bit)

    result of self nearly_eq other.



2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
# File 'ext/numo/narray/types/dfloat.c', line 2553

static VALUE
numo_dfloat_nearly_eq(VALUE self, VALUE other)
{
    
#line 46 "/home/masa/numo/narray/ext/numo/narray/gen/tmpl/cond_binary.c"
    VALUE klass, v;
    klass = na_upcast(CLASS_OF(self),CLASS_OF(other));
    if (klass==cT) {
        return numo_dfloat_nearly_eq_self(self, other);
    } else {
        v = rb_funcall(klass, id_cast, 1, self);
        return rb_funcall(v, id_nearly_eq, 1, other);
    }
    
}

#poly(a0, a1, ...) ⇒ Numo::DFloat

Polynomial.: a0 + a1*x + a2*x**2 + a3*x**3 + … + an*x**n

Parameters:

Returns:



4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
# File 'ext/numo/narray/types/dfloat.c', line 4549

static VALUE
numo_dfloat_poly(VALUE self, VALUE args)
{
    int argc, i;
    VALUE *argv;
    volatile VALUE v, a;
    ndfunc_arg_out_t aout[1] = {{cT,0}};
    ndfunc_t ndf = { iter_dfloat_poly, NO_LOOP, 0, 1, 0, aout };

    argc = RARRAY_LEN(args);
    ndf.nin = argc+1;
    ndf.ain = ALLOCA_N(ndfunc_arg_in_t,argc+1);
    for (i=0; i<argc+1; i++) {
        ndf.ain[i].type = cT;
    }
    argv = ALLOCA_N(VALUE,argc+1);
    argv[0] = self;
    for (i=0; i<argc; i++) {
        argv[i+1] = RARRAY_PTR(args)[i];
    }
    a = rb_ary_new4(argc+1, argv);
    v = na_ndloop2(&ndf, a);
    return numo_dfloat_extract(v);
}

#prod(*args) ⇒ Numo::DFloat

Prod of self.

Parameters:

  • args (Array of Numeric, Range)

    Affected dimensions.

Returns:



3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
# File 'ext/numo/narray/types/dfloat.c', line 3374

static VALUE
numo_dfloat_prod(int argc, VALUE *argv, VALUE self)
{
    VALUE v, reduce;
    ndfunc_arg_in_t ain[2] = {{cT,0},{sym_reduce,0}};
    ndfunc_arg_out_t aout[1] = {{cT,0}};
    ndfunc_t ndf = { iter_dfloat_prod, STRIDE_LOOP_NIP|NDF_FLAT_REDUCE, 2, 1, ain, aout };

    reduce = na_reduce_dimension(argc, argv, 1, &self);
    v =  na_ndloop(&ndf, 2, self, reduce);
#line 32 "/home/masa/numo/narray/ext/numo/narray/gen/tmpl/accum.c"
    return numo_dfloat_extract(v);
#line 36 "/home/masa/numo/narray/ext/numo/narray/gen/tmpl/accum.c"
}

#rand([[low],high]) ⇒ Numo::DFloat

Generate uniformly distributed random numbers on self narray.

Examples:

Numo::DFloat.new(6).rand
=> Numo::DFloat#shape=[6]
   [0.0617545, 0.373067, 0.794815, 0.201042, 0.116041, 0.344032]
Numo::DComplex.new(6).rand(5+5i)
=> Numo::DComplex#shape=[6]
   [2.69974+3.68908i, 0.825443+0.254414i, 0.540323+0.34354i, 4.52061+2.39322i, ...]
Numo::Int32.new(6).rand(2,5)
=> Numo::Int32#shape=[6]
   [4, 3, 3, 2, 4, 2]

Parameters:

  • low (Numeric)

    lower inclusive boundary of random numbers. (default=0)

  • high (Numeric)

    upper exclusive boundary of random numbers. (default=1 or 1+1i for complex types)

Returns:



4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
# File 'ext/numo/narray/types/dfloat.c', line 4375

static VALUE
numo_dfloat_rand(int argc, VALUE *args, VALUE self)
{
    rand_opt_t g;
    VALUE v1=Qnil, v2=Qnil;
    dtype high;
    ndfunc_arg_in_t ain[1] = {{OVERWRITE,0}};
    ndfunc_t ndf = {iter_dfloat_rand, FULL_LOOP, 1,0, ain,0};

    
#line 140 "/home/masa/numo/narray/ext/numo/narray/gen/tmpl/rand.c"
    rb_scan_args(argc, args, "02", &v1, &v2);
    if (v2==Qnil) {
        g.low = m_zero;
        if (v1==Qnil) {
            
#line 147 "/home/masa/numo/narray/ext/numo/narray/gen/tmpl/rand.c"
            g.max = high = m_one;
            
        } else {
            g.max = high = m_num_to_data(v1);
        }
    
    } else {
        g.low = m_num_to_data(v1);
        high = m_num_to_data(v2);
        g.max = m_sub(high,g.low);
    }
    
#line 163 "/home/masa/numo/narray/ext/numo/narray/gen/tmpl/rand.c"
    na_ndloop3(&ndf, &g, 1, self);
    return self;
}

#rand_norm([mu,[sigma]]) ⇒ Numo::DFloat

Generates random numbers from the normal distribution on self narray using Box-Muller Transformation.

Examples:

Numo::DFloat.new(5,5).rand_norm
=> Numo::DFloat#shape=[5,5]
   [[-0.581255, -0.168354, 0.586895, -0.595142, -0.802802],
    [-0.326106, 0.282922, 1.68427, 0.918499, -0.0485384],
    [-0.464453, -0.992194, 0.413794, -0.60717, -0.699695],
    [-1.64168, 0.48676, -0.875871, -1.43275, 0.812172],
    [-0.209975, -0.103612, -0.878617, -1.42495, 1.0968]]
Numo::DFloat.new(5,5).rand_norm(10,0.1)
=> Numo::DFloat#shape=[5,5]
   [[9.9019, 9.90339, 10.0826, 9.98384, 9.72861],
    [9.81507, 10.0272, 9.91445, 10.0568, 9.88923],
    [10.0234, 9.97874, 9.96011, 9.9006, 9.99964],
    [10.0186, 9.94598, 9.92236, 9.99811, 9.97003],
    [9.79266, 9.95044, 9.95212, 9.93692, 10.2027]]
Numo::DComplex.new(3,3).rand_norm(5+5i)
=> Numo::DComplex#shape=[3,3]
   [[5.84303+4.40052i, 4.00984+6.08982i, 5.10979+5.13215i],
    [4.26477+3.99655i, 4.90052+5.00763i, 4.46607+2.3444i],
    [4.5528+7.11003i, 5.62117+6.69094i, 5.05443+5.35133i]]

Parameters:

  • mu (Numeric)

    mean of normal distribution. (default=0)

  • sigma (Numeric)

    standard deviation of normal distribution. (default=1)

Returns:



4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
# File 'ext/numo/narray/types/dfloat.c', line 4497

static VALUE
numo_dfloat_rand_norm(int argc, VALUE *args, VALUE self)
{
    int n;
    randn_opt_t g;
    VALUE v1=Qnil, v2=Qnil;
    ndfunc_arg_in_t ain[1] = {{OVERWRITE,0}};
    ndfunc_t ndf = {iter_dfloat_rand_norm, FULL_LOOP, 1,0, ain,0};

    n = rb_scan_args(argc, args, "02", &v1, &v2);
    if (n == 0) {
        g.mu = m_zero;
    } else {
        g.mu = m_num_to_data(v1);
    }
    if (n == 2) {
        g.sigma = NUM2DBL(v2);
    } else {
        g.sigma = 1;
    }
    na_ndloop3(&ndf, &g, 1, self);
    return self;
}

#reciprocalNumo::DFloat

Unary reciprocal.

Returns:



2323
2324
2325
2326
2327
2328
2329
2330
2331
# File 'ext/numo/narray/types/dfloat.c', line 2323

static VALUE
numo_dfloat_reciprocal(VALUE self)
{
    ndfunc_arg_in_t ain[1] = {{cT,0}};
    ndfunc_arg_out_t aout[1] = {{cT,0}};
    ndfunc_t ndf = {iter_dfloat_reciprocal, FULL_LOOP, 1,1, ain,aout};

    return na_ndloop(&ndf, 1, self);
}

#rintNumo::DFloat

Unary rint.

Returns:



2869
2870
2871
2872
2873
2874
2875
2876
2877
# File 'ext/numo/narray/types/dfloat.c', line 2869

static VALUE
numo_dfloat_rint(VALUE self)
{
    ndfunc_arg_in_t ain[1] = {{cT,0}};
    ndfunc_arg_out_t aout[1] = {{cT,0}};
    ndfunc_t ndf = {iter_dfloat_rint, FULL_LOOP, 1,1, ain,aout};

    return na_ndloop(&ndf, 1, self);
}

#rms(*args) ⇒ Numo::DFloat

Rms of self.

Parameters:

  • args (Array of Numeric, Range)

    Affected dimensions.

Returns:



3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
# File 'ext/numo/narray/types/dfloat.c', line 3564

static VALUE
numo_dfloat_rms(int argc, VALUE *argv, VALUE self)
{
    VALUE v, reduce;
    ndfunc_arg_in_t ain[2] = {{cT,0},{sym_reduce,0}};
    ndfunc_arg_out_t aout[1] = {{cRT,0}};
    ndfunc_t ndf = { iter_dfloat_rms, STRIDE_LOOP_NIP|NDF_FLAT_REDUCE, 2, 1, ain, aout };

    reduce = na_reduce_dimension(argc, argv, 1, &self);
    v =  na_ndloop(&ndf, 2, self, reduce);
#line 34 "/home/masa/numo/narray/ext/numo/narray/gen/tmpl/accum.c"
    return rb_funcall(v,rb_intern("extract"),0);
#line 36 "/home/masa/numo/narray/ext/numo/narray/gen/tmpl/accum.c"
}

#roundNumo::DFloat

Unary round.

Returns:



2683
2684
2685
2686
2687
2688
2689
2690
2691
# File 'ext/numo/narray/types/dfloat.c', line 2683

static VALUE
numo_dfloat_round(VALUE self)
{
    ndfunc_arg_in_t ain[1] = {{cT,0}};
    ndfunc_arg_out_t aout[1] = {{cT,0}};
    ndfunc_t ndf = {iter_dfloat_round, FULL_LOOP, 1,1, ain,aout};

    return na_ndloop(&ndf, 1, self);
}

#seq([beg,[step]]) ⇒ Numo::DFloat Also known as: indgen

Set linear sequence of numbers to self. The sequence is obtained from

beg+i*step

where i is 1-dimensional index.

Examples:

Numo::DFloat.new(6).seq(1,-0.2)
=> Numo::DFloat#shape=[6]
   [1, 0.8, 0.6, 0.4, 0.2, 0]
Numo::DComplex.new(6).seq(1,-0.2+0.2i)
=> Numo::DComplex#shape=[6]
   [1+0i, 0.8+0.2i, 0.6+0.4i, 0.4+0.6i, 0.2+0.8i, 0+1i]

Parameters:

  • beg (Numeric)

    begining of sequence. (default=0)

  • step (Numeric)

    step of sequence. (default=1)

Returns:



4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
# File 'ext/numo/narray/types/dfloat.c', line 4110

static VALUE
numo_dfloat_seq(int argc, VALUE *args, VALUE self)
{
    seq_opt_t *g;
    VALUE vbeg=Qnil, vstep=Qnil;
    ndfunc_arg_in_t ain[1] = {{OVERWRITE,0}};
    ndfunc_t ndf = {iter_dfloat_seq, FULL_LOOP, 1,0, ain,0};

    g = ALLOCA_N(seq_opt_t,1);
    g->beg = m_zero;
    g->step = m_one;
    g->count = 0;
    rb_scan_args(argc, args, "02", &vbeg, &vstep);
#line 86 "/home/masa/numo/narray/ext/numo/narray/gen/tmpl/seq.c"
    if (vbeg!=Qnil) {g->beg = m_num_to_data(vbeg);}
    if (vstep!=Qnil) {g->step = m_num_to_data(vstep);}

#line 90 "/home/masa/numo/narray/ext/numo/narray/gen/tmpl/seq.c"
    na_ndloop3(&ndf, g, 1, self);
    return self;
}

#signNumo::DFloat

Unary sign.

Returns:



2385
2386
2387
2388
2389
2390
2391
2392
2393
# File 'ext/numo/narray/types/dfloat.c', line 2385

static VALUE
numo_dfloat_sign(VALUE self)
{
    ndfunc_arg_in_t ain[1] = {{cT,0}};
    ndfunc_arg_out_t aout[1] = {{cT,0}};
    ndfunc_t ndf = {iter_dfloat_sign, FULL_LOOP, 1,1, ain,aout};

    return na_ndloop(&ndf, 1, self);
}

#sortObject #sort(dim0, dim1, ...) ⇒ Object

Return an index array of sort result.

Numo::DFloat[3,4,1,2].sort => Numo::DFloat[1,2,3,4]


4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
# File 'ext/numo/narray/types/dfloat.c', line 4745

static VALUE
numo_dfloat_sort(int argc, VALUE *argv, VALUE self)
{
    VALUE reduce;
    ndfunc_arg_in_t ain[2] = {{OVERWRITE,0},{sym_reduce,0}};
    ndfunc_t ndf = {iter_dfloat_sort, STRIDE_LOOP_NIP|NDF_INPLACE|NDF_FLAT_REDUCE, 2,0, ain,0};

    if (!TEST_INPLACE(self)) {
        self = na_copy(self);
    }
    reduce = na_reduce_dimension(argc, argv, 1, &self); // v[0] = self

    na_ndloop(&ndf, 2, self, reduce);
    return self;
}

#sort_indexObject #sort_index(dim0, dim1, ..) ⇒ Object

Return an index array of sort result.

Numo::NArray[3,4,1,2].sort_index => Numo::Int32[2,3,0,1]


4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
# File 'ext/numo/narray/types/dfloat.c', line 4999

static VALUE
numo_dfloat_sort_index(int argc, VALUE *argv, VALUE self)
{
    size_t size;
    narray_t *na;
    VALUE idx, tmp, reduce, res;
    char *buf;
    ndfunc_arg_in_t ain[3] = {{cT,0},{0,0},{sym_reduce,0}};
    ndfunc_arg_out_t aout[1] = {{0,0,0}};
    ndfunc_t ndf = {0, STRIDE_LOOP_NIP|NDF_FLAT_REDUCE|NDF_CUM, 3,1, ain,aout};

    GetNArray(self,na);
    if (na->ndim==0) {
        return INT2FIX(0);
    }
    if (na->size > (~(u_int32_t)0)) {
        ain[1].type =
        aout[0].type = numo_cInt64;
        idx = rb_narray_new(numo_cInt64, na->ndim, na->shape);
        ndf.func = dfloat_index64_qsort;
    } else {
        ain[1].type =
        aout[0].type = numo_cInt32;
        idx = rb_narray_new(numo_cInt32, na->ndim, na->shape);
        ndf.func = dfloat_index32_qsort;
    }
    rb_funcall(idx, rb_intern("seq"), 0);

    reduce = na_reduce_dimension(argc, argv, 1, &self); // v[0] = self

    size = na->size*sizeof(void*);
    buf = rb_alloc_tmp_buffer(&tmp, size);
    res = na_ndloop3(&ndf, buf, 3, self, idx, reduce);
    rb_free_tmp_buffer(&tmp);
    return res;
}

#stddev(*args) ⇒ Numo::DFloat

Stddev of self.

Parameters:

  • args (Array of Numeric, Range)

    Affected dimensions.

Returns:



3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
# File 'ext/numo/narray/types/dfloat.c', line 3488

static VALUE
numo_dfloat_stddev(int argc, VALUE *argv, VALUE self)
{
    VALUE v, reduce;
    ndfunc_arg_in_t ain[2] = {{cT,0},{sym_reduce,0}};
    ndfunc_arg_out_t aout[1] = {{cRT,0}};
    ndfunc_t ndf = { iter_dfloat_stddev, STRIDE_LOOP_NIP|NDF_FLAT_REDUCE, 2, 1, ain, aout };

    reduce = na_reduce_dimension(argc, argv, 1, &self);
    v =  na_ndloop(&ndf, 2, self, reduce);
#line 34 "/home/masa/numo/narray/ext/numo/narray/gen/tmpl/accum.c"
    return rb_funcall(v,rb_intern("extract"),0);
#line 36 "/home/masa/numo/narray/ext/numo/narray/gen/tmpl/accum.c"
}

#store(other) ⇒ Numo::DFloat

Store elements to Numo::DFloat from other.

Parameters:

  • other (Object)

Returns:



948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
# File 'ext/numo/narray/types/dfloat.c', line 948

static VALUE
numo_dfloat_store(VALUE self, VALUE obj)
{
    VALUE r;

    
    if (FIXNUM_P(obj) || TYPE(obj)==T_FLOAT || TYPE(obj)==T_BIGNUM || rb_obj_is_kind_of(obj,rb_cComplex)) {
        numo_dfloat_store_numeric(self,obj);
        return self;
    }
    
#line 13 "/home/masa/numo/narray/ext/numo/narray/gen/tmpl/store.c"
    if (rb_obj_is_kind_of(obj,numo_cBit)) {
        numo_dfloat_store_bit(self,obj);
        return self;
    }
    
#line 13 "/home/masa/numo/narray/ext/numo/narray/gen/tmpl/store.c"
    if (rb_obj_is_kind_of(obj,numo_cDFloat)) {
        numo_dfloat_store_dfloat(self,obj);
        return self;
    }
    
#line 13 "/home/masa/numo/narray/ext/numo/narray/gen/tmpl/store.c"
    if (rb_obj_is_kind_of(obj,numo_cSFloat)) {
        numo_dfloat_store_sfloat(self,obj);
        return self;
    }
    
#line 13 "/home/masa/numo/narray/ext/numo/narray/gen/tmpl/store.c"
    if (rb_obj_is_kind_of(obj,numo_cInt64)) {
        numo_dfloat_store_int64(self,obj);
        return self;
    }
    
#line 13 "/home/masa/numo/narray/ext/numo/narray/gen/tmpl/store.c"
    if (rb_obj_is_kind_of(obj,numo_cInt32)) {
        numo_dfloat_store_int32(self,obj);
        return self;
    }
    
#line 13 "/home/masa/numo/narray/ext/numo/narray/gen/tmpl/store.c"
    if (rb_obj_is_kind_of(obj,numo_cInt16)) {
        numo_dfloat_store_int16(self,obj);
        return self;
    }
    
#line 13 "/home/masa/numo/narray/ext/numo/narray/gen/tmpl/store.c"
    if (rb_obj_is_kind_of(obj,numo_cInt8)) {
        numo_dfloat_store_int8(self,obj);
        return self;
    }
    
#line 13 "/home/masa/numo/narray/ext/numo/narray/gen/tmpl/store.c"
    if (rb_obj_is_kind_of(obj,numo_cUInt64)) {
        numo_dfloat_store_uint64(self,obj);
        return self;
    }
    
#line 13 "/home/masa/numo/narray/ext/numo/narray/gen/tmpl/store.c"
    if (rb_obj_is_kind_of(obj,numo_cUInt32)) {
        numo_dfloat_store_uint32(self,obj);
        return self;
    }
    
#line 13 "/home/masa/numo/narray/ext/numo/narray/gen/tmpl/store.c"
    if (rb_obj_is_kind_of(obj,numo_cUInt16)) {
        numo_dfloat_store_uint16(self,obj);
        return self;
    }
    
#line 13 "/home/masa/numo/narray/ext/numo/narray/gen/tmpl/store.c"
    if (rb_obj_is_kind_of(obj,numo_cUInt8)) {
        numo_dfloat_store_uint8(self,obj);
        return self;
    }
    
#line 13 "/home/masa/numo/narray/ext/numo/narray/gen/tmpl/store.c"
    if (rb_obj_is_kind_of(obj,numo_cRObject)) {
        numo_dfloat_store_robject(self,obj);
        return self;
    }
    
#line 13 "/home/masa/numo/narray/ext/numo/narray/gen/tmpl/store.c"
    if (TYPE(obj)==T_ARRAY) {
        numo_dfloat_store_array(self,obj);
        return self;
    }
    

    if (IsNArray(obj)) {
        r = rb_funcall(obj, rb_intern("coerce_cast"), 1, cT);
        if (CLASS_OF(r)==cT) {
            numo_dfloat_store(self,r);
            return self;
        }
    }

    
#line 30 "/home/masa/numo/narray/ext/numo/narray/gen/tmpl/store.c"
    rb_raise(nary_eCastError, "unknown conversion from %s to %s",
             rb_class2name(CLASS_OF(obj)),
             rb_class2name(CLASS_OF(self)));
    
    return self;
}

#sum(*args) ⇒ Numo::DFloat

Sum of self.

Parameters:

  • args (Array of Numeric, Range)

    Affected dimensions.

Returns:



3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
# File 'ext/numo/narray/types/dfloat.c', line 3336

static VALUE
numo_dfloat_sum(int argc, VALUE *argv, VALUE self)
{
    VALUE v, reduce;
    ndfunc_arg_in_t ain[2] = {{cT,0},{sym_reduce,0}};
    ndfunc_arg_out_t aout[1] = {{cT,0}};
    ndfunc_t ndf = { iter_dfloat_sum, STRIDE_LOOP_NIP|NDF_FLAT_REDUCE, 2, 1, ain, aout };

    reduce = na_reduce_dimension(argc, argv, 1, &self);
    v =  na_ndloop(&ndf, 2, self, reduce);
#line 32 "/home/masa/numo/narray/ext/numo/narray/gen/tmpl/accum.c"
    return numo_dfloat_extract(v);
#line 36 "/home/masa/numo/narray/ext/numo/narray/gen/tmpl/accum.c"
}

#to_aArray

Convert self to Array.

Returns:

  • (Array)


1271
1272
1273
1274
1275
1276
1277
1278
# File 'ext/numo/narray/types/dfloat.c', line 1271

static VALUE
numo_dfloat_to_a(VALUE self)
{
    ndfunc_arg_in_t ain[3] = {{Qnil,0},{sym_loop_opt},{sym_option}};
    ndfunc_arg_out_t aout[1] = {{rb_cArray,0}}; // dummy?
    ndfunc_t ndf = { iter_dfloat_to_a, FULL_LOOP_NIP, 3, 1, ain, aout };
    return na_ndloop_cast_narray_to_rarray(&ndf, self, Qnil);
}

#truncNumo::DFloat

Unary trunc.

Returns:



2807
2808
2809
2810
2811
2812
2813
2814
2815
# File 'ext/numo/narray/types/dfloat.c', line 2807

static VALUE
numo_dfloat_trunc(VALUE self)
{
    ndfunc_arg_in_t ain[1] = {{cT,0}};
    ndfunc_arg_out_t aout[1] = {{cT,0}};
    ndfunc_t ndf = {iter_dfloat_trunc, FULL_LOOP, 1,1, ain,aout};

    return na_ndloop(&ndf, 1, self);
}

#var(*args) ⇒ Numo::DFloat

Var of self.

Parameters:

  • args (Array of Numeric, Range)

    Affected dimensions.

Returns:



3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
# File 'ext/numo/narray/types/dfloat.c', line 3526

static VALUE
numo_dfloat_var(int argc, VALUE *argv, VALUE self)
{
    VALUE v, reduce;
    ndfunc_arg_in_t ain[2] = {{cT,0},{sym_reduce,0}};
    ndfunc_arg_out_t aout[1] = {{cRT,0}};
    ndfunc_t ndf = { iter_dfloat_var, STRIDE_LOOP_NIP|NDF_FLAT_REDUCE, 2, 1, ain, aout };

    reduce = na_reduce_dimension(argc, argv, 1, &self);
    v =  na_ndloop(&ndf, 2, self, reduce);
#line 34 "/home/masa/numo/narray/ext/numo/narray/gen/tmpl/accum.c"
    return rb_funcall(v,rb_intern("extract"),0);
#line 36 "/home/masa/numo/narray/ext/numo/narray/gen/tmpl/accum.c"
}