Class: Numo::Bit
- Defined in:
- ext/numo/narray/src/t_bit.c,
ext/numo/narray/src/t_bit.c
Overview
Binary digit (bit) N-dimensional array class.
Constant Summary collapse
- UPCAST =
Upcasting rules of Bit.
hCast- ELEMENT_BIT_SIZE =
Element size of Bit in bits.
INT2FIX(1)
- ELEMENT_BYTE_SIZE =
Element size of Bit in bytes.
rb_float_new(1.0 / 8)
- CONTIGUOUS_STRIDE =
Stride size of contiguous Bit array.
INT2FIX(1)
Constants inherited from NArray
NArray::ALTERNATIVE, NArray::VERSION
Class Method Summary collapse
Instance Method Summary collapse
- #&(other) ⇒ Object
-
#[](dim0, ..., dimL) ⇒ Numeric, Numo::Bit
Multi-dimensional element reference.
- #[]=(*args) ⇒ Object
- #^(other) ⇒ Object
- #all?(*args) ⇒ Object
- #allocate ⇒ Object
- #any?(*args) ⇒ Object
-
#coerce_cast(type) ⇒ nil
return NArray with cast to the type of self.
- #copy ⇒ Object
- #count_false(*args) ⇒ Object (also: #count_0)
- #count_true(*args) ⇒ Object (also: #count_1, #count)
-
#each {|x| ... } ⇒ Numo::NArray
Calls the given block once for each element in self, passing that element as a parameter.
-
#each_with_index {|x, i, j, ...| ... } ⇒ Numo::NArray
Invokes the given block once for each element of self, passing that element and indices along each axis as parameters.
- #eq(other) ⇒ Object
-
#extract ⇒ Numeric, Numo::NArray
Extract an element only if self is a dimensionless NArray.
-
#fill(other) ⇒ Numo::Bit
Fill elements with other.
-
#format(format) ⇒ Numo::RObject
Format elements into strings.
-
#format_to_a(format) ⇒ Array
Format elements into strings.
-
#inspect ⇒ String
Returns a string containing a human-readable representation of NArray.
- #mask(val) ⇒ Object
-
#mean(axis: nil, keepdims: false, nan: false) ⇒ Numo::DFloat
mean of self.
- #none?(*args) ⇒ Boolean
-
#rms(axis: nil, keepdims: false, nan: false) ⇒ Numo::DFloat
rms of self.
-
#stddev(axis: nil, keepdims: false, nan: false) ⇒ Numo::DFloat
stddev of self.
- #store(obj) ⇒ Object
-
#to_a ⇒ Array
Convert self to Array.
-
#var(axis: nil, keepdims: false, nan: false) ⇒ Numo::DFloat
var of self.
- #where ⇒ Object
- #where2 ⇒ Object
- #|(other) ⇒ Object
- #~ ⇒ Object
Methods inherited from NArray
#==, alternative?, #append, #argsort, 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
.[](obj) ⇒ Object
1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 |
# File 'ext/numo/narray/src/t_bit.c', line 1579
static VALUE bit_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 bit_new_dim0(x);
}
if (RTEST(rb_obj_is_kind_of(obj, rb_cArray))) {
return bit_cast_array(obj);
}
if (IsNArray(obj)) {
GetNArray(obj, na);
v = nary_new(cT, NA_NDIM(na), NA_SHAPE(na));
if (NA_SIZE(na) > 0) {
bit_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 bit_cast_array(obj);
}
rb_raise(nary_eCastError, "cannot cast to %s", rb_class2name(type));
return Qnil;
}
|
.cast(obj) ⇒ Object
1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 |
# File 'ext/numo/narray/src/t_bit.c', line 1579
static VALUE bit_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 bit_new_dim0(x);
}
if (RTEST(rb_obj_is_kind_of(obj, rb_cArray))) {
return bit_cast_array(obj);
}
if (IsNArray(obj)) {
GetNArray(obj, na);
v = nary_new(cT, NA_NDIM(na), NA_SHAPE(na));
if (NA_SIZE(na) > 0) {
bit_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 bit_cast_array(obj);
}
rb_raise(nary_eCastError, "cannot cast to %s", rb_class2name(type));
return Qnil;
}
|
Instance Method Details
#&(other) ⇒ Object
1973 1974 1975 1976 1977 1978 1979 |
# File 'ext/numo/narray/src/t_bit.c', line 1973
static VALUE bit_and(VALUE self, VALUE other) {
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
ndfunc_t ndf = { iter_bit_and, FULL_LOOP, 2, 1, ain, aout };
return na_ndloop(&ndf, 2, self, other);
}
|
#[](dim0, ..., dimL) ⇒ Numeric, Numo::Bit
Multi-dimensional element reference.
45 46 47 48 49 50 51 52 53 54 55 |
# File 'ext/numo/narray/src/t_bit.c', line 45
static VALUE bit_aref(int argc, VALUE* argv, VALUE self) {
size_t pos;
int nd = na_get_result_dimension(self, argc, argv, 1, &pos);
if (nd) {
return na_aref_main(argc, argv, self, 0, nd);
}
char* ptr = na_get_pointer_for_read(self);
BIT_DIGIT x;
LOAD_BIT(ptr, pos, x);
return m_data_to_num(x);
}
|
#[]=(*args) ⇒ Object
1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 |
# File 'ext/numo/narray/src/t_bit.c', line 1640
static VALUE bit_aset(int argc, VALUE* argv, VALUE self) {
int nd;
size_t pos;
char* ptr;
VALUE a;
dtype x;
argc--;
if (argc == 0) {
bit_store(self, argv[argc]);
} else {
nd = na_get_result_dimension(self, argc, argv, 1, &pos);
if (nd) {
a = na_aref_main(argc, argv, self, 0, nd);
bit_store(a, argv[argc]);
} else {
x = bit_extract_data(argv[argc]);
ptr = na_get_pointer_for_read_write(self);
STORE_BIT(ptr, pos, x);
}
}
return argv[argc];
}
|
#^(other) ⇒ Object
2231 2232 2233 2234 2235 2236 2237 |
# File 'ext/numo/narray/src/t_bit.c', line 2231
static VALUE bit_xor(VALUE self, VALUE other) {
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
ndfunc_t ndf = { iter_bit_xor, FULL_LOOP, 2, 1, ain, aout };
return na_ndloop(&ndf, 2, self, other);
}
|
#all?(*args) ⇒ Object
2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 |
# File 'ext/numo/narray/src/t_bit.c', line 2643
static VALUE bit_all_p(int argc, VALUE* argv, VALUE self) {
VALUE v, reduce;
narray_t* na;
ndfunc_arg_in_t ain[3] = { { cT, 0 }, { sym_reduce, 0 }, { sym_init, 0 } };
ndfunc_arg_out_t aout[1] = { { numo_cBit, 0 } };
ndfunc_t ndf = { iter_bit_all_p, FULL_LOOP_NIP, 3, 1, ain, aout };
GetNArray(self, na);
if (NA_SIZE(na) == 0) {
return Qfalse;
}
reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, 0);
v = na_ndloop(&ndf, 3, self, reduce, INT2FIX(1));
if (argc > 0) {
return v;
}
v = bit_extract(v);
switch (v) {
case INT2FIX(0):
return Qfalse;
case INT2FIX(1):
return Qtrue;
default:
rb_bug("unexpected result");
return v;
}
}
|
#allocate ⇒ Object
510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 |
# File 'ext/numo/narray/src/t_bit.c', line 510
static VALUE bit_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(((na->size - 1) / 8 / sizeof(BIT_DIGIT) + 1) * sizeof(BIT_DIGIT));
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;
default:
rb_raise(rb_eRuntimeError, "invalid narray type");
}
return self;
}
|
#any?(*args) ⇒ Object
2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 |
# File 'ext/numo/narray/src/t_bit.c', line 2771
static VALUE bit_any_p(int argc, VALUE* argv, VALUE self) {
VALUE v, reduce;
narray_t* na;
ndfunc_arg_in_t ain[3] = { { cT, 0 }, { sym_reduce, 0 }, { sym_init, 0 } };
ndfunc_arg_out_t aout[1] = { { numo_cBit, 0 } };
ndfunc_t ndf = { iter_bit_any_p, FULL_LOOP_NIP, 3, 1, ain, aout };
GetNArray(self, na);
if (NA_SIZE(na) == 0) {
return Qfalse;
}
reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, 0);
v = na_ndloop(&ndf, 3, self, reduce, INT2FIX(0));
if (argc > 0) {
return v;
}
v = bit_extract(v);
switch (v) {
case INT2FIX(0):
return Qfalse;
case INT2FIX(1):
return Qtrue;
default:
rb_bug("unexpected result");
return v;
}
}
|
#coerce_cast(type) ⇒ nil
return NArray with cast to the type of self.
57 58 59 |
# File 'ext/numo/narray/src/t_bit.c', line 57
static VALUE bit_coerce_cast(VALUE self, VALUE type) {
return Qnil;
}
|
#copy ⇒ Object
1750 1751 1752 1753 1754 1755 1756 |
# File 'ext/numo/narray/src/t_bit.c', line 1750
static VALUE bit_copy(VALUE self) {
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
ndfunc_t ndf = { iter_bit_copy, FULL_LOOP, 1, 1, ain, aout };
return na_ndloop(&ndf, 1, self);
}
|
#count_false(*args) ⇒ Object Also known as: count_0
2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 |
# File 'ext/numo/narray/src/t_bit.c', line 2528
static VALUE bit_count_false(int argc, VALUE* argv, VALUE self) {
VALUE v, reduce;
narray_t* na;
ndfunc_arg_in_t ain[3] = { { cT, 0 }, { sym_reduce, 0 }, { sym_init, 0 } };
ndfunc_arg_out_t aout[1] = { { numo_cInt64, 0 } };
ndfunc_t ndf = { iter_bit_count_false, FULL_LOOP_NIP, 3, 1, ain, aout };
GetNArray(self, na);
if (NA_SIZE(na) == 0) {
return INT2FIX(0);
}
reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, 0);
v = na_ndloop(&ndf, 3, self, reduce, INT2FIX(0));
return rb_funcall(v, rb_intern("extract"), 0);
}
|
#count_true(*args) ⇒ Object Also known as: count_1, count
2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 |
# File 'ext/numo/narray/src/t_bit.c', line 2440
static VALUE bit_count_true(int argc, VALUE* argv, VALUE self) {
VALUE v, reduce;
narray_t* na;
ndfunc_arg_in_t ain[3] = { { cT, 0 }, { sym_reduce, 0 }, { sym_init, 0 } };
ndfunc_arg_out_t aout[1] = { { numo_cInt64, 0 } };
ndfunc_t ndf = { iter_bit_count_true, FULL_LOOP_NIP, 3, 1, ain, aout };
GetNArray(self, na);
if (NA_SIZE(na) == 0) {
return INT2FIX(0);
}
reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, 0);
v = na_ndloop(&ndf, 3, self, reduce, INT2FIX(0));
return rb_funcall(v, rb_intern("extract"), 0);
}
|
#each {|x| ... } ⇒ Numo::NArray
Calls the given block once for each element in self, passing that element as a parameter.
288 289 290 291 292 293 |
# File 'ext/numo/narray/src/t_bit.c', line 288
static VALUE bit_each(VALUE self) {
ndfunc_arg_in_t ain[1] = { { Qnil, 0 } };
ndfunc_t ndf = { iter_bit_each, FULL_LOOP_NIP, 1, 0, ain, 0 };
na_ndloop(&ndf, 1, self);
return self;
}
|
#each_with_index {|x, i, j, ...| ... } ⇒ Numo::NArray
Invokes the given block once for each element of self, passing that element and indices along each axis as parameters.
334 335 336 337 338 339 |
# File 'ext/numo/narray/src/t_bit.c', line 334
static VALUE bit_each_with_index(VALUE self) {
ndfunc_arg_in_t ain[1] = { { Qnil, 0 } };
ndfunc_t ndf = { iter_bit_each_with_index, FULL_LOOP_NIP, 1, 0, ain, 0 };
na_ndloop_with_index(&ndf, 1, self);
return self;
}
|
#eq(other) ⇒ Object
2360 2361 2362 2363 2364 2365 2366 |
# File 'ext/numo/narray/src/t_bit.c', line 2360
static VALUE bit_eq(VALUE self, VALUE other) {
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
ndfunc_t ndf = { iter_bit_eq, FULL_LOOP, 2, 1, ain, aout };
return na_ndloop(&ndf, 2, self, other);
}
|
#extract ⇒ Numeric, Numo::NArray
Extract an element only if self is a dimensionless NArray.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'ext/numo/narray/src/t_bit.c', line 29
static VALUE bit_extract(VALUE self) {
BIT_DIGIT* ptr;
BIT_DIGIT val;
size_t pos;
narray_t* na;
GetNArray(self, na);
if (na->ndim == 0) {
pos = na_get_offset(self);
ptr = (BIT_DIGIT*)na_get_pointer_for_read(self);
val = ((*((ptr) + (pos) / NB)) >> ((pos) % NB)) & 1u;
na_release_lock(self);
return INT2FIX(val);
}
return self;
}
|
#fill(other) ⇒ Numo::Bit
Fill elements with other.
150 151 152 153 154 155 |
# File 'ext/numo/narray/src/t_bit.c', line 150
static VALUE bit_fill(VALUE self, VALUE val) {
ndfunc_arg_in_t ain[2] = { { OVERWRITE, 0 }, { sym_option } };
ndfunc_t ndf = { iter_bit_fill, FULL_LOOP, 2, 0, ain, 0 };
na_ndloop(&ndf, 2, self, val);
return self;
}
|
#format(format) ⇒ Numo::RObject
Format elements into strings.
200 201 202 203 204 205 206 207 |
# File 'ext/numo/narray/src/t_bit.c', line 200
static VALUE bit_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_bit_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.
242 243 244 245 246 247 248 249 |
# File 'ext/numo/narray/src/t_bit.c', line 242
static VALUE bit_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 } };
ndfunc_t ndf = { iter_bit_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);
}
|
#inspect ⇒ String
Returns a string containing a human-readable representation of NArray.
257 258 259 |
# File 'ext/numo/narray/src/t_bit.c', line 257 static VALUE bit_inspect(VALUE ary) { return na_ndloop_inspect(ary, iter_bit_inspect, Qnil); } |
#mask(val) ⇒ Object
3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 |
# File 'ext/numo/narray/src/t_bit.c', line 3068
static VALUE bit_mask(VALUE mask, VALUE val) {
int i;
VALUE idx_1, view;
narray_data_t* nidx;
narray_view_t *nv, *nv_val;
narray_t *na, *na_mask;
stridx_t stridx0;
size_t n_1;
where_opt_t g;
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { Qnil, 0 } };
ndfunc_t ndf = { iter_bit_mask, FULL_LOOP, 2, 0, ain, 0 };
// cast val to NArray
if (!rb_obj_is_kind_of(val, numo_cNArray)) {
val = rb_funcall(numo_cNArray, id_cast, 1, val);
}
// shapes of mask and val must be same
GetNArray(val, na);
GetNArray(mask, na_mask);
if (na_mask->ndim != na->ndim) {
shape_error();
}
for (i = 0; i < na->ndim; i++) {
if (na_mask->shape[i] != na->shape[i]) {
shape_error();
}
}
n_1 = NUM2SIZET(bit_count_true(0, NULL, mask));
idx_1 = nary_new(cIndex, 1, &n_1);
g.count = 0;
g.elmsz = SIZEOF_VOIDP;
g.idx1 = na_get_pointer_for_write(idx_1);
g.idx0 = NULL;
na_ndloop3(&ndf, &g, 2, mask, val);
view = na_s_allocate_view(rb_obj_class(val));
GetNArrayView(view, nv);
na_setup_shape((narray_t*)nv, 1, &n_1);
GetNArrayData(idx_1, nidx);
SDX_SET_INDEX(stridx0, (size_t*)nidx->ptr);
nidx->ptr = NULL;
RB_GC_GUARD(idx_1);
nv->stridx = ALLOC_N(stridx_t, 1);
nv->stridx[0] = stridx0;
nv->offset = 0;
switch (NA_TYPE(na)) {
case NARRAY_DATA_T:
nv->data = val;
break;
case NARRAY_VIEW_T:
GetNArrayView(val, nv_val);
nv->data = nv_val->data;
break;
default:
rb_raise(rb_eRuntimeError, "invalid NA_TYPE: %d", NA_TYPE(na));
}
return view;
}
|
#mean(axis: nil, keepdims: false, nan: false) ⇒ Numo::DFloat
mean of self.
356 357 358 359 360 361 362 363 |
# File 'ext/numo/narray/src/t_bit.c', line 356
static VALUE bit_mean(int argc, VALUE* argv, VALUE self) {
ndfunc_arg_in_t ain[2] = { { numo_cBit, 0 }, { sym_reduce, 0 } };
ndfunc_arg_out_t aout[1] = { { numo_cDFloat, 0 } };
ndfunc_t ndf = { iter_bit_mean, STRIDE_LOOP_NIP | NDF_FLAT_REDUCE, 2, 1, ain, aout };
VALUE reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, 0);
VALUE v = na_ndloop(&ndf, 2, self, reduce);
return rb_funcall(v, rb_intern("extract"), 0);
}
|
#none?(*args) ⇒ Boolean
2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 |
# File 'ext/numo/narray/src/t_bit.c', line 2799
static VALUE bit_none_p(int argc, VALUE* argv, VALUE self) {
VALUE v;
v = bit_any_p(argc, argv, self);
if (v == Qtrue) {
return Qfalse;
} else if (v == Qfalse) {
return Qtrue;
}
return bit_not(v);
}
|
#rms(axis: nil, keepdims: false, nan: false) ⇒ Numo::DFloat
rms of self.
428 429 430 431 432 433 434 435 |
# File 'ext/numo/narray/src/t_bit.c', line 428
static VALUE bit_rms(int argc, VALUE* argv, VALUE self) {
ndfunc_arg_in_t ain[2] = { { numo_cBit, 0 }, { sym_reduce, 0 } };
ndfunc_arg_out_t aout[1] = { { numo_cDFloat, 0 } };
ndfunc_t ndf = { iter_bit_rms, STRIDE_LOOP_NIP | NDF_FLAT_REDUCE, 2, 1, ain, aout };
VALUE reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, 0);
VALUE v = na_ndloop(&ndf, 2, self, reduce);
return rb_funcall(v, rb_intern("extract"), 0);
}
|
#stddev(axis: nil, keepdims: false, nan: false) ⇒ Numo::DFloat
stddev of self.
404 405 406 407 408 409 410 411 |
# File 'ext/numo/narray/src/t_bit.c', line 404
static VALUE bit_stddev(int argc, VALUE* argv, VALUE self) {
ndfunc_arg_in_t ain[2] = { { numo_cBit, 0 }, { sym_reduce, 0 } };
ndfunc_arg_out_t aout[1] = { { numo_cDFloat, 0 } };
ndfunc_t ndf = { iter_bit_stddev, STRIDE_LOOP_NIP | NDF_FLAT_REDUCE, 2, 1, ain, aout };
VALUE reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, 0);
VALUE v = na_ndloop(&ndf, 2, self, reduce);
return rb_funcall(v, rb_intern("extract"), 0);
}
|
#store(obj) ⇒ Object
1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 |
# File 'ext/numo/narray/src/t_bit.c', line 1365
static VALUE bit_store(VALUE self, VALUE obj) {
VALUE r, klass;
klass = rb_obj_class(obj);
if (klass == numo_cBit) {
bit_store_bit(self, obj);
return self;
}
if (IS_INTEGER_CLASS(klass) || klass == rb_cFloat || klass == rb_cComplex) {
bit_store_numeric(self, obj);
return self;
}
if (klass == numo_cDFloat) {
bit_store_dfloat(self, obj);
return self;
}
if (klass == numo_cSFloat) {
bit_store_sfloat(self, obj);
return self;
}
if (klass == numo_cInt64) {
bit_store_int64(self, obj);
return self;
}
if (klass == numo_cInt32) {
bit_store_int32(self, obj);
return self;
}
if (klass == numo_cInt16) {
bit_store_int16(self, obj);
return self;
}
if (klass == numo_cInt8) {
bit_store_int8(self, obj);
return self;
}
if (klass == numo_cUInt64) {
bit_store_uint64(self, obj);
return self;
}
if (klass == numo_cUInt32) {
bit_store_uint32(self, obj);
return self;
}
if (klass == numo_cUInt16) {
bit_store_uint16(self, obj);
return self;
}
if (klass == numo_cUInt8) {
bit_store_uint8(self, obj);
return self;
}
if (klass == numo_cRObject) {
bit_store_robject(self, obj);
return self;
}
if (klass == rb_cArray) {
bit_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) {
bit_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;
}
|
#to_a ⇒ Array
Convert self to Array.
92 93 94 95 96 97 |
# File 'ext/numo/narray/src/t_bit.c', line 92
static VALUE bit_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 } };
ndfunc_t ndf = { iter_bit_to_a, FULL_LOOP_NIP, 3, 1, ain, aout };
return na_ndloop_cast_narray_to_rarray(&ndf, self, Qnil);
}
|
#var(axis: nil, keepdims: false, nan: false) ⇒ Numo::DFloat
var of self.
380 381 382 383 384 385 386 387 |
# File 'ext/numo/narray/src/t_bit.c', line 380
static VALUE bit_var(int argc, VALUE* argv, VALUE self) {
ndfunc_arg_in_t ain[2] = { { numo_cBit, 0 }, { sym_reduce, 0 } };
ndfunc_arg_out_t aout[1] = { { numo_cDFloat, 0 } };
ndfunc_t ndf = { iter_bit_var, STRIDE_LOOP_NIP | NDF_FLAT_REDUCE, 2, 1, ain, aout };
VALUE reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, 0);
VALUE v = na_ndloop(&ndf, 2, self, reduce);
return rb_funcall(v, rb_intern("extract"), 0);
}
|
#where ⇒ Object
2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 |
# File 'ext/numo/narray/src/t_bit.c', line 2869
static VALUE bit_where(VALUE self) {
volatile VALUE idx_1;
size_t size, n_1;
where_opt_t* g;
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
ndfunc_t ndf = { iter_bit_where, FULL_LOOP, 1, 0, ain, 0 };
size = RNARRAY_SIZE(self);
n_1 = NUM2SIZET(bit_count_true(0, NULL, self));
g = ALLOCA_N(where_opt_t, 1);
g->count = 0;
if (size > 4294967295ul) {
idx_1 = nary_new(numo_cInt64, 1, &n_1);
g->elmsz = 8;
} else {
idx_1 = nary_new(numo_cInt32, 1, &n_1);
g->elmsz = 4;
}
g->idx1 = na_get_pointer_for_write(idx_1);
g->idx0 = NULL;
na_ndloop3(&ndf, g, 1, self);
na_release_lock(idx_1);
return idx_1;
}
|
#where2 ⇒ Object
2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 |
# File 'ext/numo/narray/src/t_bit.c', line 2953
static VALUE bit_where2(VALUE self) {
VALUE idx_1, idx_0;
size_t size, n_1, n_0;
where_opt_t* g;
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
ndfunc_t ndf = { iter_bit_where2, FULL_LOOP, 1, 0, ain, 0 };
size = RNARRAY_SIZE(self);
n_1 = NUM2SIZET(bit_count_true(0, NULL, self));
n_0 = size - n_1;
g = ALLOCA_N(where_opt_t, 1);
g->count = 0;
if (size > 4294967295ul) {
idx_1 = nary_new(numo_cInt64, 1, &n_1);
idx_0 = nary_new(numo_cInt64, 1, &n_0);
g->elmsz = 8;
} else {
idx_1 = nary_new(numo_cInt32, 1, &n_1);
idx_0 = nary_new(numo_cInt32, 1, &n_0);
g->elmsz = 4;
}
g->idx1 = na_get_pointer_for_write(idx_1);
g->idx0 = na_get_pointer_for_write(idx_0);
na_ndloop3(&ndf, g, 1, self);
na_release_lock(idx_0);
na_release_lock(idx_1);
return rb_assoc_new(idx_1, idx_0);
}
|
#|(other) ⇒ Object
2102 2103 2104 2105 2106 2107 2108 |
# File 'ext/numo/narray/src/t_bit.c', line 2102
static VALUE bit_or(VALUE self, VALUE other) {
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
ndfunc_t ndf = { iter_bit_or, FULL_LOOP, 2, 1, ain, aout };
return na_ndloop(&ndf, 2, self, other);
}
|
#~ ⇒ Object
1844 1845 1846 1847 1848 1849 1850 |
# File 'ext/numo/narray/src/t_bit.c', line 1844
static VALUE bit_not(VALUE self) {
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
ndfunc_t ndf = { iter_bit_not, FULL_LOOP, 1, 1, ain, aout };
return na_ndloop(&ndf, 1, self);
}
|