Class: Numo::RObject

Inherits:
NArray show all
Defined in:
ext/numo/narray/src/t_robject.c

Constant Summary collapse

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, #each_over_axis, #empty?, #expand_dims, eye, #flatten, #fliplr, #flipud, #fortran_contiguous?, #free, 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, #percentile, profile, profile=, #rad2deg, #repeat, #reshape, #reshape!, #reverse, #rot90, #row_major?, #shape, #size, #split, #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:



1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
# File 'ext/numo/narray/src/t_robject.c', line 1149

static VALUE robject_s_cast(VALUE type, VALUE obj) {
  VALUE v;
  narray_t* na;
  dtype x;

  if (rb_obj_class(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;
  }
  if (rb_respond_to(obj, id_to_a)) {
    obj = rb_funcall(obj, id_to_a, 0);
    if (TYPE(obj) != T_ARRAY) {
      rb_raise(rb_eTypeError, "`to_a' did not return Array");
    }
    return robject_cast_array(obj);
  }

  return robject_new_dim0(obj);
}

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

Cast object to Numo::RObject.

Parameters:

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

Returns:



1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
# File 'ext/numo/narray/src/t_robject.c', line 1149

static VALUE robject_s_cast(VALUE type, VALUE obj) {
  VALUE v;
  narray_t* na;
  dtype x;

  if (rb_obj_class(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;
  }
  if (rb_respond_to(obj, id_to_a)) {
    obj = rb_funcall(obj, id_to_a, 0);
    if (TYPE(obj) != T_ARRAY) {
      rb_raise(rb_eTypeError, "`to_a' did not return Array");
    }
    return robject_cast_array(obj);
  }

  return robject_new_dim0(obj);
}

.maximum(*args) ⇒ Object



4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
# File 'ext/numo/narray/src/t_robject.c', line 4693

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;
  }

  return na_ndloop(&ndf, 2, a1, a2);
}

.minimum(*args) ⇒ Object



4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
# File 'ext/numo/narray/src/t_robject.c', line 4762

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;
  }

  return na_ndloop(&ndf, 2, a1, a2);
}

Instance Method Details

#%(other) ⇒ Numo::NArray

Binary mod.

Parameters:

Returns:



2134
2135
2136
# File 'ext/numo/narray/src/t_robject.c', line 2134

static VALUE robject_mod(VALUE self, VALUE other) {
  return robject_mod_self(self, other);
}

#&(other) ⇒ Numo::NArray

Binary bit_and.

Parameters:

Returns:



2661
2662
2663
# File 'ext/numo/narray/src/t_robject.c', line 2661

static VALUE robject_bit_and(VALUE self, VALUE other) {
  return robject_bit_and_self(self, other);
}

#*(other) ⇒ Numo::NArray

Binary mul.

Parameters:

Returns:



1974
1975
1976
# File 'ext/numo/narray/src/t_robject.c', line 1974

static VALUE robject_mul(VALUE self, VALUE other) {
  return robject_mul_self(self, other);
}

#**(other) ⇒ Numo::NArray Also known as: pow

Binary power.

Parameters:

Returns:



2235
2236
2237
# File 'ext/numo/narray/src/t_robject.c', line 2235

static VALUE robject_pow(VALUE self, VALUE other) {
  return robject_pow_self(self, other);
}

#+(other) ⇒ Numo::NArray

Binary add.

Parameters:

Returns:



1820
1821
1822
# File 'ext/numo/narray/src/t_robject.c', line 1820

static VALUE robject_add(VALUE self, VALUE other) {
  return robject_add_self(self, other);
}

#-(other) ⇒ Numo::NArray

Binary sub.

Parameters:

Returns:



1897
1898
1899
# File 'ext/numo/narray/src/t_robject.c', line 1897

static VALUE robject_sub(VALUE self, VALUE other) {
  return robject_sub_self(self, other);
}

#-@Numo::RObject

Unary minus.

Returns:



2289
2290
2291
2292
2293
2294
2295
# File 'ext/numo/narray/src/t_robject.c', line 2289

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:



2054
2055
2056
# File 'ext/numo/narray/src/t_robject.c', line 2054

static VALUE robject_div(VALUE self, VALUE other) {
  return robject_div_self(self, other);
}

#<<(other) ⇒ Numo::NArray

Binary left_shift.

Parameters:

Returns:



2950
2951
2952
# File 'ext/numo/narray/src/t_robject.c', line 2950

static VALUE robject_left_shift(VALUE self, VALUE other) {
  return robject_left_shift_self(self, other);
}

#>>(other) ⇒ Numo::NArray

Binary right_shift.

Parameters:

Returns:



3027
3028
3029
# File 'ext/numo/narray/src/t_robject.c', line 3027

static VALUE robject_right_shift(VALUE self, VALUE other) {
  return robject_right_shift_self(self, other);
}

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

Multi-dimensional element reference. indices.

Parameters:

Returns:

See Also:



1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
# File 'ext/numo/narray/src/t_robject.c', line 1192

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, ...

Multi-dimensional element assignment. indices.

Parameters:

Returns:

  • (Numeric, Numo::NArray, Array)

    returns ‘val` (last argument).

See Also:



1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
# File 'ext/numo/narray/src/t_robject.c', line 1216

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:



2815
2816
2817
# File 'ext/numo/narray/src/t_robject.c', line 2815

static VALUE robject_bit_xor(VALUE self, VALUE other) {
  return robject_bit_xor_self(self, other);
}

#absNumo::RObject

abs of self.

Returns:



1739
1740
1741
1742
1743
1744
1745
# File 'ext/numo/narray/src/t_robject.c', line 1739

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



155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# File 'ext/numo/narray/src/t_robject.c', line 155

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;
      NA_DATA_OWNED(na) = TRUE;
    }
    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;
}

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

Index of the maximum value.

Examples:

a = Numo::NArray[3,4,1,2]
a.argmax  #=> 1

b = Numo::NArray[[3,4,1],[2,0,5]]
b.argmax                       #=> 5
b.argmax(axis:1)               #=> [1, 2]
b.argmax(axis:0)               #=> [0, 0, 1]
b.at(b.argmax(axis:0), 0..-1)  #=> [3, 4, 5]

Parameters:

  • nan (TrueClass)

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

  • axis (Numeric, Array, Range)

    Finds maximum values along the axis and returns **indices along the axis**.

Returns:

  • (Integer, Numo::Int)

    returns the result indices.

See Also:



4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
# File 'ext/numo/narray/src/t_robject.c', line 4459

static VALUE robject_argmax(int argc, VALUE* argv, VALUE self) {
  narray_t* na;
  VALUE reduce;
  ndfunc_arg_in_t ain[2] = {{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, 2, 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;
    ndf.func = iter_robject_argmax_arg64;

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

  } else {
    aout[0].type = numo_cInt32;
    ndf.func = iter_robject_argmax_arg32;

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

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

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

Index of the minimum value.

Examples:

a = Numo::NArray[3,4,1,2]
a.argmin  #=> 2

b = Numo::NArray[[3,4,1],[2,0,5]]
b.argmin                       #=> 4
b.argmin(axis:1)               #=> [2, 1]
b.argmin(axis:0)               #=> [1, 1, 0]
b.at(b.argmin(axis:0), 0..-1)  #=> [2, 0, 1]

Parameters:

  • nan (TrueClass)

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

  • axis (Numeric, Array, Range)

    Finds minimum values along the axis and returns **indices along the axis**.

Returns:

  • (Integer, Numo::Int)

    returns the result indices.

See Also:



4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
# File 'ext/numo/narray/src/t_robject.c', line 4569

static VALUE robject_argmin(int argc, VALUE* argv, VALUE self) {
  narray_t* na;
  VALUE reduce;
  ndfunc_arg_in_t ain[2] = {{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, 2, 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;
    ndf.func = iter_robject_argmin_arg64;

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

  } else {
    aout[0].type = numo_cInt32;
    ndf.func = iter_robject_argmin_arg32;

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

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

#ceilNumo::RObject

Unary ceil.

Returns:



3197
3198
3199
3200
3201
3202
3203
# File 'ext/numo/narray/src/t_robject.c', line 3197

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
# => Numo::Int32#shape=[10]
# [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

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

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

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

b.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:



3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
# File 'ext/numo/narray/src/t_robject.c', line 3514

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)


1245
1246
1247
# File 'ext/numo/narray/src/t_robject.c', line 1245

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)

    Performs cumprod along the axis.

  • nan (TrueClass)

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

Returns:



4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
# File 'ext/numo/narray/src/t_robject.c', line 4893

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);

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

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

cumsum of self.

Parameters:

  • axis (Numeric, Array, Range)

    Performs cumsum along the axis.

  • nan (TrueClass)

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

Returns:



4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
# File 'ext/numo/narray/src/t_robject.c', line 4832

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);

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

#divmod(other) ⇒ Numo::NArray

Binary divmod.

Parameters:

Returns:



2175
2176
2177
# File 'ext/numo/narray/src/t_robject.c', line 2175

static VALUE robject_divmod(VALUE self, VALUE other) {
  return robject_divmod_self(self, other);
}

#eachNumo::NArray

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

Yield Parameters:

  • x (Numeric)

    an element of NArray.

Returns:

See Also:



1472
1473
1474
1475
1476
1477
1478
# File 'ext/numo/narray/src/t_robject.c', line 1472

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,…| … }`,

Yield Parameters:

  • x (Numeric)

    an element

  • i,j,... (Integer)

    multitimensional indices

Returns:

See Also:



1594
1595
1596
1597
1598
1599
1600
# File 'ext/numo/narray/src/t_robject.c', line 1594

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:



2506
2507
2508
# File 'ext/numo/narray/src/t_robject.c', line 2506

static VALUE robject_eq(VALUE self, VALUE other) {
  return robject_eq_self(self, 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:



198
199
200
201
202
203
204
205
206
207
208
209
210
211
# File 'ext/numo/narray/src/t_robject.c', line 198

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:



5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
# File 'ext/numo/narray/src/t_robject.c', line 5214

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:



1314
1315
1316
1317
1318
1319
1320
# File 'ext/numo/narray/src/t_robject.c', line 1314

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:



3081
3082
3083
3084
3085
3086
3087
# File 'ext/numo/narray/src/t_robject.c', line 3081

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:



1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
# File 'ext/numo/narray/src/t_robject.c', line 1368

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 formatted strings.



1415
1416
1417
1418
1419
1420
1421
1422
1423
# File 'ext/numo/narray/src/t_robject.c', line 1415

static VALUE robject_format_to_a(int argc, VALUE* argv, VALUE self) {
  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:



3337
3338
3339
# File 'ext/numo/narray/src/t_robject.c', line 3337

static VALUE robject_ge(VALUE self, VALUE other) {
  return robject_ge_self(self, other);
}

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

Comparison gt other.

Parameters:

Returns:



3298
3299
3300
# File 'ext/numo/narray/src/t_robject.c', line 3298

static VALUE robject_gt(VALUE self, VALUE other) {
  return robject_gt_self(self, other);
}

#inspectString

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

Returns:

  • (String)


1434
1435
1436
# File 'ext/numo/narray/src/t_robject.c', line 1434

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

#isfiniteNumo::Bit

Condition of isfinite.

Returns:



3738
3739
3740
3741
3742
3743
3744
# File 'ext/numo/narray/src/t_robject.c', line 3738

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:



3612
3613
3614
3615
3616
3617
3618
# File 'ext/numo/narray/src/t_robject.c', line 3612

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:



3570
3571
3572
3573
3574
3575
3576
# File 'ext/numo/narray/src/t_robject.c', line 3570

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:



3696
3697
3698
3699
3700
3701
3702
# File 'ext/numo/narray/src/t_robject.c', line 3696

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:



3654
3655
3656
3657
3658
3659
3660
# File 'ext/numo/narray/src/t_robject.c', line 3654

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:



3415
3416
3417
# File 'ext/numo/narray/src/t_robject.c', line 3415

static VALUE robject_le(VALUE self, VALUE other) {
  return robject_le_self(self, other);
}

#logseq(, self) ⇒ Object



5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
# File 'ext/numo/narray/src/t_robject.c', line 5157

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:



3376
3377
3378
# File 'ext/numo/narray/src/t_robject.c', line 3376

static VALUE robject_lt(VALUE self, VALUE other) {
  return robject_lt_self(self, other);
}

#mapNumo::RObject

Unary map.

Returns:



1530
1531
1532
1533
1534
1535
1536
# File 'ext/numo/narray/src/t_robject.c', line 1530

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,…| … }`,

Yield Parameters:

  • x (Numeric)

    an element

  • i,j,... (Integer)

    multitimensional indices

Returns:

See Also:



1685
1686
1687
1688
1689
1690
1691
# File 'ext/numo/narray/src/t_robject.c', line 1685

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)

    Performs max along the axis.

  • keepdims (TrueClass)

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

Returns:



4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
# File 'ext/numo/narray/src/t_robject.c', line 4085

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);

  v = na_ndloop(&ndf, 2, self, reduce);

  return robject_extract(v);
}

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

Index of the maximum value.

Examples:

a = Numo::NArray[3,4,1,2]
a.max_index  #=> 1

b = Numo::NArray[[3,4,1],[2,0,5]]
b.max_index             #=> 5
b.max_index(axis:1)     #=> [1, 5]
b.max_index(axis:0)     #=> [0, 1, 5]
b[b.max_index(axis:0)]  #=> [3, 4, 5]

Parameters:

  • nan (TrueClass)

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

  • axis (Numeric, Array, Range)

    Finds maximum values along the axis and returns **flat 1-d indices**.

Returns:

  • (Integer, Numo::Int)

    returns result indices.

See Also:



4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
# File 'ext/numo/narray/src/t_robject.c', line 4229

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);

  } 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);
  }
  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)

    Performs mean along the axis.

  • keepdims (TrueClass)

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

Returns:



3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
# File 'ext/numo/narray/src/t_robject.c', line 3865

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);

  v = na_ndloop(&ndf, 2, self, reduce);

  return robject_extract(v);
}

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

    Performs min along the axis.

  • keepdims (TrueClass)

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

Returns:



4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
# File 'ext/numo/narray/src/t_robject.c', line 4041

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);

  v = na_ndloop(&ndf, 2, self, reduce);

  return robject_extract(v);
}

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

Index of the minimum value.

Examples:

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

b = Numo::NArray[[3,4,1],[2,0,5]]
b.min_index             #=> 4
b.min_index(axis:1)     #=> [2, 4]
b.min_index(axis:0)     #=> [3, 4, 2]
b[b.min_index(axis:0)]  #=> [2, 0, 1]

Parameters:

  • nan (TrueClass)

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

  • axis (Numeric, Array, Range)

    Finds minimum values along the axis and returns **flat 1-d indices**.

Returns:

  • (Integer, Numo::Int)

    returns result indices.

See Also:



4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
# File 'ext/numo/narray/src/t_robject.c', line 4346

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);

  } 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);
  }
  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)

    Finds min-max along the axis.

  • keepdims (TrueClass)

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

Returns:



4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
# File 'ext/numo/narray/src/t_robject.c', line 4633

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);

  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)

    Performs mulsum along the axis.

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



5005
5006
5007
5008
5009
5010
5011
5012
5013
# File 'ext/numo/narray/src/t_robject.c', line 5005

static VALUE robject_mulsum(int argc, VALUE* argv, VALUE self) {
  //
  if (argc < 1) {
    rb_raise(rb_eArgError, "wrong number of arguments (%d for >=1)", argc);
  }
  //
  return robject_mulsum_self(argc, argv, self);
  //
}

#ne(other) ⇒ Numo::Bit

Comparison ne other.

Parameters:

Returns:



2545
2546
2547
# File 'ext/numo/narray/src/t_robject.c', line 2545

static VALUE robject_ne(VALUE self, VALUE other) {
  return robject_ne_self(self, 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.



2584
2585
2586
# File 'ext/numo/narray/src/t_robject.c', line 2584

static VALUE robject_nearly_eq(VALUE self, VALUE other) {
  return robject_nearly_eq_self(self, other);
}

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

Calculate polynomial.

`x.poly(a0,a1,a2,...,an) = a0 + a1*x + a2*x**2 + ... + an*x**n`

Parameters:

Returns:



5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
# File 'ext/numo/narray/src/t_robject.c', line 5372

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 = (int)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)

    Performs prod along the axis.

  • keepdims (TrueClass)

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

Returns:



3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
# File 'ext/numo/narray/src/t_robject.c', line 3821

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);

  v = na_ndloop(&ndf, 2, self, reduce);

  return robject_extract(v);
}

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

    Performs ptp along the axis.

  • keepdims (TrueClass)

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

Returns:



4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
# File 'ext/numo/narray/src/t_robject.c', line 4129

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);

  v = na_ndloop(&ndf, 2, self, reduce);

  return robject_extract(v);
}

#rand(, self) ⇒ Object



5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
# File 'ext/numo/narray/src/t_robject.c', line 5321

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};

  rb_scan_args(argc, args, "02", &v1, &v2);
  if (v2 == Qnil) {
    g.low = m_zero;
    if (v1 == Qnil) {

      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);
  }

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

#reciprocalNumo::RObject

Unary reciprocal.

Returns:



2347
2348
2349
2350
2351
2352
2353
# File 'ext/numo/narray/src/t_robject.c', line 2347

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)

    Performs rms along the axis.

  • keepdims (TrueClass)

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

Returns:



3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
# File 'ext/numo/narray/src/t_robject.c', line 3997

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);

  v = na_ndloop(&ndf, 2, self, reduce);

  return rb_funcall(v, rb_intern("extract"), 0);
}

#roundNumo::RObject

Unary round.

Returns:



3139
3140
3141
3142
3143
3144
3145
# File 'ext/numo/narray/src/t_robject.c', line 3139

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(, self) ⇒ Object Also known as: indgen



5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
# File 'ext/numo/narray/src/t_robject.c', line 5074

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);
  if (vbeg != Qnil) {
    g->beg = m_num_to_data(vbeg);
  }
  if (vstep != Qnil) {
    g->step = m_num_to_data(vstep);
  }

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

#signNumo::RObject

Unary sign.

Returns:



2405
2406
2407
2408
2409
2410
2411
# File 'ext/numo/narray/src/t_robject.c', line 2405

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:



2463
2464
2465
2466
2467
2468
2469
# File 'ext/numo/narray/src/t_robject.c', line 2463

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)

    Performs stddev along the axis.

  • keepdims (TrueClass)

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

Returns:



3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
# File 'ext/numo/narray/src/t_robject.c', line 3909

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);

  v = na_ndloop(&ndf, 2, self, reduce);

  return rb_funcall(v, rb_intern("extract"), 0);
}

#store(other) ⇒ Numo::RObject

Store elements to Numo::RObject from other.

Parameters:

  • other (Object)

Returns:



941
942
943
944
945
946
947
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
# File 'ext/numo/narray/src/t_robject.c', line 941

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

  klass = rb_obj_class(obj);

  if (klass == numo_cRObject) {
    robject_store_robject(self, obj);
    return self;
  }

  if (IS_INTEGER_CLASS(klass) || klass == rb_cFloat || klass == rb_cComplex) {
    robject_store_numeric(self, obj);
    return self;
  }

  if (klass == numo_cBit) {
    robject_store_bit(self, obj);
    return self;
  }

  if (klass == numo_cDFloat) {
    robject_store_dfloat(self, obj);
    return self;
  }

  if (klass == numo_cSFloat) {
    robject_store_sfloat(self, obj);
    return self;
  }

  if (klass == numo_cInt64) {
    robject_store_int64(self, obj);
    return self;
  }

  if (klass == numo_cInt32) {
    robject_store_int32(self, obj);
    return self;
  }

  if (klass == numo_cInt16) {
    robject_store_int16(self, obj);
    return self;
  }

  if (klass == numo_cInt8) {
    robject_store_int8(self, obj);
    return self;
  }

  if (klass == numo_cUInt64) {
    robject_store_uint64(self, obj);
    return self;
  }

  if (klass == numo_cUInt32) {
    robject_store_uint32(self, obj);
    return self;
  }

  if (klass == numo_cUInt16) {
    robject_store_uint16(self, obj);
    return self;
  }

  if (klass == numo_cUInt8) {
    robject_store_uint8(self, obj);
    return self;
  }

  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 (rb_obj_class(r) == cT) {
      robject_store(self, r);
      return self;
    }
  }

  robject_store_numeric(self, obj);

  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)

    Performs sum along the axis.

  • keepdims (TrueClass)

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

Returns:



3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
# File 'ext/numo/narray/src/t_robject.c', line 3777

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);

  v = na_ndloop(&ndf, 2, self, reduce);

  return robject_extract(v);
}

#to_aArray

Convert self to Array.

Returns:

  • (Array)


1280
1281
1282
1283
1284
1285
# File 'ext/numo/narray/src/t_robject.c', line 1280

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:



3255
3256
3257
3258
3259
3260
3261
# File 'ext/numo/narray/src/t_robject.c', line 3255

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)

    Performs var along the axis.

  • keepdims (TrueClass)

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

Returns:



3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
# File 'ext/numo/narray/src/t_robject.c', line 3953

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);

  v = na_ndloop(&ndf, 2, self, reduce);

  return rb_funcall(v, rb_intern("extract"), 0);
}

#|(other) ⇒ Numo::NArray

Binary bit_or.

Parameters:

Returns:



2738
2739
2740
# File 'ext/numo/narray/src/t_robject.c', line 2738

static VALUE robject_bit_or(VALUE self, VALUE other) {
  return robject_bit_or_self(self, other);
}

#~Numo::RObject

Unary bit_not.

Returns:



2869
2870
2871
2872
2873
2874
2875
# File 'ext/numo/narray/src/t_robject.c', line 2869

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);
}