Class: Numo::Bit
Defined Under Namespace
Modules: Math
Constant Summary
collapse
- 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, #coerce, #column_major?, debug=, #debug_info, #diagonal, #dot, #expand_dims, eye, #flatten, from_string, #host_order?, #initialize, #initialize_copy, #inplace, #inplace!, #inplace?, #ndim, ones, #out_of_place!, profile, profile=, #reshape, #reverse, #row_major?, #shape, #size, #slice, step, #swap_byte, #to_host, #to_network, #to_string, #to_swapped, #to_vacs, #transpose, upcast, #view, zeros
Constructor Details
This class inherits a constructor from Numo::NArray
Class Method Details
.[](obj) ⇒ Object
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
# File 'ext/numo/narray/gen/bit.erb.c', line 105
static VALUE
numo_bit_s_cast(VALUE type, VALUE obj)
{
VALUE r;
if (CLASS_OF(obj)==cT) {
return obj;
} else if (TYPE(obj)==T_ARRAY) {
return numo_cast_array_to_bit(obj);
} else if (TYPE(obj)==T_FLOAT || FIXNUM_P(obj) || TYPE(obj)==T_BIGNUM) {
return numo_bit_cast_numeric(obj);
}
if (IsNArray(obj)) {
r = rb_funcall(obj, rb_intern("coerce_cast"), 1, cT);
if (RTEST(r)) {
return r;
}
}
rb_raise(nary_eCastError, "unknown conversion from %s to %s",
rb_class2name(CLASS_OF(obj)),
rb_class2name(type));
return Qnil;
}
|
.cast(obj) ⇒ Object
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
# File 'ext/numo/narray/gen/bit.erb.c', line 105
static VALUE
numo_bit_s_cast(VALUE type, VALUE obj)
{
VALUE r;
if (CLASS_OF(obj)==cT) {
return obj;
} else if (TYPE(obj)==T_ARRAY) {
return numo_cast_array_to_bit(obj);
} else if (TYPE(obj)==T_FLOAT || FIXNUM_P(obj) || TYPE(obj)==T_BIGNUM) {
return numo_bit_cast_numeric(obj);
}
if (IsNArray(obj)) {
r = rb_funcall(obj, rb_intern("coerce_cast"), 1, cT);
if (RTEST(r)) {
return r;
}
}
rb_raise(nary_eCastError, "unknown conversion from %s to %s",
rb_class2name(CLASS_OF(obj)),
rb_class2name(type));
return Qnil;
}
|
Instance Method Details
#[]=(*args) ⇒ Object
method: []=(idx1,idx2,…,idxN,val)
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
|
# File 'ext/numo/narray/gen/bit.erb.c', line 483
static VALUE
numo_bit_aset(int argc, VALUE *argv, VALUE self)
{
VALUE a;
argc--;
if (argc==0)
numo_bit_store(self, argv[argc]);
else {
//a = na_aref(argc, argv, self);
a = rb_funcall2(self, rb_intern("[]"), argc, argv);
numo_bit_store(a, argv[argc]);
}
return argv[argc];
}
|
#all? ⇒ Boolean
743
744
745
746
747
|
# File 'ext/numo/narray/gen/bit.erb.c', line 743
VALUE
numo_bit_all_p(VALUE self)
{
return (rb_funcall(self, rb_intern("count_false"), 0)==INT2FIX(0)) ? Qtrue : Qfalse;
}
|
#allocate ⇒ Object
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'ext/numo/narray/gen/bit.erb.c', line 42
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)/sizeof(BIT_DIGIT)+1)*sizeof(BIT_DIGIT)/8);
NA_DATA_PTR(na) = ptr;
}
break;
case NARRAY_FILEMAP_T:
//ptr = ((narray_filemap_t*)na)->ptr;
// to be implemented
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? ⇒ Boolean
749
750
751
752
753
|
# File 'ext/numo/narray/gen/bit.erb.c', line 749
VALUE
numo_bit_any_p(VALUE self)
{
return (rb_funcall(self, rb_intern("count_true"), 0)!=INT2FIX(0)) ? Qtrue : Qfalse;
}
|
#coerce_cast(type) ⇒ Object
131
132
133
134
135
|
# File 'ext/numo/narray/gen/bit.erb.c', line 131
static VALUE
numo_bit_coerce_cast(VALUE value, VALUE type)
{
return Qnil;
}
|
#copy ⇒ Object
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
|
# File 'ext/numo/narray/gen/bit.erb.c', line 435
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(val) ⇒ Object
307
308
309
310
311
312
313
314
315
|
# File 'ext/numo/narray/gen/bit.erb.c', line 307
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;
}
|
197
198
199
200
201
202
203
204
205
206
207
|
# File 'ext/numo/narray/gen/bit.erb.c', line 197
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, 2, 1, ain, aout };
rb_scan_args(argc, argv, "01", &fmt);
return na_ndloop(&ndf, 2, self, fmt);
}
|
242
243
244
245
246
247
248
249
250
251
252
|
# File 'ext/numo/narray/gen/bit.erb.c', line 242
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, 3, 1, ain, aout };
rb_scan_args(argc, argv, "01", &fmt);
return na_ndloop_cast_narray_to_rarray(&ndf, self, fmt);
}
|
#inspect ⇒ Object
158
159
160
161
162
|
# File 'ext/numo/narray/gen/bit.erb.c', line 158
VALUE
numo_bit_inspect(VALUE ary)
{
return na_ndloop_inspect(ary, bit_inspect_element, Qnil);
}
|
#mask(val) ⇒ Object
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
|
# File 'ext/numo/narray/gen/bit.erb.c', line 707
static VALUE
numo_bit_mask(VALUE mask, VALUE val)
{
volatile VALUE idx_1, view;
narray_data_t *nidx;
narray_view_t *nv;
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 = NUM2SIZE(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;
nv->data = val;
return view;
}
|
#none? ⇒ Boolean
755
756
757
758
759
|
# File 'ext/numo/narray/gen/bit.erb.c', line 755
VALUE
numo_bit_none_p(VALUE self)
{
return (rb_funcall(self, rb_intern("count_true"), 0)==INT2FIX(0)) ? Qtrue : Qfalse;
}
|
#store ⇒ Object
#to_a ⇒ Object
349
350
351
352
353
354
355
356
|
# File 'ext/numo/narray/gen/bit.erb.c', line 349
static VALUE
numo_bit_cast_to_rarray(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 = { bit_cast_to_robj, FULL_LOOP, 3, 1, ain, aout };
return na_ndloop_cast_narray_to_rarray(&ndf, self, Qnil);
}
|
#where ⇒ Object
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
|
# File 'ext/numo/narray/gen/bit.erb.c', line 570
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 = NUM2SIZE(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;
}
|
#where2 ⇒ Object
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
|
# File 'ext/numo/narray/gen/bit.erb.c', line 598
static VALUE
numo_bit_where2(VALUE self)
{
VALUE idx_1, idx_0;
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 = NUM2SIZE(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);
idx_0 = rb_narray_new(numo_cInt64, 1, &n_1);
g->elmsz = 8;
} else {
idx_1 = rb_narray_new(numo_cInt32, 1, &n_1);
idx_0 = rb_narray_new(numo_cInt32, 1, &n_1);
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);
}
|