Class: Numo::RObject

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

Constant Summary

UPCAST =
hCast
ELEMENT_BIT_SIZE =
INT2FIX(sizeof(dtype)*8)
ELEMENT_BYTE_SIZE =
INT2FIX(sizeof(dtype))
CONTIGUOUS_STRIDE =
INT2FIX(sizeof(dtype))

Constants inherited from NArray

NArray::VERSION

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from NArray

#==, #append, array_type, asarray, #at, byte_size, #byte_size, #byte_swapped?, #cast_to, #coerce, #column_major?, column_stack, concatenate, #concatenate, #contiguous?, #cov, debug=, #debug_info, #deg2rad, #delete, #diag, #diag_indices, diag_indices, #diagonal, #diff, #dot, #dsplit, dstack, #empty?, #expand_dims, eye, #flatten, #fliplr, #flipud, from_binary, #host_order?, #hsplit, hstack, #initialize, #initialize_copy, #inner, #inplace, #inplace!, #inplace?, #insert, inspect_cols, inspect_cols=, inspect_rows, inspect_rows=, #kron, linspace, logspace, #marshal_dump, #marshal_load, #ndim, #new_fill, new_like, #new_narray, #new_ones, #new_zeros, ones, #out_of_place!, #outer, parse, profile, profile=, #rad2deg, #repeat, #reshape, #reshape!, #reverse, #rot90, #row_major?, #shape, #size, #split, srand, #store_binary, #swap_byte, #swapaxes, #tile, #to_binary, #to_c, #to_f, #to_host, #to_i, #to_network, #to_swapped, #to_vacs, #trace, #transpose, #tril, #tril!, #tril_indices, tril_indices, #triu, #triu!, #triu_indices, triu_indices, upcast, #view, #vsplit, vstack, zeros

Constructor Details

This class inherits a constructor from Numo::NArray

Class Method Details

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

Cast object to Numo::RObject.

Parameters:

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

Returns:



1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
# File 'ext/numo/narray/types/robject.c', line 1303

static VALUE
robject_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 robject_new_dim0(x);
    }
    if (RTEST(rb_obj_is_kind_of(obj,rb_cArray))) {
        return robject_cast_array(obj);
    }
    if (IsNArray(obj)) {
        GetNArray(obj,na);
        v = nary_new(cT, NA_NDIM(na), NA_SHAPE(na));
        if (NA_SIZE(na) > 0) {
            robject_store(v,obj);
        }
        return v;
    }
    
    return robject_new_dim0(obj);
    
#line 44 "gen/tmpl/cast.c"
}

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

Cast object to Numo::RObject.

Parameters:

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

Returns:



1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
# File 'ext/numo/narray/types/robject.c', line 1303

static VALUE
robject_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 robject_new_dim0(x);
    }
    if (RTEST(rb_obj_is_kind_of(obj,rb_cArray))) {
        return robject_cast_array(obj);
    }
    if (IsNArray(obj)) {
        GetNArray(obj,na);
        v = nary_new(cT, NA_NDIM(na), NA_SHAPE(na));
        if (NA_SIZE(na) > 0) {
            robject_store(v,obj);
        }
        return v;
    }
    
    return robject_new_dim0(obj);
    
#line 44 "gen/tmpl/cast.c"
}

.maximum(*args) ⇒ Object



4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
# File 'ext/numo/narray/types/robject.c', line 4961

static VALUE
robject_s_maximum(int argc, VALUE *argv, VALUE mod)
{
    VALUE a1 = Qnil;
    VALUE a2 = Qnil;
    ndfunc_arg_in_t ain[2] = {{cT,0},{cT,0}};
    ndfunc_arg_out_t aout[1] = {{cT,0}};
    ndfunc_t ndf = { iter_robject_s_maximum, STRIDE_LOOP_NIP, 2, 1, ain, aout };

    
    VALUE kw_hash = Qnil;
    ID kw_table[1] = {id_nan};
    VALUE opts[1] = {Qundef};

    rb_scan_args(argc, argv, "20:", &a1, &a2, &kw_hash);
    rb_get_kwargs(kw_hash, kw_table, 0, 1, opts);
    if (opts[0] != Qundef) {
        ndf.func = iter_robject_s_maximum_nan;
    }
    

#line 63 "gen/tmpl/ewcomp.c"
    return na_ndloop(&ndf, 2, a1, a2);
}

.minimum(*args) ⇒ Object



5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
# File 'ext/numo/narray/types/robject.c', line 5044

static VALUE
robject_s_minimum(int argc, VALUE *argv, VALUE mod)
{
    VALUE a1 = Qnil;
    VALUE a2 = Qnil;
    ndfunc_arg_in_t ain[2] = {{cT,0},{cT,0}};
    ndfunc_arg_out_t aout[1] = {{cT,0}};
    ndfunc_t ndf = { iter_robject_s_minimum, STRIDE_LOOP_NIP, 2, 1, ain, aout };

    
    VALUE kw_hash = Qnil;
    ID kw_table[1] = {id_nan};
    VALUE opts[1] = {Qundef};

    rb_scan_args(argc, argv, "20:", &a1, &a2, &kw_hash);
    rb_get_kwargs(kw_hash, kw_table, 0, 1, opts);
    if (opts[0] != Qundef) {
        ndf.func = iter_robject_s_minimum_nan;
    }
    

#line 63 "gen/tmpl/ewcomp.c"
    return na_ndloop(&ndf, 2, a1, a2);
}

Instance Method Details

#%(other) ⇒ Numo::NArray

Binary mod.

Parameters:

Returns:



2316
2317
2318
2319
2320
2321
2322
2323
# File 'ext/numo/narray/types/robject.c', line 2316

static VALUE
robject_mod(VALUE self, VALUE other)
{
    
    return robject_mod_self(self, other);
    
#line 97 "gen/tmpl/binary.c"
}

#&(other) ⇒ Numo::NArray

Binary bit_and.

Parameters:

Returns:



2919
2920
2921
2922
2923
2924
2925
2926
# File 'ext/numo/narray/types/robject.c', line 2919

static VALUE
robject_bit_and(VALUE self, VALUE other)
{
    
    return robject_bit_and_self(self, other);
    
#line 97 "gen/tmpl/binary.c"
}

#*(other) ⇒ Numo::NArray

Binary mul.

Parameters:

Returns:



2192
2193
2194
2195
2196
2197
2198
2199
# File 'ext/numo/narray/types/robject.c', line 2192

static VALUE
robject_mul(VALUE self, VALUE other)
{
    
    return robject_mul_self(self, other);
    
#line 97 "gen/tmpl/binary.c"
}

#**(other) ⇒ Numo::NArray

Binary power.

Parameters:

Returns:



2443
2444
2445
2446
2447
2448
2449
2450
# File 'ext/numo/narray/types/robject.c', line 2443

static VALUE
robject_pow(VALUE self, VALUE other)
{
    
    return robject_pow_self(self,other);
    
#line 78 "gen/tmpl/pow.c"
}

#+(other) ⇒ Numo::NArray

Binary add.

Parameters:

Returns:



2076
2077
2078
2079
2080
2081
2082
2083
# File 'ext/numo/narray/types/robject.c', line 2076

static VALUE
robject_add(VALUE self, VALUE other)
{
    
    return robject_add_self(self, other);
    
#line 97 "gen/tmpl/binary.c"
}

#-(other) ⇒ Numo::NArray

Binary sub.

Parameters:

Returns:



2134
2135
2136
2137
2138
2139
2140
2141
# File 'ext/numo/narray/types/robject.c', line 2134

static VALUE
robject_sub(VALUE self, VALUE other)
{
    
    return robject_sub_self(self, other);
    
#line 97 "gen/tmpl/binary.c"
}

#-@Numo::RObject

Unary minus.

Returns:



2508
2509
2510
2511
2512
2513
2514
2515
2516
# File 'ext/numo/narray/types/robject.c', line 2508

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

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

#/(other) ⇒ Numo::NArray

Binary div.

Parameters:

Returns:



2254
2255
2256
2257
2258
2259
2260
2261
# File 'ext/numo/narray/types/robject.c', line 2254

static VALUE
robject_div(VALUE self, VALUE other)
{
    
    return robject_div_self(self, other);
    
#line 97 "gen/tmpl/binary.c"
}

#<<(other) ⇒ Numo::NArray

Binary left_shift.

Parameters:

Returns:



3159
3160
3161
3162
3163
3164
3165
3166
# File 'ext/numo/narray/types/robject.c', line 3159

static VALUE
robject_left_shift(VALUE self, VALUE other)
{
    
    return robject_left_shift_self(self, other);
    
#line 97 "gen/tmpl/binary.c"
}

#>>(other) ⇒ Numo::NArray

Binary right_shift.

Parameters:

Returns:



3217
3218
3219
3220
3221
3222
3223
3224
# File 'ext/numo/narray/types/robject.c', line 3217

static VALUE
robject_right_shift(VALUE self, VALUE other)
{
    
    return robject_right_shift_self(self, other);
    
#line 97 "gen/tmpl/binary.c"
}

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

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::RObject)

    Element object or NArray view.



1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
# File 'ext/numo/narray/types/robject.c', line 1374

static VALUE
robject_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).



1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
# File 'ext/numo/narray/types/robject.c', line 1431

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

    argc--;
    if (argc==0) {
        robject_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);
            robject_store(a, argv[argc]);
        } else {
            x = robject_extract_data(argv[argc]);
            ptr = na_get_pointer_for_read_write(self) + pos;
            *(dtype*)ptr = x;
        }

    }
    return argv[argc];
}

#^(other) ⇒ Numo::NArray

Binary bit_xor.

Parameters:

Returns:



3035
3036
3037
3038
3039
3040
3041
3042
# File 'ext/numo/narray/types/robject.c', line 3035

static VALUE
robject_bit_xor(VALUE self, VALUE other)
{
    
    return robject_bit_xor_self(self, other);
    
#line 97 "gen/tmpl/binary.c"
}

#absNumo::RObject

abs of self.

Returns:



2017
2018
2019
2020
2021
2022
2023
2024
2025
# File 'ext/numo/narray/types/robject.c', line 2017

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

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

#allocateObject



178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
# File 'ext/numo/narray/types/robject.c', line 178

static VALUE
robject_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);
            
            {   size_t i;
                VALUE *a = (VALUE*)ptr;
                for (i=na->size; i--;) {
                    *a++ = Qnil;
                }
            }
            
            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::RObject

Unary ceil.

Returns:



3414
3415
3416
3417
3418
3419
3420
3421
3422
# File 'ext/numo/narray/types/robject.c', line 3414

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

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

#clip(min, max) ⇒ Numo::NArray

Clip array elements by [min,max]. If either of min or max is nil, one side is clipped.

Examples:

a = Numo::Int32.new(10).seq
p a.clip(1,8)
# Numo::Int32#shape=[10]
# [1, 1, 2, 3, 4, 5, 6, 7, 8, 8]

p a
# Numo::Int32#shape=[10]
# [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

p a.inplace.clip(3,6)
# Numo::Int32(view)#shape=[10]
# [3, 3, 3, 3, 4, 5, 6, 6, 6, 6]

p a
# Numo::Int32#shape=[10]
# [3, 3, 3, 3, 4, 5, 6, 6, 6, 6]

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

p a.clip([3,4,1,1,1,4,4,4,4,4], 8)
# Numo::Int32#shape=[10]
# [3, 4, 2, 3, 4, 5, 6, 7, 8, 8]

Parameters:

Returns:



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

static VALUE
robject_clip(VALUE self, VALUE min, VALUE max)
{
    ndfunc_arg_in_t ain[3] = {{Qnil,0},{cT,0},{cT,0}};
    ndfunc_arg_out_t aout[1] = {{cT,0}};
    ndfunc_t ndf_min = { iter_robject_clip_min, STRIDE_LOOP, 2, 1, ain, aout };
    ndfunc_t ndf_max = { iter_robject_clip_max, STRIDE_LOOP, 2, 1, ain, aout };
    ndfunc_t ndf_both = { iter_robject_clip, STRIDE_LOOP, 3, 1, ain, aout };

    if (RTEST(min)) {
        if (RTEST(max)) {
            return na_ndloop(&ndf_both, 3, self, min, max);
        } else {
            return na_ndloop(&ndf_min, 2, self, min);
        }
    } else {
        if (RTEST(max)) {
            return na_ndloop(&ndf_max, 2, self, max);
        }
    }
    rb_raise(rb_eArgError,"min and max are not given");
    return Qnil;
}

#coerce_cast(type) ⇒ nil

return NArray with cast to the type of self.

Returns:

  • (nil)


1465
1466
1467
1468
1469
# File 'ext/numo/narray/types/robject.c', line 1465

static VALUE
robject_coerce_cast(VALUE self, VALUE type)
{
    return Qnil;
}

#cumprod(axis: nil, nan: false) ⇒ Numo::RObject

cumprod of self.

Parameters:

  • axis (Numeric, Array, Range)

    Affected dimensions.

  • nan (TrueClass)

    If true, apply NaN-aware algorithm (avoid NaN if exists).

Returns:



5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
# File 'ext/numo/narray/types/robject.c', line 5203

static VALUE
robject_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_robject_cumprod, STRIDE_LOOP|NDF_FLAT_REDUCE|NDF_CUM,
                     2, 1, ain, aout };

  
    reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, iter_robject_cumprod_nan);
  
#line 48 "gen/tmpl/cum.c"
    return na_ndloop(&ndf, 2, self, reduce);
}

#cumsum(axis: nil, nan: false) ⇒ Numo::RObject

cumsum of self.

Parameters:

  • axis (Numeric, Array, Range)

    Affected dimensions.

  • nan (TrueClass)

    If true, apply NaN-aware algorithm (avoid NaN if exists).

Returns:



5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
# File 'ext/numo/narray/types/robject.c', line 5128

static VALUE
robject_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_robject_cumsum, STRIDE_LOOP|NDF_FLAT_REDUCE|NDF_CUM,
                     2, 1, ain, aout };

  
    reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, iter_robject_cumsum_nan);
  
#line 48 "gen/tmpl/cum.c"
    return na_ndloop(&ndf, 2, self, reduce);
}

#divmod(other) ⇒ Numo::NArray

Binary divmod.

Parameters:

Returns:



2370
2371
2372
2373
2374
2375
2376
2377
# File 'ext/numo/narray/types/robject.c', line 2370

static VALUE
robject_divmod(VALUE self, VALUE other)
{
    
    return robject_divmod_self(self, other);
    
#line 59 "gen/tmpl/binary2.c"
}

#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:



1726
1727
1728
1729
1730
1731
1732
1733
1734
# File 'ext/numo/narray/types/robject.c', line 1726

static VALUE
robject_each(VALUE self)
{
    ndfunc_arg_in_t ain[1] = {{Qnil,0}};
    ndfunc_t ndf = {iter_robject_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:



1859
1860
1861
1862
1863
1864
1865
1866
1867
# File 'ext/numo/narray/types/robject.c', line 1859

static VALUE
robject_each_with_index(VALUE self)
{
    ndfunc_arg_in_t ain[1] = {{Qnil,0}};
    ndfunc_t ndf = {iter_robject_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:



2760
2761
2762
2763
2764
2765
2766
2767
# File 'ext/numo/narray/types/robject.c', line 2760

static VALUE
robject_eq(VALUE self, VALUE other)
{
    
    return robject_eq_self(self, other);
    
#line 55 "gen/tmpl/cond_binary.c"
}

#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:



223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
# File 'ext/numo/narray/types/robject.c', line 223

static VALUE
robject_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::RObject

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:



5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
# File 'ext/numo/narray/types/robject.c', line 5558

static VALUE
robject_eye(int argc, VALUE *argv, VALUE self)
{
    ndfunc_arg_in_t ain[1] = {{OVERWRITE,2}};
    ndfunc_t ndf = {iter_robject_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::RObject

Fill elements with other.

Parameters:

  • other (Numeric)

Returns:



1546
1547
1548
1549
1550
1551
1552
1553
1554
# File 'ext/numo/narray/types/robject.c', line 1546

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

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

#floorNumo::RObject

Unary floor.

Returns:



3282
3283
3284
3285
3286
3287
3288
3289
3290
# File 'ext/numo/narray/types/robject.c', line 3282

static VALUE
robject_floor(VALUE self)
{
    ndfunc_arg_in_t ain[1] = {{cT,0}};
    ndfunc_arg_out_t aout[1] = {{cT,0}};
    ndfunc_t ndf = {iter_robject_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:



1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
# File 'ext/numo/narray/types/robject.c', line 1606

static VALUE
robject_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_robject_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.



1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
# File 'ext/numo/narray/types/robject.c', line 1657

static VALUE
robject_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_robject_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:



3581
3582
3583
3584
3585
3586
3587
3588
# File 'ext/numo/narray/types/robject.c', line 3581

static VALUE
robject_ge(VALUE self, VALUE other)
{
    
    return robject_ge_self(self, other);
    
#line 55 "gen/tmpl/cond_binary.c"
}

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

Comparison gt other.

Parameters:

Returns:



3531
3532
3533
3534
3535
3536
3537
3538
# File 'ext/numo/narray/types/robject.c', line 3531

static VALUE
robject_gt(VALUE self, VALUE other)
{
    
    return robject_gt_self(self, other);
    
#line 55 "gen/tmpl/cond_binary.c"
}

#inspectString

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

Returns:

  • (String)


1684
1685
1686
1687
1688
# File 'ext/numo/narray/types/robject.c', line 1684

VALUE
robject_inspect(VALUE ary)
{
    return na_ndloop_inspect(ary, iter_robject_inspect, Qnil);
}

#isfiniteNumo::Bit

Condition of isfinite.

Returns:



4045
4046
4047
4048
4049
4050
4051
4052
4053
# File 'ext/numo/narray/types/robject.c', line 4045

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

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

#isinfNumo::Bit

Condition of isinf.

Returns:



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

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

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

#isnanNumo::Bit

Condition of isnan.

Returns:



3853
3854
3855
3856
3857
3858
3859
3860
3861
# File 'ext/numo/narray/types/robject.c', line 3853

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

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

#isneginfNumo::Bit

Condition of isneginf.

Returns:



3997
3998
3999
4000
4001
4002
4003
4004
4005
# File 'ext/numo/narray/types/robject.c', line 3997

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

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

#isposinfNumo::Bit

Condition of isposinf.

Returns:



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

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

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

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

Comparison le other.

Parameters:

Returns:



3681
3682
3683
3684
3685
3686
3687
3688
# File 'ext/numo/narray/types/robject.c', line 3681

static VALUE
robject_le(VALUE self, VALUE other)
{
    
    return robject_le_self(self, other);
    
#line 55 "gen/tmpl/cond_binary.c"
}

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

Set logarithmic sequence of numbers to self. The sequence is obtained from base*(beg+istep) 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:



5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
# File 'ext/numo/narray/types/robject.c', line 5495

static VALUE
robject_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_robject_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:



3631
3632
3633
3634
3635
3636
3637
3638
# File 'ext/numo/narray/types/robject.c', line 3631

static VALUE
robject_lt(VALUE self, VALUE other)
{
    
    return robject_lt_self(self, other);
    
#line 55 "gen/tmpl/cond_binary.c"
}

#mapNumo::RObject

Unary map.

Returns:



1792
1793
1794
1795
1796
1797
1798
1799
1800
# File 'ext/numo/narray/types/robject.c', line 1792

static VALUE
robject_map(VALUE self)
{
    ndfunc_arg_in_t ain[1] = {{cT,0}};
    ndfunc_arg_out_t aout[1] = {{cT,0}};
    ndfunc_t ndf = {iter_robject_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:



1956
1957
1958
1959
1960
1961
1962
1963
1964
# File 'ext/numo/narray/types/robject.c', line 1956

static VALUE
robject_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_robject_map_with_index, FULL_LOOP, 1,1, ain,aout};

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

#max(axis: nil, keepdims: false, nan: false) ⇒ Numo::RObject

max of self.

Parameters:

  • nan (TrueClass)

    If true, apply NaN-aware algorithm (avoid NaN for sum/mean etc, or, return NaN for min/max etc).

  • axis (Numeric, Array, Range)

    (keyword) Affected dimensions.

  • keepdims (TrueClass)

    (keyword) If true, the reduced axes are left in the result array as dimensions with size one.

Returns:



4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
# File 'ext/numo/narray/types/robject.c', line 4508

static VALUE
robject_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_robject_max, STRIDE_LOOP_NIP|NDF_FLAT_REDUCE, 2, 1, ain, aout };

  
    reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, iter_robject_max_nan);
  
#line 42 "gen/tmpl/accum.c"
    v =  na_ndloop(&ndf, 2, self, reduce);
  
    return robject_extract(v);
  
#line 48 "gen/tmpl/accum.c"
}

#max_index(axis: nil, nan: false) ⇒ Integer, Numo::Int

max_index. Return an index of result.

Examples:

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

Parameters:

  • nan (TrueClass)

    If true, apply NaN-aware algorithm (return NaN posision if exist).

  • axis (Numeric, Array, Range)

    Affected dimensions.

Returns:

  • (Integer, Numo::Int)

    returns result index of max_index.



4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
# File 'ext/numo/narray/types/robject.c', line 4679

static VALUE
robject_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 = nary_new(numo_cInt64, na->ndim, na->shape);
        ndf.func = iter_robject_max_index_index64;
      
        reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, iter_robject_max_index_index64_nan);
      
#line 58 "gen/tmpl/accum_index.c"
    } else {
        aout[0].type = numo_cInt32;
        idx = nary_new(numo_cInt32, na->ndim, na->shape);
        ndf.func = iter_robject_max_index_index32;
      
        reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, iter_robject_max_index_index32_nan);
      
#line 67 "gen/tmpl/accum_index.c"
    }
    rb_funcall(idx, rb_intern("seq"), 0);

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

#mean(axis: nil, keepdims: false, nan: false) ⇒ Numo::RObject

mean of self.

Parameters:

  • nan (TrueClass)

    If true, apply NaN-aware algorithm (avoid NaN for sum/mean etc, or, return NaN for min/max etc).

  • axis (Numeric, Array, Range)

    (keyword) Affected dimensions.

  • keepdims (TrueClass)

    (keyword) If true, the reduced axes are left in the result array as dimensions with size one.

Returns:



4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
# File 'ext/numo/narray/types/robject.c', line 4213

static VALUE
robject_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_robject_mean, STRIDE_LOOP_NIP|NDF_FLAT_REDUCE, 2, 1, ain, aout };

  
    reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, iter_robject_mean_nan);
  
#line 42 "gen/tmpl/accum.c"
    v =  na_ndloop(&ndf, 2, self, reduce);
  
    return robject_extract(v);
  
#line 48 "gen/tmpl/accum.c"
}

#min(axis: nil, keepdims: false, nan: false) ⇒ Numo::RObject

min of self.

Parameters:

  • nan (TrueClass)

    If true, apply NaN-aware algorithm (avoid NaN for sum/mean etc, or, return NaN for min/max etc).

  • axis (Numeric, Array, Range)

    (keyword) Affected dimensions.

  • keepdims (TrueClass)

    (keyword) If true, the reduced axes are left in the result array as dimensions with size one.

Returns:



4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
# File 'ext/numo/narray/types/robject.c', line 4449

static VALUE
robject_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_robject_min, STRIDE_LOOP_NIP|NDF_FLAT_REDUCE, 2, 1, ain, aout };

  
    reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, iter_robject_min_nan);
  
#line 42 "gen/tmpl/accum.c"
    v =  na_ndloop(&ndf, 2, self, reduce);
  
    return robject_extract(v);
  
#line 48 "gen/tmpl/accum.c"
}

#min_index(axis: nil, nan: false) ⇒ Integer, Numo::Int

min_index. Return an index of result.

Examples:

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

Parameters:

  • nan (TrueClass)

    If true, apply NaN-aware algorithm (return NaN posision if exist).

  • axis (Numeric, Array, Range)

    Affected dimensions.

Returns:

  • (Integer, Numo::Int)

    returns result index of min_index.



4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
# File 'ext/numo/narray/types/robject.c', line 4807

static VALUE
robject_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 = nary_new(numo_cInt64, na->ndim, na->shape);
        ndf.func = iter_robject_min_index_index64;
      
        reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, iter_robject_min_index_index64_nan);
      
#line 58 "gen/tmpl/accum_index.c"
    } else {
        aout[0].type = numo_cInt32;
        idx = nary_new(numo_cInt32, na->ndim, na->shape);
        ndf.func = iter_robject_min_index_index32;
      
        reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, iter_robject_min_index_index32_nan);
      
#line 67 "gen/tmpl/accum_index.c"
    }
    rb_funcall(idx, rb_intern("seq"), 0);

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

#minmax(axis: nil, keepdims: false, nan: false) ⇒ Numo::RObject

minmax of self.

Parameters:

  • nan (TrueClass)

    If true, apply NaN-aware algorithm (return NaN if exist).

  • axis (Numeric, Array, Range)

    (keyword) Affected dimensions.

  • keepdims (TrueClass)

    (keyword) If true, the reduced axes are left in the result array as dimensions with size one.

Returns:



4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
# File 'ext/numo/narray/types/robject.c', line 4888

static VALUE
robject_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_robject_minmax, STRIDE_LOOP_NIP|NDF_FLAT_REDUCE|NDF_EXTRACT, 2,2, ain,aout};

  
    reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, iter_robject_minmax_nan);
  
#line 45 "gen/tmpl/minmax.c"
    return na_ndloop(&ndf, 2, self, reduce);
}

#mulsum(other, axis: nil, keepdims: false, nan: false) ⇒ Numo::NArray

Binary mulsum.

Parameters:

  • other (Numo::NArray, Numeric)
  • axis (Numeric, Array, Range)

    (keyword) Affected dimensions.

  • keepdims (TrueClass)

    (keyword) If true, the reduced axes are left in the result array as dimensions with size one.

  • nan (TrueClass)

    (keyword) If true, apply NaN-aware algorithm (avoid NaN if exists).

Returns:



5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
# File 'ext/numo/narray/types/robject.c', line 5330

static VALUE
robject_mulsum(int argc, VALUE *argv, VALUE self)
{
    //
#line 86 "gen/tmpl/accum_binary.c"
    if (argc < 1) {
        rb_raise(rb_eArgError,"wrong number of arguments (%d for >=1)",argc);
    }
    //
    return robject_mulsum_self(argc, argv, self);
    //
#line 100 "gen/tmpl/accum_binary.c"
}

#ne(other) ⇒ Numo::Bit

Comparison ne other.

Parameters:

Returns:



2810
2811
2812
2813
2814
2815
2816
2817
# File 'ext/numo/narray/types/robject.c', line 2810

static VALUE
robject_ne(VALUE self, VALUE other)
{
    
    return robject_ne_self(self, other);
    
#line 55 "gen/tmpl/cond_binary.c"
}

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

Comparison nearly_eq other.

Parameters:

Returns:

  • (Numo::Bit)

    result of self nearly_eq other.



2860
2861
2862
2863
2864
2865
2866
2867
# File 'ext/numo/narray/types/robject.c', line 2860

static VALUE
robject_nearly_eq(VALUE self, VALUE other)
{
    
    return robject_nearly_eq_self(self, other);
    
#line 55 "gen/tmpl/cond_binary.c"
}

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

Polynomial.: a0 + a1x + a2x2 + a3x**3 + … + anxn

Parameters:

Returns:



5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
# File 'ext/numo/narray/types/robject.c', line 5733

static VALUE
robject_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_robject_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 robject_extract(v);
}

#prod(axis: nil, keepdims: false, nan: false) ⇒ Numo::RObject

prod of self.

Parameters:

  • nan (TrueClass)

    If true, apply NaN-aware algorithm (avoid NaN for sum/mean etc, or, return NaN for min/max etc).

  • axis (Numeric, Array, Range)

    (keyword) Affected dimensions.

  • keepdims (TrueClass)

    (keyword) If true, the reduced axes are left in the result array as dimensions with size one.

Returns:



4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
# File 'ext/numo/narray/types/robject.c', line 4154

static VALUE
robject_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_robject_prod, STRIDE_LOOP_NIP|NDF_FLAT_REDUCE, 2, 1, ain, aout };

  
    reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, iter_robject_prod_nan);
  
#line 42 "gen/tmpl/accum.c"
    v =  na_ndloop(&ndf, 2, self, reduce);
  
    return robject_extract(v);
  
#line 48 "gen/tmpl/accum.c"
}

#ptp(axis: nil, keepdims: false, nan: false) ⇒ Numo::RObject

ptp of self.

Parameters:

  • nan (TrueClass)

    If true, apply NaN-aware algorithm (avoid NaN for sum/mean etc, or, return NaN for min/max etc).

  • axis (Numeric, Array, Range)

    (keyword) Affected dimensions.

  • keepdims (TrueClass)

    (keyword) If true, the reduced axes are left in the result array as dimensions with size one.

Returns:



4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
# File 'ext/numo/narray/types/robject.c', line 4567

static VALUE
robject_ptp(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_robject_ptp, STRIDE_LOOP_NIP|NDF_FLAT_REDUCE, 2, 1, ain, aout };

  
    reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, iter_robject_ptp_nan);
  
#line 42 "gen/tmpl/accum.c"
    v =  na_ndloop(&ndf, 2, self, reduce);
  
    return robject_extract(v);
  
#line 48 "gen/tmpl/accum.c"
}

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

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:



5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
# File 'ext/numo/narray/types/robject.c', line 5672

static VALUE
robject_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_robject_rand, FULL_LOOP, 1,0, ain,0};

    
#line 140 "gen/tmpl/rand.c"
    rb_scan_args(argc, args, "02", &v1, &v2);
    if (v2==Qnil) {
        g.low = m_zero;
        if (v1==Qnil) {
            
#line 147 "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 "gen/tmpl/rand.c"
    na_ndloop3(&ndf, &g, 1, self);
    return self;
}

#reciprocalNumo::RObject

Unary reciprocal.

Returns:



2574
2575
2576
2577
2578
2579
2580
2581
2582
# File 'ext/numo/narray/types/robject.c', line 2574

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

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

#rms(axis: nil, keepdims: false, nan: false) ⇒ Numo::RObject

rms of self.

Parameters:

  • nan (TrueClass)

    If true, apply NaN-aware algorithm (avoid NaN for sum/mean etc, or, return NaN for min/max etc).

  • axis (Numeric, Array, Range)

    (keyword) Affected dimensions.

  • keepdims (TrueClass)

    (keyword) If true, the reduced axes are left in the result array as dimensions with size one.

Returns:



4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
# File 'ext/numo/narray/types/robject.c', line 4390

static VALUE
robject_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_robject_rms, STRIDE_LOOP_NIP|NDF_FLAT_REDUCE, 2, 1, ain, aout };

  
    reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, iter_robject_rms_nan);
  
#line 42 "gen/tmpl/accum.c"
    v =  na_ndloop(&ndf, 2, self, reduce);
  
#line 46 "gen/tmpl/accum.c"
    return rb_funcall(v,rb_intern("extract"),0);
  
}

#roundNumo::RObject

Unary round.

Returns:



3348
3349
3350
3351
3352
3353
3354
3355
3356
# File 'ext/numo/narray/types/robject.c', line 3348

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

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

#seq([beg,[step]]) ⇒ Numo::RObject 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:



5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
# File 'ext/numo/narray/types/robject.c', line 5409

static VALUE
robject_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_robject_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 "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 "gen/tmpl/seq.c"
    na_ndloop3(&ndf, g, 1, self);
    return self;
}

#signNumo::RObject

Unary sign.

Returns:



2640
2641
2642
2643
2644
2645
2646
2647
2648
# File 'ext/numo/narray/types/robject.c', line 2640

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

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

#squareNumo::RObject

Unary square.

Returns:



2706
2707
2708
2709
2710
2711
2712
2713
2714
# File 'ext/numo/narray/types/robject.c', line 2706

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

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

#stddev(axis: nil, keepdims: false, nan: false) ⇒ Numo::RObject

stddev of self.

Parameters:

  • nan (TrueClass)

    If true, apply NaN-aware algorithm (avoid NaN for sum/mean etc, or, return NaN for min/max etc).

  • axis (Numeric, Array, Range)

    (keyword) Affected dimensions.

  • keepdims (TrueClass)

    (keyword) If true, the reduced axes are left in the result array as dimensions with size one.

Returns:



4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
# File 'ext/numo/narray/types/robject.c', line 4272

static VALUE
robject_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_robject_stddev, STRIDE_LOOP_NIP|NDF_FLAT_REDUCE, 2, 1, ain, aout };

  
    reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, iter_robject_stddev_nan);
  
#line 42 "gen/tmpl/accum.c"
    v =  na_ndloop(&ndf, 2, self, reduce);
  
#line 46 "gen/tmpl/accum.c"
    return rb_funcall(v,rb_intern("extract"),0);
  
}

#store(other) ⇒ Numo::RObject

Store elements to Numo::RObject from other.

Parameters:

  • other (Object)

Returns:



1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
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
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
# File 'ext/numo/narray/types/robject.c', line 1055

static VALUE
robject_store(VALUE self, VALUE obj)
{
    VALUE r, klass;

    klass = CLASS_OF(obj);

    
    if (klass==numo_cRObject) {
        robject_store_robject(self,obj);
        return self;
    }
    
#line 19 "gen/tmpl/store.c"
    if (IS_INTEGER_CLASS(klass) || klass==rb_cFloat || klass==rb_cComplex) {
        robject_store_numeric(self,obj);
        return self;
    }
    
#line 19 "gen/tmpl/store.c"
    if (klass==numo_cBit) {
        robject_store_bit(self,obj);
        return self;
    }
    
#line 19 "gen/tmpl/store.c"
    if (klass==numo_cDFloat) {
        robject_store_dfloat(self,obj);
        return self;
    }
    
#line 19 "gen/tmpl/store.c"
    if (klass==numo_cSFloat) {
        robject_store_sfloat(self,obj);
        return self;
    }
    
#line 19 "gen/tmpl/store.c"
    if (klass==numo_cInt64) {
        robject_store_int64(self,obj);
        return self;
    }
    
#line 19 "gen/tmpl/store.c"
    if (klass==numo_cInt32) {
        robject_store_int32(self,obj);
        return self;
    }
    
#line 19 "gen/tmpl/store.c"
    if (klass==numo_cInt16) {
        robject_store_int16(self,obj);
        return self;
    }
    
#line 19 "gen/tmpl/store.c"
    if (klass==numo_cInt8) {
        robject_store_int8(self,obj);
        return self;
    }
    
#line 19 "gen/tmpl/store.c"
    if (klass==numo_cUInt64) {
        robject_store_uint64(self,obj);
        return self;
    }
    
#line 19 "gen/tmpl/store.c"
    if (klass==numo_cUInt32) {
        robject_store_uint32(self,obj);
        return self;
    }
    
#line 19 "gen/tmpl/store.c"
    if (klass==numo_cUInt16) {
        robject_store_uint16(self,obj);
        return self;
    }
    
#line 19 "gen/tmpl/store.c"
    if (klass==numo_cUInt8) {
        robject_store_uint8(self,obj);
        return self;
    }
    
#line 19 "gen/tmpl/store.c"
    if (klass==rb_cArray) {
        robject_store_array(self,obj);
        return self;
    }
    

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

    
    robject_store_numeric(self,obj);
    
#line 40 "gen/tmpl/store.c"
    return self;
}

#sum(axis: nil, keepdims: false, nan: false) ⇒ Numo::RObject

sum of self.

Parameters:

  • nan (TrueClass)

    If true, apply NaN-aware algorithm (avoid NaN for sum/mean etc, or, return NaN for min/max etc).

  • axis (Numeric, Array, Range)

    (keyword) Affected dimensions.

  • keepdims (TrueClass)

    (keyword) If true, the reduced axes are left in the result array as dimensions with size one.

Returns:



4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
# File 'ext/numo/narray/types/robject.c', line 4095

static VALUE
robject_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_robject_sum, STRIDE_LOOP_NIP|NDF_FLAT_REDUCE, 2, 1, ain, aout };

  
    reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, iter_robject_sum_nan);
  
#line 42 "gen/tmpl/accum.c"
    v =  na_ndloop(&ndf, 2, self, reduce);
  
    return robject_extract(v);
  
#line 48 "gen/tmpl/accum.c"
}

#to_aArray

Convert self to Array.

Returns:

  • (Array)


1506
1507
1508
1509
1510
1511
1512
1513
# File 'ext/numo/narray/types/robject.c', line 1506

static VALUE
robject_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_robject_to_a, FULL_LOOP_NIP, 3, 1, ain, aout };
    return na_ndloop_cast_narray_to_rarray(&ndf, self, Qnil);
}

#truncNumo::RObject

Unary trunc.

Returns:



3480
3481
3482
3483
3484
3485
3486
3487
3488
# File 'ext/numo/narray/types/robject.c', line 3480

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

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

#var(axis: nil, keepdims: false, nan: false) ⇒ Numo::RObject

var of self.

Parameters:

  • nan (TrueClass)

    If true, apply NaN-aware algorithm (avoid NaN for sum/mean etc, or, return NaN for min/max etc).

  • axis (Numeric, Array, Range)

    (keyword) Affected dimensions.

  • keepdims (TrueClass)

    (keyword) If true, the reduced axes are left in the result array as dimensions with size one.

Returns:



4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
# File 'ext/numo/narray/types/robject.c', line 4331

static VALUE
robject_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_robject_var, STRIDE_LOOP_NIP|NDF_FLAT_REDUCE, 2, 1, ain, aout };

  
    reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, iter_robject_var_nan);
  
#line 42 "gen/tmpl/accum.c"
    v =  na_ndloop(&ndf, 2, self, reduce);
  
#line 46 "gen/tmpl/accum.c"
    return rb_funcall(v,rb_intern("extract"),0);
  
}

#|(other) ⇒ Numo::NArray

Binary bit_or.

Parameters:

Returns:



2977
2978
2979
2980
2981
2982
2983
2984
# File 'ext/numo/narray/types/robject.c', line 2977

static VALUE
robject_bit_or(VALUE self, VALUE other)
{
    
    return robject_bit_or_self(self, other);
    
#line 97 "gen/tmpl/binary.c"
}

#~Numo::RObject

Unary bit_not.

Returns:



3100
3101
3102
3103
3104
3105
3106
3107
3108
# File 'ext/numo/narray/types/robject.c', line 3100

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

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