Class: Numo::Int64

Inherits:
NArray show all
Defined in:
ext/numo/narray/src/t_int64.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::Int64 .cast(array) ⇒ Numo::Int64

Cast object to Numo::Int64.

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_int64.c', line 1111

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

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

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

Cast object to Numo::Int64.

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_int64.c', line 1111

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

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

.maximum(*args) ⇒ Object



4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
# File 'ext/numo/narray/src/t_int64.c', line 4323

static VALUE int64_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_int64_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



4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
# File 'ext/numo/narray/src/t_int64.c', line 4363

static VALUE int64_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_int64_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:



2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
# File 'ext/numo/narray/src/t_int64.c', line 2300

static VALUE int64_mod(VALUE self, VALUE other) {

  VALUE klass, v;

  klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
  if (klass == cT) {
    return int64_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:



2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
# File 'ext/numo/narray/src/t_int64.c', line 2927

static VALUE int64_bit_and(VALUE self, VALUE other) {

  VALUE klass, v;

  klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
  if (klass == cT) {
    return int64_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:



2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
# File 'ext/numo/narray/src/t_int64.c', line 2062

static VALUE int64_mul(VALUE self, VALUE other) {

  VALUE klass, v;

  klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
  if (klass == cT) {
    return int64_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:



2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
# File 'ext/numo/narray/src/t_int64.c', line 2418

static VALUE int64_pow(VALUE self, VALUE other) {

  VALUE klass, v;
  klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
  if (klass == cT) {
    return int64_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:



1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
# File 'ext/numo/narray/src/t_int64.c', line 1830

static VALUE int64_add(VALUE self, VALUE other) {

  VALUE klass, v;

  klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
  if (klass == cT) {
    return int64_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:



1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
# File 'ext/numo/narray/src/t_int64.c', line 1946

static VALUE int64_sub(VALUE self, VALUE other) {

  VALUE klass, v;

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

#-@Numo::Int64

Unary minus.

Returns:



2497
2498
2499
2500
2501
2502
2503
# File 'ext/numo/narray/src/t_int64.c', line 2497

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

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

#/(other) ⇒ Numo::NArray

Binary div.

Parameters:

Returns:



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

static VALUE int64_div(VALUE self, VALUE other) {

  VALUE klass, v;

  klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
  if (klass == cT) {
    return int64_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:



3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
# File 'ext/numo/narray/src/t_int64.c', line 3350

static VALUE int64_left_shift(VALUE self, VALUE other) {

  VALUE klass, v;

  klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
  if (klass == cT) {
    return int64_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:



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

static VALUE int64_right_shift(VALUE self, VALUE other) {

  VALUE klass, v;

  klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
  if (klass == cT) {
    return int64_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::Int64

Multi-dimensional element reference. indices.

Parameters:

Returns:

  • (Numeric, Numo::Int64)

    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_int64.c', line 1155

static VALUE int64_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_int64.c', line 1179

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

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



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

static VALUE int64_bit_xor(VALUE self, VALUE other) {

  VALUE klass, v;

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

#absNumo::Int64

abs of self.

Returns:



1719
1720
1721
1722
1723
1724
1725
# File 'ext/numo/narray/src/t_int64.c', line 1719

static VALUE int64_abs(VALUE self) {
  ndfunc_arg_in_t ain[1] = {{cT, 0}};
  ndfunc_arg_out_t aout[1] = {{cRT, 0}};
  ndfunc_t ndf = {iter_int64_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_int64.c', line 124

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



4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
# File 'ext/numo/narray/src/t_int64.c', line 4158

static VALUE int64_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_int64_argmax_arg64;

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

  } else {
    aout[0].type = numo_cInt32;
    ndf.func = iter_int64_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:



4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
# File 'ext/numo/narray/src/t_int64.c', line 4235

static VALUE int64_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_int64_argmin_arg64;

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

  } else {
    aout[0].type = numo_cInt32;
    ndf.func = iter_int64_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.



4563
4564
4565
4566
4567
4568
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
4595
4596
4597
4598
4599
4600
4601
4602
# File 'ext/numo/narray/src/t_int64.c', line 4563

static VALUE int64_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 = int64_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 int64_bincount_64(self, length);
    } else {
      return int64_bincount_32(self, length);
    }
  } else {
    wclass = rb_obj_class(weight);
    if (wclass == numo_cSFloat) {
      return int64_bincount_sf(self, weight, length);
    } else {
      return int64_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:



3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
# File 'ext/numo/narray/src/t_int64.c', line 3762

static VALUE int64_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_int64_clip_min, STRIDE_LOOP, 2, 1, ain, aout};
  ndfunc_t ndf_max = {iter_int64_clip_max, STRIDE_LOOP, 2, 1, ain, aout};
  ndfunc_t ndf_both = {iter_int64_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_int64.c', line 1208

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

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

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:



4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
# File 'ext/numo/narray/src/t_int64.c', line 4673

static VALUE int64_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_int64_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::Int64

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:



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

static VALUE int64_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_int64_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:



2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
# File 'ext/numo/narray/src/t_int64.c', line 2350

static VALUE int64_divmod(VALUE self, VALUE other) {

  VALUE klass, v;
  klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
  if (klass == cT) {
    return int64_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_int64.c', line 1435

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



1574
1575
1576
1577
1578
1579
1580
# File 'ext/numo/narray/src/t_int64.c', line 1574

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



2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
# File 'ext/numo/narray/src/t_int64.c', line 2765

static VALUE int64_eq(VALUE self, VALUE other) {

  VALUE klass, v;
  klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
  if (klass == cT) {
    return int64_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_int64.c', line 159

static VALUE int64_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::Int64

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:



4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
# File 'ext/numo/narray/src/t_int64.c', line 4889

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

Fill elements with other.

Parameters:

  • other (Numeric)

Returns:



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

static VALUE int64_fill(VALUE self, VALUE val) {
  ndfunc_arg_in_t ain[2] = {{OVERWRITE, 0}, {sym_option}};
  ndfunc_t ndf = {iter_int64_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_int64.c', line 1331

static VALUE int64_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_int64_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_int64.c', line 1378

static VALUE int64_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_int64_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:



3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
# File 'ext/numo/narray/src/t_int64.c', line 3561

static VALUE int64_ge(VALUE self, VALUE other) {

  VALUE klass, v;
  klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
  if (klass == cT) {
    return int64_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:



3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
# File 'ext/numo/narray/src/t_int64.c', line 3514

static VALUE int64_gt(VALUE self, VALUE other) {

  VALUE klass, v;
  klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
  if (klass == cT) {
    return int64_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_int64.c', line 1397

static VALUE int64_inspect(VALUE ary) {
  return na_ndloop_inspect(ary, iter_int64_inspect, Qnil);
}

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

Comparison le other.

Parameters:

Returns:



3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
# File 'ext/numo/narray/src/t_int64.c', line 3655

static VALUE int64_le(VALUE self, VALUE other) {

  VALUE klass, v;
  klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
  if (klass == cT) {
    return int64_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:



3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
# File 'ext/numo/narray/src/t_int64.c', line 3608

static VALUE int64_lt(VALUE self, VALUE other) {

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

#mapNumo::Int64

Unary map.

Returns:



1510
1511
1512
1513
1514
1515
1516
# File 'ext/numo/narray/src/t_int64.c', line 1510

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



1665
1666
1667
1668
1669
1670
1671
# File 'ext/numo/narray/src/t_int64.c', line 1665

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

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

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

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:



3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
# File 'ext/numo/narray/src/t_int64.c', line 3899

static VALUE int64_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_int64_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 int64_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:



3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
# File 'ext/numo/narray/src/t_int64.c', line 3996

static VALUE int64_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_int64_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_int64_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::Int64

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:



5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
# File 'ext/numo/narray/src/t_int64.c', line 5594

static VALUE int64_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_int64_median;
  reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, 0);

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

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

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:



3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
# File 'ext/numo/narray/src/t_int64.c', line 3867

static VALUE int64_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_int64_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 int64_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:



4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
# File 'ext/numo/narray/src/t_int64.c', line 4078

static VALUE int64_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_int64_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_int64_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::Int64

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:



4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
# File 'ext/numo/narray/src/t_int64.c', line 4284

static VALUE int64_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_int64_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:



4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
# File 'ext/numo/narray/src/t_int64.c', line 4750

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



2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
# File 'ext/numo/narray/src/t_int64.c', line 2812

static VALUE int64_ne(VALUE self, VALUE other) {

  VALUE klass, v;
  klass = na_upcast(rb_obj_class(self), rb_obj_class(other));
  if (klass == cT) {
    return int64_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::Int64

Calculate polynomial.

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

Parameters:

Returns:



5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
# File 'ext/numo/narray/src/t_int64.c', line 5082

static VALUE int64_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_int64_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 int64_extract(v);
}

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

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:



3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
# File 'ext/numo/narray/src/t_int64.c', line 3835

static VALUE int64_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_int64_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::Int64

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:



3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
# File 'ext/numo/narray/src/t_int64.c', line 3931

static VALUE int64_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_int64_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 int64_extract(v);
}

#rand(, self) ⇒ Object



5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
# File 'ext/numo/narray/src/t_int64.c', line 5033

static VALUE int64_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_int64_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::Int64

Unary reciprocal.

Returns:



2572
2573
2574
2575
2576
2577
2578
# File 'ext/numo/narray/src/t_int64.c', line 2572

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

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

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



4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
# File 'ext/numo/narray/src/t_int64.c', line 4829

static VALUE int64_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_int64_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::Int64

Unary sign.

Returns:



2647
2648
2649
2650
2651
2652
2653
# File 'ext/numo/narray/src/t_int64.c', line 2647

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

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

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

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:



5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
# File 'ext/numo/narray/src/t_int64.c', line 5300

static VALUE int64_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_int64_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.



5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
# File 'ext/numo/narray/src/t_int64.c', line 5529

static VALUE int64_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 = int64_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 = int64_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::Int64

Unary square.

Returns:



2722
2723
2724
2725
2726
2727
2728
# File 'ext/numo/narray/src/t_int64.c', line 2722

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

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

#store(other) ⇒ Numo::Int64

Store elements to Numo::Int64 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_int64.c', line 902

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

  klass = rb_obj_class(obj);

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

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

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

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

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

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

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

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

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

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

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

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

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

  if (klass == rb_cArray) {
    int64_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) {
      int64_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::Int64

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:



3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
# File 'ext/numo/narray/src/t_int64.c', line 3803

static VALUE int64_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_int64_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_int64.c', line 1243

static VALUE int64_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_int64_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:



3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
# File 'ext/numo/narray/src/t_int64.c', line 3043

static VALUE int64_bit_or(VALUE self, VALUE other) {

  VALUE klass, v;

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

#~Numo::Int64

Unary bit_not.

Returns:



3239
3240
3241
3242
3243
3244
3245
# File 'ext/numo/narray/src/t_int64.c', line 3239

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

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