Class: Numo::Bit

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

Constant Summary collapse

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?, #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, profile, profile=, #rad2deg, #repeat, #reshape, #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, #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::Bit .cast(array) ⇒ Numo::Bit

Cast object to Numo::Bit.

Parameters:

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

Returns:



1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
# File 'ext/numo/narray/types/bit.c', line 1325

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;
    }
    
#line 41 "/home/masa/numo/numo-narray/ext/numo/narray/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:



1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
# File 'ext/numo/narray/types/bit.c', line 1325

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;
    }
    
#line 41 "/home/masa/numo/numo-narray/ext/numo/narray/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:



2143
2144
2145
2146
2147
2148
2149
2150
2151
# File 'ext/numo/narray/types/bit.c', line 2143

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.

Examples:

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

b = (a%2).eq(0)
# => Numo::Bit#shape=[3,4]
# [[1, 0, 1, 0],
#  [1, 0, 1, 0],
#  [1, 0, 1, 0]]

b[true,(0..-1)%2]
# => Numo::Bit(view)#shape=[3,2]
# [[1, 1],
#  [1, 1],
#  [1, 1]]

b[1,1]
# => 0

Parameters:

Returns:

  • (Numeric, Numo::Bit)

    an element or NArray view.

See Also:



1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
# File 'ext/numo/narray/types/bit.c', line 1389

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

Multi-dimensional element assignment.

Examples:

a = Numo::Bit.new(4,5).fill(0)
# => Numo::Bit#shape=[4,5]
# [[0, 0, 0, 0, 0],
#  [0, 0, 0, 0, 0],
#  [0, 0, 0, 0, 0],
#  [0, 0, 0, 0, 0]]

a[(0..-1)%2,(1..-1)%2] = 1
a
# => Numo::Bit#shape=[4,5]
# [[0, 1, 0, 1, 0],
#  [0, 0, 0, 0, 0],
#  [0, 1, 0, 1, 0],
#  [0, 0, 0, 0, 0]]

Parameters:

Returns:

  • (Numeric, Numo::NArray, Array)

    returns val (last argument).

See Also:



1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
# File 'ext/numo/narray/types/bit.c', line 1434

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:



2393
2394
2395
2396
2397
2398
2399
2400
2401
# File 'ext/numo/narray/types/bit.c', line 2393

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

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:



2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
# File 'ext/numo/narray/types/bit.c', line 2819

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

#allocateObject



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

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

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:



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

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.

Returns:

  • (nil)


1468
1469
1470
1471
1472
# File 'ext/numo/narray/types/bit.c', line 1468

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

#copyNumo::Bit

Unary copy.

Returns:



1924
1925
1926
1927
1928
1929
1930
1931
1932
# File 'ext/numo/narray/types/bit.c', line 1924

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:



2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
# File 'ext/numo/narray/types/bit.c', line 2698

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



2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
# File 'ext/numo/narray/types/bit.c', line 2603

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

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



1761
1762
1763
1764
1765
1766
1767
1768
1769
# File 'ext/numo/narray/types/bit.c', line 1761

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:



1830
1831
1832
1833
1834
1835
1836
1837
1838
# File 'ext/numo/narray/types/bit.c', line 1830

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:



2518
2519
2520
2521
2522
2523
2524
2525
2526
# File 'ext/numo/narray/types/bit.c', line 2518

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:



168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'ext/numo/narray/types/bit.c', line 168

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:



1578
1579
1580
1581
1582
1583
1584
1585
1586
# File 'ext/numo/narray/types/bit.c', line 1578

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:



1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
# File 'ext/numo/narray/types/bit.c', line 1639

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.



1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
# File 'ext/numo/narray/types/bit.c', line 1691

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


1718
1719
1720
1721
1722
# File 'ext/numo/narray/types/bit.c', line 1718

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



3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
# File 'ext/numo/narray/types/bit.c', line 3271

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

#none?(*args) ⇒ Boolean

Returns:

  • (Boolean)


2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
# File 'ext/numo/narray/types/bit.c', line 2984

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:



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
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
# File 'ext/numo/narray/types/bit.c', line 1073

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

    
#line 36 "/home/masa/numo/numo-narray/ext/numo/narray/gen/tmpl/store.c"
    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_aArray

Convert self to Array.

Returns:

  • (Array)


1511
1512
1513
1514
1515
1516
1517
1518
# File 'ext/numo/narray/types/bit.c', line 1511

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:



3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
# File 'ext/numo/narray/types/bit.c', line 3060

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:



3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
# File 'ext/numo/narray/types/bit.c', line 3150

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:



2268
2269
2270
2271
2272
2273
2274
2275
2276
# File 'ext/numo/narray/types/bit.c', line 2268

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:



2018
2019
2020
2021
2022
2023
2024
2025
2026
# File 'ext/numo/narray/types/bit.c', line 2018

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