Class: Numo::Bit

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

Constant Summary

UPCAST =
hCast
ELEMENT_BIT_SIZE =
INT2FIX(1)
ELEMENT_BYTE_SIZE =
rb_float_new(1.0/8)
CONTIGUOUS_STRIDE =
INT2FIX(1)

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?, debug=, #debug_info, #deg2rad, #delete, #diagonal, #diff, #dot, #dsplit, dstack, #empty?, #expand_dims, eye, #flatten, #fliplr, #flipud, from_binary, #host_order?, #hsplit, hstack, #initialize, #initialize_copy, #inplace, #inplace!, #inplace?, #insert, inspect_cols, inspect_cols=, inspect_rows, inspect_rows=, linspace, logspace, #marshal_dump, #marshal_load, #ndim, #new_fill, new_like, #new_narray, #new_ones, #new_zeros, ones, #out_of_place!, profile, profile=, #rad2deg, #repeat, #reshape, #reverse, #rot90, #row_major?, #shape, #size, #split, srand, #store_binary, #swap_byte, #swapaxes, #tile, #to_binary, #to_c, #to_f, #to_host, #to_i, #to_network, #to_swapped, #to_vacs, #transpose, upcast, #view, #vsplit, vstack, zeros

Constructor Details

This class inherits a constructor from Numo::NArray

Class Method Details

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

Cast object to Numo::Bit.

Parameters:

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

Returns:



1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
# File 'ext/numo/narray/types/bit.c', line 1295

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

    if (CLASS_OF(obj)==cT) {
        return obj;
    }
    if (RTEST(rb_obj_is_kind_of(obj,rb_cNumeric))) {
        x = m_num_to_data(obj);
        return 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;
    }
    
#line 41 "gen/tmpl/cast.c"
    rb_raise(nary_eCastError,"cannot cast to %s",rb_class2name(type));
    return Qnil;
    
}

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

Cast object to Numo::Bit.

Parameters:

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

Returns:



1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
# File 'ext/numo/narray/types/bit.c', line 1295

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

    if (CLASS_OF(obj)==cT) {
        return obj;
    }
    if (RTEST(rb_obj_is_kind_of(obj,rb_cNumeric))) {
        x = m_num_to_data(obj);
        return 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;
    }
    
#line 41 "gen/tmpl/cast.c"
    rb_raise(nary_eCastError,"cannot cast to %s",rb_class2name(type));
    return Qnil;
    
}

Instance Method Details

#&(other) ⇒ Numo::NArray

Binary and.

Parameters:

Returns:



2079
2080
2081
2082
2083
2084
2085
2086
2087
# File 'ext/numo/narray/types/bit.c', line 2079

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, NArray::Bit

Array element referenece or slice view. — Returns the element at dim0, dim1, … are Numeric indices for each dimension, or returns a NArray View as a sliced subarray if dim0, dim1, … includes other than Numeric index, e.g., Range or Array or true.

Examples:

a = Numo::DFloat.new(4,5).seq
=> Numo::DFloat#shape=[4,5]
[[0, 1, 2, 3, 4],
 [5, 6, 7, 8, 9],
 [10, 11, 12, 13, 14],
 [15, 16, 17, 18, 19]]

a[1,1]
=> 6.0

a[1..3,1]
=> Numo::DFloat#shape=[3]
[6, 11, 16]

a[1,[1,3,4]]
=> Numo::DFloat#shape=[3]
[6, 8, 9]

a[true,2].fill(99)
a
=> Numo::DFloat#shape=[4,5]
[[0, 1, 99, 3, 4],
 [5, 6, 99, 8, 9],
 [10, 11, 99, 13, 14],
 [15, 16, 99, 18, 19]]

Parameters:

  • dim0,...,dimL (Numeric, Range, etc)

    Multi-dimensional Index.

Returns:

  • (Numeric, NArray::Bit)

    Element object or NArray view.



1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
# File 'ext/numo/narray/types/bit.c', line 1367

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

    nd = na_get_result_dimension(self, argc, argv, 1, &pos);
    if (nd) {
        return na_aref_main(argc, argv, self, 0, nd);
    } else {
        ptr = na_get_pointer_for_read(self);
        LOAD_BIT(ptr,pos,x);
        return m_data_to_num(x);
    }
}

#[]=(dim0, .., dimL, val) ⇒ Numeric

Array element(s) set. — Replace element(s) at dim0, dim1, … (index/range/array/true for each dimention). Broadcasting mechanism is applied.

Examples:

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

a[1,2]=99
a
=> Numo::DFloat#shape=[3,4]
[[0, 1, 2, 3],
 [4, 5, 99, 7],
 [8, 9, 10, 11]]

a[1,[0,2]] = [101,102]
a
=> Numo::DFloat#shape=[3,4]
[[0, 1, 2, 3],
 [101, 5, 102, 7],
 [8, 9, 10, 11]]

a[1,true]=99
a
=> Numo::DFloat#shape=[3,4]
[[0, 1, 2, 3],
 [99, 99, 99, 99],
 [8, 9, 10, 11]]

Parameters:

  • dim0,..,dimL (Numeric, Range, etc)

    Multi-dimensional Index.

  • val (Numeric, Numo::NArray, etc)

    Value(s) to be set to self.

Returns:

  • (Numeric)

    returns val (last argument).



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
# File 'ext/numo/narray/types/bit.c', line 1426

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

Binary xor.

Parameters:

Returns:



2273
2274
2275
2276
2277
2278
2279
2280
2281
# File 'ext/numo/narray/types/bit.c', line 2273

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?(axis: nil, keepdims: false) ⇒ Numo::Bit, Boolean

Return true if all of bits are one (true). If argument is supplied, return Bit-array reduced along the axes.

Parameters:

  • axis (Integer, Array, Range)

    (keyword) axes to be reduced.

  • keepdims (TrueClass)

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

Returns:



2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
# File 'ext/numo/narray/types/bit.c', line 2661

static VALUE
bit_all_p(int argc, VALUE *argv, VALUE self)
{
    VALUE v, reduce;
    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};

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

#allocateObject



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'ext/numo/narray/types/bit.c', line 129

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;
        }
        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?(axis: nil, keepdims: false) ⇒ Numo::Bit, Boolean

Return true if any of bits is one (true). If argument is supplied, return Bit-array reduced along the axes.

Parameters:

  • axis (Integer, Array, Range)

    (keyword) axes to be reduced.

  • keepdims (TrueClass)

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

Returns:



2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
# File 'ext/numo/narray/types/bit.c', line 2789

static VALUE
bit_any_p(int argc, VALUE *argv, VALUE self)
{
    VALUE v, reduce;
    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};

    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.

Returns:

  • (nil)


1460
1461
1462
1463
1464
# File 'ext/numo/narray/types/bit.c', line 1460

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

#copyNumo::Bit

Unary copy.

Returns:



1902
1903
1904
1905
1906
1907
1908
1909
1910
# File 'ext/numo/narray/types/bit.c', line 1902

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(axis: nil, keepdims: false) ⇒ Numo::Int64 Also known as: count_0

Returns the number of bits. If argument is supplied, return Int-array counted along the axes.

Parameters:

  • axis (Integer, Array, Range)

    (keyword) axes to be counted.

  • keepdims (TrueClass)

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

Returns:



2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
# File 'ext/numo/narray/types/bit.c', line 2545

static VALUE
bit_count_false(int argc, VALUE *argv, VALUE self)
{
    VALUE v, reduce;
    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 };

    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(axis: nil, keepdims: false) ⇒ Numo::Int64 Also known as: count_1, count

Returns the number of bits. If argument is supplied, return Int-array counted along the axes.

Parameters:

  • axis (Integer, Array, Range)

    (keyword) axes to be counted.

  • keepdims (TrueClass)

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

Returns:



2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
# File 'ext/numo/narray/types/bit.c', line 2455

static VALUE
bit_count_true(int argc, VALUE *argv, VALUE self)
{
    VALUE v, reduce;
    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 };

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

#eachNumo::NArray

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

Yields:

  • (x)

    x is element of NArray.

Returns:



1753
1754
1755
1756
1757
1758
1759
1760
1761
# File 'ext/numo/narray/types/bit.c', line 1753

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_indexNumo::NArray

Invokes the given block once for each element of self, passing that element and indices along each axis as parameters. For a block {|x,i,j,…| … }

Yields:

  • (x, i, j, ...)

    x is an element, i,j,… are multidimensional indices.

Returns:



1822
1823
1824
1825
1826
1827
1828
1829
1830
# File 'ext/numo/narray/types/bit.c', line 1822

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

Binary eq.

Parameters:

Returns:



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

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

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



164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'ext/numo/narray/types/bit.c', line 164

static VALUE
bit_extract(VALUE self)
{
    BIT_DIGIT *ptr, 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.

Parameters:

  • other (Numeric)

Returns:



1570
1571
1572
1573
1574
1575
1576
1577
1578
# File 'ext/numo/narray/types/bit.c', line 1570

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.

Parameters:

  • format (String)

Returns:



1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
# File 'ext/numo/narray/types/bit.c', line 1631

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.

Parameters:

  • format (String)

Returns:

  • (Array)

    array of formated strings.



1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
# File 'ext/numo/narray/types/bit.c', line 1683

static VALUE
bit_format_to_a(int argc, VALUE *argv, VALUE self)
{
    volatile VALUE fmt=Qnil;
    ndfunc_arg_in_t ain[3] = {{Qnil,0},{sym_loop_opt},{sym_option}};
    ndfunc_arg_out_t aout[1] = {{rb_cArray,0}}; // dummy?
    ndfunc_t ndf = {iter_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);
}

#inspectString

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

Returns:

  • (String)


1710
1711
1712
1713
1714
# File 'ext/numo/narray/types/bit.c', line 1710

VALUE
bit_inspect(VALUE ary)
{
    return na_ndloop_inspect(ary, iter_bit_inspect, Qnil);
}

#mask(array) ⇒ Numo::NArray

Return subarray of argument masked with self bit array.

Parameters:

Returns:



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
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
# File 'ext/numo/narray/types/bit.c', line 3099

static VALUE
bit_mask(VALUE mask, VALUE val)
{
    volatile VALUE idx_1, view;
    narray_data_t *nidx;
    narray_view_t *nv;
    narray_t      *na;
    narray_view_t *na1;
    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};

    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(CLASS_OF(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;

    nv->stridx = ALLOC_N(stridx_t,1);
    nv->stridx[0] = stridx0;
    nv->offset = 0;

    GetNArray(val, na);
    switch(NA_TYPE(na)) {
    case NARRAY_DATA_T:
        nv->data = val;
        break;
    case NARRAY_VIEW_T:
        GetNArrayView(val, na1);
        nv->data = na1->data;
        break;
    default:
        rb_raise(rb_eRuntimeError,"invalid NA_TYPE: %d",NA_TYPE(na));
    }

    return view;
}

#none?(*args) ⇒ Boolean

Returns:

  • (Boolean)


2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
# File 'ext/numo/narray/types/bit.c', line 2816

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

#store(other) ⇒ Numo::Bit

Store elements to Numo::Bit from other.

Parameters:

  • other (Object)

Returns:



1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
# File 'ext/numo/narray/types/bit.c', line 1043

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

    klass = CLASS_OF(obj);

    
    if (klass==numo_cBit) {
        bit_store_bit(self,obj);
        return self;
    }
    
#line 19 "gen/tmpl/store.c"
    if (IS_INTEGER_CLASS(klass) || klass==rb_cFloat || klass==rb_cComplex) {
        bit_store_numeric(self,obj);
        return self;
    }
    
#line 19 "gen/tmpl/store.c"
    if (klass==numo_cDFloat) {
        bit_store_dfloat(self,obj);
        return self;
    }
    
#line 19 "gen/tmpl/store.c"
    if (klass==numo_cSFloat) {
        bit_store_sfloat(self,obj);
        return self;
    }
    
#line 19 "gen/tmpl/store.c"
    if (klass==numo_cInt64) {
        bit_store_int64(self,obj);
        return self;
    }
    
#line 19 "gen/tmpl/store.c"
    if (klass==numo_cInt32) {
        bit_store_int32(self,obj);
        return self;
    }
    
#line 19 "gen/tmpl/store.c"
    if (klass==numo_cInt16) {
        bit_store_int16(self,obj);
        return self;
    }
    
#line 19 "gen/tmpl/store.c"
    if (klass==numo_cInt8) {
        bit_store_int8(self,obj);
        return self;
    }
    
#line 19 "gen/tmpl/store.c"
    if (klass==numo_cUInt64) {
        bit_store_uint64(self,obj);
        return self;
    }
    
#line 19 "gen/tmpl/store.c"
    if (klass==numo_cUInt32) {
        bit_store_uint32(self,obj);
        return self;
    }
    
#line 19 "gen/tmpl/store.c"
    if (klass==numo_cUInt16) {
        bit_store_uint16(self,obj);
        return self;
    }
    
#line 19 "gen/tmpl/store.c"
    if (klass==numo_cUInt8) {
        bit_store_uint8(self,obj);
        return self;
    }
    
#line 19 "gen/tmpl/store.c"
    if (klass==numo_cRObject) {
        bit_store_robject(self,obj);
        return self;
    }
    
#line 19 "gen/tmpl/store.c"
    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 (CLASS_OF(r)==cT) {
            bit_store(self,r);
            return self;
        }
    }

    
#line 36 "gen/tmpl/store.c"
    rb_raise(nary_eCastError, "unknown conversion from %s to %s",
             rb_class2name(CLASS_OF(obj)),
             rb_class2name(CLASS_OF(self)));
    
    return self;
}

#to_aArray

Convert self to Array.

Returns:

  • (Array)


1503
1504
1505
1506
1507
1508
1509
1510
# File 'ext/numo/narray/types/bit.c', line 1503

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}}; // dummy?
    ndfunc_t ndf = {iter_bit_to_a, FULL_LOOP_NIP, 3,1, ain,aout};
    return na_ndloop_cast_narray_to_rarray(&ndf, self, Qnil);
}

#whereNumo::Int32, Numo::Int64

Returns the array of index where the bit is one (true).

Returns:



2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
# File 'ext/numo/narray/types/bit.c', line 2892

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

#where2Numo::Int32, Numo::Int64

Returns two index arrays. The first array contains index where the bit is one (true). The second array contains index where the bit is zero (false).

Returns:



2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
# File 'ext/numo/narray/types/bit.c', line 2982

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

Binary or.

Parameters:

Returns:



2176
2177
2178
2179
2180
2181
2182
2183
2184
# File 'ext/numo/narray/types/bit.c', line 2176

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

#notNumo::Bit

Unary not.

Returns:



1982
1983
1984
1985
1986
1987
1988
1989
1990
# File 'ext/numo/narray/types/bit.c', line 1982

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