Class: Numo::Bit

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

Constant Summary

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

Constants inherited from NArray

NArray::VERSION

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from NArray

#==, array_type, byte_size, #byte_size, #byte_swapped?, #cast_to, #check_axis, #coerce, #column_major?, concatenate, #concatenate, #contiguous?, debug=, #debug_info, #diagonal, #dot, #dsplit, dstack, #empty?, #expand_dims, eye, #flatten, from_binary, #host_order?, #hsplit, hstack, #initialize, #initialize_copy, #inplace, #inplace!, #inplace?, inspect_cols, inspect_cols=, inspect_rows, inspect_rows=, linspace, logspace, #marshal_dump, #marshal_load, #ndim, ones, #out_of_place!, profile, profile=, #repeat, #reshape, #reverse, #row_major?, #shape, #size, #split, srand, #store_binary, #swap_byte, #tile, #to_binary, #to_host, #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:



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

static VALUE
numo_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 numo_bit_new_dim0(x);
    }
    if (RTEST(rb_obj_is_kind_of(obj,rb_cArray))) {
        return numo_bit_cast_array(obj);
    }
    if (IsNArray(obj)) {
        GetNArray(obj,na);
        v = rb_narray_new(cT, NA_NDIM(na), NA_SHAPE(na));
        if (NA_SIZE(na) > 0) {
            numo_bit_allocate(v);
            numo_bit_store(v,obj);
        }
        return v;
    }
    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:



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

static VALUE
numo_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 numo_bit_new_dim0(x);
    }
    if (RTEST(rb_obj_is_kind_of(obj,rb_cArray))) {
        return numo_bit_cast_array(obj);
    }
    if (IsNArray(obj)) {
        GetNArray(obj,na);
        v = rb_narray_new(cT, NA_NDIM(na), NA_SHAPE(na));
        if (NA_SIZE(na) > 0) {
            numo_bit_allocate(v);
            numo_bit_store(v,obj);
        }
        return v;
    }
    rb_raise(nary_eCastError,"cannot cast to %s",rb_class2name(type));
    return Qnil;
}

Instance Method Details

#&(other) ⇒ Numo::NArray

Binary and.

Parameters:

Returns:



1898
1899
1900
1901
1902
1903
1904
1905
1906
# File 'ext/numo/narray/types/bit.c', line 1898

static VALUE
numo_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.



1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
# File 'ext/numo/narray/types/bit.c', line 1176

static VALUE
numo_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).



1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
# File 'ext/numo/narray/types/bit.c', line 1236

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

    argc--;
    if (argc==0) {
        numo_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);
            numo_bit_store(a, argv[argc]);
        } else {
            ptr = na_get_pointer_for_read_write(self);
            x = m_num_to_data(argv[argc]);
            STORE_BIT(ptr,pos,x);
        }

    }
    return argv[argc];
}

#^(other) ⇒ Numo::NArray

Binary xor.

Parameters:

Returns:



2094
2095
2096
2097
2098
2099
2100
2101
2102
# File 'ext/numo/narray/types/bit.c', line 2094

static VALUE
numo_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,..]) ⇒ 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)

    axes to be reduced.

Returns:



2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
# File 'ext/numo/narray/types/bit.c', line 2480

static VALUE
numo_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);
    v = na_ndloop(&ndf, 3, self, reduce, INT2FIX(1));
    if (argc > 0) {
        return v;
    }
    v = numo_bit_extract(v);
    switch (v) {
    case INT2FIX(0):
        return Qfalse;
    case INT2FIX(1):
        return Qtrue;
    default:
        rb_bug("unexpected result");
        return v;
    }
}

#allocateObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'ext/numo/narray/types/bit.c', line 36

static VALUE
numo_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_FILEMAP_T:
    // to be implemented
    //    ptr = ((narray_filemap_t*)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,..]) ⇒ 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)

    axes to be reduced.

Returns:



2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
# File 'ext/numo/narray/types/bit.c', line 2608

static VALUE
numo_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);
    v = na_ndloop(&ndf, 3, self, reduce, INT2FIX(0));
    if (argc > 0) {
        return v;
    }
    v = numo_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

Returns:

  • (nil)


1269
1270
1271
1272
1273
# File 'ext/numo/narray/types/bit.c', line 1269

static VALUE
numo_bit_coerce_cast(VALUE value, VALUE type)
{
    return Qnil;
}

#copyNumo::Bit

Unary copy.

Returns:



1719
1720
1721
1722
1723
1724
1725
1726
1727
# File 'ext/numo/narray/types/bit.c', line 1719

static VALUE
numo_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,..]) ⇒ 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)

    axes to be counted.

Returns:



2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
# File 'ext/numo/narray/types/bit.c', line 2365

static VALUE
numo_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);
    v = na_ndloop(&ndf, 3, self, reduce, INT2FIX(0));
    return rb_funcall(v,rb_intern("extract"),0);
}

#count_true([axis,..]) ⇒ 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)

    axes to be counted.

Returns:



2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
# File 'ext/numo/narray/types/bit.c', line 2277

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



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

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



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

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



2192
2193
2194
2195
2196
2197
2198
2199
2200
# File 'ext/numo/narray/types/bit.c', line 2192

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



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'ext/numo/narray/types/bit.c', line 76

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



1381
1382
1383
1384
1385
1386
1387
1388
1389
# File 'ext/numo/narray/types/bit.c', line 1381

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



1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
# File 'ext/numo/narray/types/bit.c', line 1443

static VALUE
numo_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.



1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
# File 'ext/numo/narray/types/bit.c', line 1496

static VALUE
numo_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)


1524
1525
1526
1527
1528
# File 'ext/numo/narray/types/bit.c', line 1524

VALUE
numo_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:



2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
# File 'ext/numo/narray/types/bit.c', line 2922

static VALUE
 numo_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_pointer, FULL_LOOP, 2, 0, ain, 0};

    n_1 = NUM2SIZET(numo_bit_count_true(0, NULL, mask));
    idx_1 = rb_narray_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)


2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
# File 'ext/numo/narray/types/bit.c', line 2636

VALUE
numo_bit_none_p(int argc, VALUE *argv, VALUE self)
{
    VALUE v;

    v = numo_bit_any_p(argc,argv,self);

    if (v==Qtrue) {
        return Qfalse;
    } else if (v==Qfalse) {
        return Qtrue;
    }
    return numo_bit_not(v);
}

#store(other) ⇒ Numo::Bit

Store elements to Numo::Bit from other.

Parameters:

  • other (Object)

Returns:



989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
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
# File 'ext/numo/narray/types/bit.c', line 989

static VALUE
numo_bit_store(VALUE self, VALUE obj)
{

    VALUE r;

    
    if (FIXNUM_P(obj) || TYPE(obj)==T_FLOAT || TYPE(obj)==T_BIGNUM || rb_obj_is_kind_of(obj,rb_cComplex)) {
        numo_bit_store_numeric(self,obj);
        return self;
    }
    
#line 14 "/home/masa/numo/narray/ext/numo/narray/gen/tmpl_bit/store.c"
    if (rb_obj_is_kind_of(obj,numo_cBit)) {
        numo_bit_store_bit(self,obj);
        return self;
    }
    
#line 14 "/home/masa/numo/narray/ext/numo/narray/gen/tmpl_bit/store.c"
    if (rb_obj_is_kind_of(obj,numo_cDFloat)) {
        numo_bit_store_dfloat(self,obj);
        return self;
    }
    
#line 14 "/home/masa/numo/narray/ext/numo/narray/gen/tmpl_bit/store.c"
    if (rb_obj_is_kind_of(obj,numo_cSFloat)) {
        numo_bit_store_sfloat(self,obj);
        return self;
    }
    
#line 14 "/home/masa/numo/narray/ext/numo/narray/gen/tmpl_bit/store.c"
    if (rb_obj_is_kind_of(obj,numo_cInt64)) {
        numo_bit_store_int64(self,obj);
        return self;
    }
    
#line 14 "/home/masa/numo/narray/ext/numo/narray/gen/tmpl_bit/store.c"
    if (rb_obj_is_kind_of(obj,numo_cInt32)) {
        numo_bit_store_int32(self,obj);
        return self;
    }
    
#line 14 "/home/masa/numo/narray/ext/numo/narray/gen/tmpl_bit/store.c"
    if (rb_obj_is_kind_of(obj,numo_cInt16)) {
        numo_bit_store_int16(self,obj);
        return self;
    }
    
#line 14 "/home/masa/numo/narray/ext/numo/narray/gen/tmpl_bit/store.c"
    if (rb_obj_is_kind_of(obj,numo_cInt8)) {
        numo_bit_store_int8(self,obj);
        return self;
    }
    
#line 14 "/home/masa/numo/narray/ext/numo/narray/gen/tmpl_bit/store.c"
    if (rb_obj_is_kind_of(obj,numo_cUInt64)) {
        numo_bit_store_uint64(self,obj);
        return self;
    }
    
#line 14 "/home/masa/numo/narray/ext/numo/narray/gen/tmpl_bit/store.c"
    if (rb_obj_is_kind_of(obj,numo_cUInt32)) {
        numo_bit_store_uint32(self,obj);
        return self;
    }
    
#line 14 "/home/masa/numo/narray/ext/numo/narray/gen/tmpl_bit/store.c"
    if (rb_obj_is_kind_of(obj,numo_cUInt16)) {
        numo_bit_store_uint16(self,obj);
        return self;
    }
    
#line 14 "/home/masa/numo/narray/ext/numo/narray/gen/tmpl_bit/store.c"
    if (rb_obj_is_kind_of(obj,numo_cUInt8)) {
        numo_bit_store_uint8(self,obj);
        return self;
    }
    
#line 14 "/home/masa/numo/narray/ext/numo/narray/gen/tmpl_bit/store.c"
    if (rb_obj_is_kind_of(obj,numo_cRObject)) {
        numo_bit_store_robject(self,obj);
        return self;
    }
    
#line 14 "/home/masa/numo/narray/ext/numo/narray/gen/tmpl_bit/store.c"
    if (TYPE(obj)==T_ARRAY) {
        numo_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) {
            numo_bit_store(self,r);
            return self;
        }
    }

    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)


1313
1314
1315
1316
1317
1318
1319
1320
# File 'ext/numo/narray/types/bit.c', line 1313

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



2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
# File 'ext/numo/narray/types/bit.c', line 2713

static VALUE
 numo_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(numo_bit_count_true(0, NULL, self));
    g = ALLOCA_N(where_opt_t,1);
    g->count = 0;
    if (size>4294967295ul) {
        idx_1 = rb_narray_new(numo_cInt64, 1, &n_1);
        g->elmsz = 8;
    } else {
        idx_1 = rb_narray_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:



2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
# File 'ext/numo/narray/types/bit.c', line 2804

static VALUE
numo_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(numo_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 = rb_narray_new(numo_cInt64, 1, &n_1);
        idx_0 = rb_narray_new(numo_cInt64, 1, &n_0);
        g->elmsz = 8;
    } else {
        idx_1 = rb_narray_new(numo_cInt32, 1, &n_1);
        idx_0 = rb_narray_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:



1996
1997
1998
1999
2000
2001
2002
2003
2004
# File 'ext/numo/narray/types/bit.c', line 1996

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



1800
1801
1802
1803
1804
1805
1806
1807
1808
# File 'ext/numo/narray/types/bit.c', line 1800

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