Class: Numo::Int8

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

Constant Summary collapse

UPCAST =
hCast
ELEMENT_BIT_SIZE =
INT2FIX(sizeof(dtype) * 8)
ELEMENT_BYTE_SIZE =
INT2FIX(sizeof(dtype))
CONTIGUOUS_STRIDE =
INT2FIX(sizeof(dtype))
MAX =
M_MAX
MIN =
M_MIN

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::Int8 .cast(array) ⇒ Numo::Int8

Cast object to Numo::Int8.

Parameters:

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

Returns:



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
# File 'ext/numo/narray/src/t_int8.c', line 1111

static VALUE int8_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 int8_new_dim0(x);
  }
  if (RTEST(rb_obj_is_kind_of(obj, rb_cArray))) {
    return int8_cast_array(obj);
  }
  if (IsNArray(obj)) {
    GetNArray(obj, na);
    v = nary_new(cT, NA_NDIM(na), NA_SHAPE(na));
    if (NA_SIZE(na) > 0) {
      int8_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 int8_cast_array(obj);
  }

  rb_raise(nary_eCastError, "cannot cast to %s", rb_class2name(type));
  return Qnil;
}

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

Cast object to Numo::Int8.

Parameters:

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

Returns:



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
# File 'ext/numo/narray/src/t_int8.c', line 1111

static VALUE int8_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 int8_new_dim0(x);
  }
  if (RTEST(rb_obj_is_kind_of(obj, rb_cArray))) {
    return int8_cast_array(obj);
  }
  if (IsNArray(obj)) {
    GetNArray(obj, na);
    v = nary_new(cT, NA_NDIM(na), NA_SHAPE(na));
    if (NA_SIZE(na) > 0) {
      int8_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 int8_cast_array(obj);
  }

  rb_raise(nary_eCastError, "cannot cast to %s", rb_class2name(type));
  return Qnil;
}

.maximum(*args) ⇒ Object



3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
# File 'ext/numo/narray/src/t_int8.c', line 3921

static VALUE int8_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_int8_s_maximum, STRIDE_LOOP_NIP, 2, 1, ain, aout};

  rb_scan_args(argc, argv, "20", &a1, &a2);

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

.minimum(*args) ⇒ Object



3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
# File 'ext/numo/narray/src/t_int8.c', line 3961

static VALUE int8_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_int8_s_minimum, STRIDE_LOOP_NIP, 2, 1, ain, aout};

  rb_scan_args(argc, argv, "20", &a1, &a2);

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

Instance Method Details

#%(other) ⇒ Numo::NArray

Binary mod.

Parameters:

Returns:



2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
# File 'ext/numo/narray/src/t_int8.c', line 2133

static VALUE int8_mod(VALUE self, VALUE other) {

  VALUE klass, v;

  klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
  if (klass == cT) {
    return int8_mod_self(self, other);
  } else {
    v = rb_funcall(klass, id_cast, 1, self);
    return rb_funcall(v, '%', 1, other);
  }
}

#&(other) ⇒ Numo::NArray

Binary bit_and.

Parameters:

Returns:



2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
# File 'ext/numo/narray/src/t_int8.c', line 2662

static VALUE int8_bit_and(VALUE self, VALUE other) {

  VALUE klass, v;

  klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
  if (klass == cT) {
    return int8_bit_and_self(self, other);
  } else {
    v = rb_funcall(klass, id_cast, 1, self);
    return rb_funcall(v, '&', 1, other);
  }
}

#*(other) ⇒ Numo::NArray

Binary mul.

Parameters:

Returns:



1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
# File 'ext/numo/narray/src/t_int8.c', line 1955

static VALUE int8_mul(VALUE self, VALUE other) {

  VALUE klass, v;

  klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
  if (klass == cT) {
    return int8_mul_self(self, other);
  } else {
    v = rb_funcall(klass, id_cast, 1, self);
    return rb_funcall(v, '*', 1, other);
  }
}

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

Binary power.

Parameters:

Returns:



2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
# File 'ext/numo/narray/src/t_int8.c', line 2251

static VALUE int8_pow(VALUE self, VALUE other) {

  VALUE klass, v;
  klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
  if (klass == cT) {
    return int8_pow_self(self, other);
  } else {
    v = rb_funcall(klass, id_cast, 1, self);
    return rb_funcall(v, id_pow, 1, other);
  }
}

#+(other) ⇒ Numo::NArray

Binary add.

Parameters:

Returns:



1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
# File 'ext/numo/narray/src/t_int8.c', line 1783

static VALUE int8_add(VALUE self, VALUE other) {

  VALUE klass, v;

  klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
  if (klass == cT) {
    return int8_add_self(self, other);
  } else {
    v = rb_funcall(klass, id_cast, 1, self);
    return rb_funcall(v, '+', 1, other);
  }
}

#-(other) ⇒ Numo::NArray

Binary sub.

Parameters:

Returns:



1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
# File 'ext/numo/narray/src/t_int8.c', line 1869

static VALUE int8_sub(VALUE self, VALUE other) {

  VALUE klass, v;

  klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
  if (klass == cT) {
    return int8_sub_self(self, other);
  } else {
    v = rb_funcall(klass, id_cast, 1, self);
    return rb_funcall(v, '-', 1, other);
  }
}

#-@Numo::Int8

Unary minus.

Returns:



2313
2314
2315
2316
2317
2318
2319
# File 'ext/numo/narray/src/t_int8.c', line 2313

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

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

#/(other) ⇒ Numo::NArray

Binary div.

Parameters:

Returns:



2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
# File 'ext/numo/narray/src/t_int8.c', line 2044

static VALUE int8_div(VALUE self, VALUE other) {

  VALUE klass, v;

  klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
  if (klass == cT) {
    return int8_div_self(self, other);
  } else {
    v = rb_funcall(klass, id_cast, 1, self);
    return rb_funcall(v, '/', 1, other);
  }
}

#<<(other) ⇒ Numo::NArray

Binary left_shift.

Parameters:

Returns:



2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
# File 'ext/numo/narray/src/t_int8.c', line 2978

static VALUE int8_left_shift(VALUE self, VALUE other) {

  VALUE klass, v;

  klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
  if (klass == cT) {
    return int8_left_shift_self(self, other);
  } else {
    v = rb_funcall(klass, id_cast, 1, self);
    return rb_funcall(v, id_left_shift, 1, other);
  }
}

#>>(other) ⇒ Numo::NArray

Binary right_shift.

Parameters:

Returns:



3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
# File 'ext/numo/narray/src/t_int8.c', line 3064

static VALUE int8_right_shift(VALUE self, VALUE other) {

  VALUE klass, v;

  klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
  if (klass == cT) {
    return int8_right_shift_self(self, other);
  } else {
    v = rb_funcall(klass, id_cast, 1, self);
    return rb_funcall(v, id_right_shift, 1, other);
  }
}

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

Multi-dimensional element reference. indices.

Parameters:

Returns:

  • (Numeric, Numo::Int8)

    an element or NArray view.

See Also:



1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
# File 'ext/numo/narray/src/t_int8.c', line 1155

static VALUE int8_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:



1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
# File 'ext/numo/narray/src/t_int8.c', line 1179

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

  argc--;
  if (argc == 0) {
    int8_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);
      int8_store(a, argv[argc]);
    } else {
      x = int8_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:



2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
# File 'ext/numo/narray/src/t_int8.c', line 2834

static VALUE int8_bit_xor(VALUE self, VALUE other) {

  VALUE klass, v;

  klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
  if (klass == cT) {
    return int8_bit_xor_self(self, other);
  } else {
    v = rb_funcall(klass, id_cast, 1, self);
    return rb_funcall(v, '^', 1, other);
  }
}

#absNumo::Int8

abs of self.

Returns:



1702
1703
1704
1705
1706
1707
1708
# File 'ext/numo/narray/src/t_int8.c', line 1702

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

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

#allocateObject



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'ext/numo/narray/src/t_int8.c', line 124

static VALUE int8_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);

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

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



3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
# File 'ext/numo/narray/src/t_int8.c', line 3756

static VALUE int8_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_int8_argmax_arg64;

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

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

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

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

#argmin(axis: nil) ⇒ 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:

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



3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
# File 'ext/numo/narray/src/t_int8.c', line 3833

static VALUE int8_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_int8_argmin_arg64;

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

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

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

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

#bincount([weight], minlength: nil) ⇒ UInt32 or UInt64 or SFloat or DFloat

Count the number of occurrences of each non-negative integer value. Only Integer-types has this method.

Examples:

Numo::Int32[0..4].bincount
# => Numo::UInt32#shape=[5]
# [1, 1, 1, 1, 1]

Numo::Int32[0, 1, 1, 3, 2, 1, 7].bincount
# => Numo::UInt32#shape=[8]
# [1, 3, 1, 1, 0, 0, 0, 1]

x = Numo::Int32[0, 1, 1, 3, 2, 1, 7, 23]
x.bincount.size == x.max+1
# => true

w = Numo::DFloat[0.3, 0.5, 0.2, 0.7, 1.0, -0.6]
x = Numo::Int32[0, 1, 1, 2, 2, 2]
x.bincount(w)
# => Numo::DFloat#shape=[3]
# [0.3, 0.7, 1.1]

Parameters:

  • weight (SFloat or DFloat or Array)

    (optional) Array of float values. Its size along last axis should be same as that of self.

  • minlength (Integer)

    (keyword, optional) Minimum size along last axis for the output array.

Returns:

  • (UInt32 or UInt64 or SFloat or DFloat)

    Returns Float NArray if weight array is supplied, otherwise returns UInt32 or UInt64 depending on the size along last axis.



4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
# File 'ext/numo/narray/src/t_int8.c', line 4161

static VALUE int8_bincount(int argc, VALUE* argv, VALUE self) {
  VALUE weight = Qnil, kw = Qnil;
  VALUE opts[1] = {Qundef};
  VALUE v, wclass;
  ID table[1] = {id_minlength};
  size_t length, minlength;

  rb_scan_args(argc, argv, "01:", &weight, &kw);
  rb_get_kwargs(kw, table, 0, 1, opts);

  v = int8_minmax(0, 0, self);
  if (m_num_to_data(RARRAY_AREF(v, 0)) < 0) {
    rb_raise(rb_eArgError, "array items must be non-netagive");
  }
  v = RARRAY_AREF(v, 1);

  length = NUM2SIZET(v) + 1;

  if (opts[0] != Qundef) {
    minlength = NUM2SIZET(opts[0]);
    if (minlength > length) {
      length = minlength;
    }
  }

  if (NIL_P(weight)) {
    if (length > 4294967295ul) {
      return int8_bincount_64(self, length);
    } else {
      return int8_bincount_32(self, length);
    }
  } else {
    wclass = rb_obj_class(weight);
    if (wclass == numo_cSFloat) {
      return int8_bincount_sf(self, weight, length);
    } else {
      return int8_bincount_df(self, weight, length);
    }
  }
}

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



3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
# File 'ext/numo/narray/src/t_int8.c', line 3360

static VALUE int8_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_int8_clip_min, STRIDE_LOOP, 2, 1, ain, aout};
  ndfunc_t ndf_max = {iter_int8_clip_max, STRIDE_LOOP, 2, 1, ain, aout};
  ndfunc_t ndf_both = {iter_int8_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)


1208
1209
1210
# File 'ext/numo/narray/src/t_int8.c', line 1208

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

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

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:



4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
# File 'ext/numo/narray/src/t_int8.c', line 4271

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

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

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

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

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:



4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
# File 'ext/numo/narray/src/t_int8.c', line 4231

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

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

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

#divmod(other) ⇒ Numo::NArray

Binary divmod.

Parameters:

Returns:



2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
# File 'ext/numo/narray/src/t_int8.c', line 2183

static VALUE int8_divmod(VALUE self, VALUE other) {

  VALUE klass, v;
  klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
  if (klass == cT) {
    return int8_divmod_self(self, other);
  } else {
    v = rb_funcall(klass, id_cast, 1, self);
    return rb_funcall(v, id_divmod, 1, other);
  }
}

#eachNumo::NArray

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

Yield Parameters:

  • x (Numeric)

    an element of NArray.

Returns:

See Also:



1435
1436
1437
1438
1439
1440
1441
# File 'ext/numo/narray/src/t_int8.c', line 1435

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



1557
1558
1559
1560
1561
1562
1563
# File 'ext/numo/narray/src/t_int8.c', line 1557

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

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

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

Comparison eq other.

Parameters:

Returns:



2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
# File 'ext/numo/narray/src/t_int8.c', line 2530

static VALUE int8_eq(VALUE self, VALUE other) {

  VALUE klass, v;
  klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
  if (klass == cT) {
    return int8_eq_self(self, other);
  } else {
    v = rb_funcall(klass, id_cast, 1, self);
    return rb_funcall(v, id_eq, 1, other);
  }
}

#extractNumeric, Numo::NArray

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

Returns:



159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'ext/numo/narray/src/t_int8.c', line 159

static VALUE int8_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::Int8

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:



4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
# File 'ext/numo/narray/src/t_int8.c', line 4487

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

Fill elements with other.

Parameters:

  • other (Numeric)

Returns:



1277
1278
1279
1280
1281
1282
1283
# File 'ext/numo/narray/src/t_int8.c', line 1277

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

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

#format(format) ⇒ Numo::RObject

Format elements into strings.

Parameters:

  • format (String)

Returns:



1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
# File 'ext/numo/narray/src/t_int8.c', line 1331

static VALUE int8_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_int8_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.



1378
1379
1380
1381
1382
1383
1384
1385
1386
# File 'ext/numo/narray/src/t_int8.c', line 1378

static VALUE int8_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_int8_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:



3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
# File 'ext/numo/narray/src/t_int8.c', line 3159

static VALUE int8_ge(VALUE self, VALUE other) {

  VALUE klass, v;
  klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
  if (klass == cT) {
    return int8_ge_self(self, other);
  } else {
    v = rb_funcall(klass, id_cast, 1, self);
    return rb_funcall(v, id_ge, 1, other);
  }
}

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

Comparison gt other.

Parameters:

Returns:



3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
# File 'ext/numo/narray/src/t_int8.c', line 3112

static VALUE int8_gt(VALUE self, VALUE other) {

  VALUE klass, v;
  klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
  if (klass == cT) {
    return int8_gt_self(self, other);
  } else {
    v = rb_funcall(klass, id_cast, 1, self);
    return rb_funcall(v, id_gt, 1, other);
  }
}

#inspectString

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

Returns:

  • (String)


1397
1398
1399
# File 'ext/numo/narray/src/t_int8.c', line 1397

static VALUE int8_inspect(VALUE ary) {
  return na_ndloop_inspect(ary, iter_int8_inspect, Qnil);
}

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

Comparison le other.

Parameters:

Returns:



3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
# File 'ext/numo/narray/src/t_int8.c', line 3253

static VALUE int8_le(VALUE self, VALUE other) {

  VALUE klass, v;
  klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
  if (klass == cT) {
    return int8_le_self(self, other);
  } else {
    v = rb_funcall(klass, id_cast, 1, self);
    return rb_funcall(v, id_le, 1, other);
  }
}

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

Comparison lt other.

Parameters:

Returns:



3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
# File 'ext/numo/narray/src/t_int8.c', line 3206

static VALUE int8_lt(VALUE self, VALUE other) {

  VALUE klass, v;
  klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
  if (klass == cT) {
    return int8_lt_self(self, other);
  } else {
    v = rb_funcall(klass, id_cast, 1, self);
    return rb_funcall(v, id_lt, 1, other);
  }
}

#mapNumo::Int8

Unary map.

Returns:



1493
1494
1495
1496
1497
1498
1499
# File 'ext/numo/narray/src/t_int8.c', line 1493

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



1648
1649
1650
1651
1652
1653
1654
# File 'ext/numo/narray/src/t_int8.c', line 1648

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

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

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

max of self.

Parameters:

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



3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
# File 'ext/numo/narray/src/t_int8.c', line 3497

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

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

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

  return int8_extract(v);
}

#max_index(axis: nil) ⇒ 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:

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



3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
# File 'ext/numo/narray/src/t_int8.c', line 3594

static VALUE int8_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_int8_max_index_index64;

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

  } else {
    aout[0].type = numo_cInt32;
    idx = nary_new(numo_cInt32, na->ndim, na->shape);
    ndf.func = iter_int8_max_index_index32;

    reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, 0);
  }
  rb_funcall(idx, rb_intern("seq"), 0);

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

#median(axis: nil, keepdims: false) ⇒ Numo::Int8

median of self.

Parameters:

  • axis (Numeric, Array, Range)

    Finds median along the axis.

  • keepdims (TrueClass)

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

Returns:



5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
# File 'ext/numo/narray/src/t_int8.c', line 5190

static VALUE int8_median(int argc, VALUE* argv, VALUE self) {
  VALUE v, reduce;
  ndfunc_arg_in_t ain[2] = {{OVERWRITE, 0}, {sym_reduce, 0}};
  ndfunc_arg_out_t aout[1] = {{INT2FIX(0), 0}};
  ndfunc_t ndf = {0, NDF_HAS_LOOP | NDF_FLAT_REDUCE, 2, 1, ain, aout};

  self = na_copy(self); // as temporary buffer

  ndf.func = iter_int8_median;
  reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, 0);

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

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

min of self.

Parameters:

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



3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
# File 'ext/numo/narray/src/t_int8.c', line 3465

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

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

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

  return int8_extract(v);
}

#min_index(axis: nil) ⇒ 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:

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



3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
# File 'ext/numo/narray/src/t_int8.c', line 3676

static VALUE int8_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_int8_min_index_index64;

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

  } else {
    aout[0].type = numo_cInt32;
    idx = nary_new(numo_cInt32, na->ndim, na->shape);
    ndf.func = iter_int8_min_index_index32;

    reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, 0);
  }
  rb_funcall(idx, rb_intern("seq"), 0);

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

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

minmax of self.

Parameters:

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



3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
# File 'ext/numo/narray/src/t_int8.c', line 3882

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

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

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

#mulsum(other, axis: nil, keepdims: 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.

Returns:



4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
# File 'ext/numo/narray/src/t_int8.c', line 4348

static VALUE int8_mulsum(int argc, VALUE* argv, VALUE self) {
  //
  VALUE klass, v;
  //
  if (argc < 1) {
    rb_raise(rb_eArgError, "wrong number of arguments (%d for >=1)", argc);
  }
  //
  klass = na_upcast(rb_obj_class(self), rb_obj_class(argv[0]));
  if (klass == cT) {
    return int8_mulsum_self(argc, argv, self);
  } else {
    v = rb_funcall(klass, id_cast, 1, self);
    //
    return rb_funcallv_kw(v, rb_intern("mulsum"), argc, argv, RB_PASS_CALLED_KEYWORDS);
    //
  }
  //
}

#ne(other) ⇒ Numo::Bit

Comparison ne other.

Parameters:

Returns:



2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
# File 'ext/numo/narray/src/t_int8.c', line 2577

static VALUE int8_ne(VALUE self, VALUE other) {

  VALUE klass, v;
  klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
  if (klass == cT) {
    return int8_ne_self(self, other);
  } else {
    v = rb_funcall(klass, id_cast, 1, self);
    return rb_funcall(v, id_ne, 1, other);
  }
}

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

Calculate polynomial.

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

Parameters:

Returns:



4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
# File 'ext/numo/narray/src/t_int8.c', line 4678

static VALUE int8_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_int8_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 int8_extract(v);
}

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

prod of self.

Parameters:

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



3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
# File 'ext/numo/narray/src/t_int8.c', line 3433

static VALUE int8_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] = {{numo_cInt64, 0}};
  ndfunc_t ndf = {iter_int8_prod, STRIDE_LOOP_NIP | NDF_FLAT_REDUCE, 2, 1, ain, aout};

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

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

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

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

ptp of self.

Parameters:

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



3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
# File 'ext/numo/narray/src/t_int8.c', line 3529

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

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

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

  return int8_extract(v);
}

#rand(, self) ⇒ Object



4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
# File 'ext/numo/narray/src/t_int8.c', line 4629

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

  rb_scan_args(argc, args, "11", &v1, &v2);
  if (v2 == Qnil) {
    g.low = m_zero;
    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);
  }

  if (high <= g.low) {
    rb_raise(rb_eArgError, "high must be larger than low");
  }

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

#reciprocalNumo::Int8

Unary reciprocal.

Returns:



2371
2372
2373
2374
2375
2376
2377
# File 'ext/numo/narray/src/t_int8.c', line 2371

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

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

#seq(, self) ⇒ Object Also known as: indgen



4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
# File 'ext/numo/narray/src/t_int8.c', line 4427

static VALUE int8_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_int8_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 = NUM2DBL(vbeg);
  }
  if (vstep != Qnil) {
    g->step = NUM2DBL(vstep);
  }

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

#signNumo::Int8

Unary sign.

Returns:



2429
2430
2431
2432
2433
2434
2435
# File 'ext/numo/narray/src/t_int8.c', line 2429

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

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

#sort(axis: nil) ⇒ Numo::Int8

sort of self.

Examples:

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

Parameters:

  • axis (Numeric, Array, Range)

    Performs sort along the axis.

Returns:



4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
# File 'ext/numo/narray/src/t_int8.c', line 4896

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

  if (!TEST_INPLACE(self)) {
    self = na_copy(self);
  }

  ndf.func = iter_int8_sort;
  reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, 0);

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

#sort_index(axis: nil) ⇒ Integer, Numo::Int

sort_index. Returns an index array of sort result.

Examples:

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

Parameters:

  • axis (Numeric, Array, Range)

    Performs sort_index along the axis.

Returns:

  • (Integer, Numo::Int)

    returns result index of sort_index.



5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
# File 'ext/numo/narray/src/t_int8.c', line 5125

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

  GetNArray(self, na);
  if (na->ndim == 0) {
    return INT2FIX(0);
  }
  if (na->size > (~(u_int32_t)0)) {
    ain[1].type = aout[0].type = numo_cInt64;
    idx = nary_new(numo_cInt64, na->ndim, na->shape);

    ndf.func = int8_index64_qsort;
    reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, 0);

  } else {
    ain[1].type = aout[0].type = numo_cInt32;
    idx = nary_new(numo_cInt32, na->ndim, na->shape);

    ndf.func = int8_index32_qsort;
    reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, 0);
  }
  rb_funcall(idx, rb_intern("seq"), 0);

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

#squareNumo::Int8

Unary square.

Returns:



2487
2488
2489
2490
2491
2492
2493
# File 'ext/numo/narray/src/t_int8.c', line 2487

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

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

#store(other) ⇒ Numo::Int8

Store elements to Numo::Int8 from other.

Parameters:

  • other (Object)

Returns:



902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
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
# File 'ext/numo/narray/src/t_int8.c', line 902

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

  klass = rb_obj_class(obj);

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

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

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

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

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

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

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

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

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

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

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

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

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

  if (klass == rb_cArray) {
    int8_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) {
      int8_store(self, r);
      return self;
    }
  }

  rb_raise(nary_eCastError, "unknown conversion from %s to %s", rb_class2name(rb_obj_class(obj)),
           rb_class2name(rb_obj_class(self)));

  return self;
}

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

sum of self.

Parameters:

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



3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
# File 'ext/numo/narray/src/t_int8.c', line 3401

static VALUE int8_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] = {{numo_cInt64, 0}};
  ndfunc_t ndf = {iter_int8_sum, STRIDE_LOOP_NIP | NDF_FLAT_REDUCE, 2, 1, ain, aout};

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

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

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

#to_aArray

Convert self to Array.

Returns:

  • (Array)


1243
1244
1245
1246
1247
1248
# File 'ext/numo/narray/src/t_int8.c', line 1243

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

#|(other) ⇒ Numo::NArray

Binary bit_or.

Parameters:

Returns:



2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
# File 'ext/numo/narray/src/t_int8.c', line 2748

static VALUE int8_bit_or(VALUE self, VALUE other) {

  VALUE klass, v;

  klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
  if (klass == cT) {
    return int8_bit_or_self(self, other);
  } else {
    v = rb_funcall(klass, id_cast, 1, self);
    return rb_funcall(v, '|', 1, other);
  }
}

#~Numo::Int8

Unary bit_not.

Returns:



2897
2898
2899
2900
2901
2902
2903
# File 'ext/numo/narray/src/t_int8.c', line 2897

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

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