Class: NArray
- Inherits:
-
Object
- Object
- NArray
- Defined in:
- lib/narray_ext.rb,
ext/narray/narray.c
Overview
Numerical Array Extention for Ruby
(C) Copyright 2000-2008 by Masahiro TANAKA
This program is free software.
You can distribute/modify this program
under the same terms as Ruby itself.
NO WARRANTY.
Direct Known Subclasses
Constant Summary collapse
- NARRAY_VERSION =
rb_str_new2(NARRAY_VERSION)
- SUPPORT_BIGMEM =
Qtrue
- BYTE =
INT2FIX(NA_BYTE)
- SINT =
INT2FIX(NA_SINT)
- LINT =
INT2FIX(NA_LINT)
- LLINT =
INT2FIX(NA_LLINT)
- INT =
INT2FIX(NA_LINT)
- SFLOAT =
INT2FIX(NA_SFLOAT)
- DFLOAT =
INT2FIX(NA_DFLOAT)
- FLOAT =
INT2FIX(NA_DFLOAT)
- SCOMPLEX =
INT2FIX(NA_SCOMPLEX)
- DCOMPLEX =
INT2FIX(NA_DCOMPLEX)
- COMPLEX =
INT2FIX(NA_DCOMPLEX)
- ROBJ =
INT2FIX(NA_ROBJ)
- OBJECT =
INT2FIX(NA_ROBJ)
- NONE =
INT2FIX(NA_NONE)
- CLASS_DIMENSION =
INT2FIX(0)
- ENDIAN =
INT2FIX(0)
Class Method Summary collapse
-
.[](*args) ⇒ Object
singleton method: NArray.
-
.byte(*args) ⇒ Object
class method: byte(size1,size2,…,sizeN).
- .cast(array, type = nil) ⇒ Object
-
.complex(*args) ⇒ Object
class method: complex(size1,size2,…,sizeN).
-
.dcomplex(*args) ⇒ Object
class method: complex(size1,size2,…,sizeN).
-
.dfloat(*args) ⇒ Object
class method: float(size1,size2,…,sizeN).
-
.div(obj1, obj2) ⇒ Object
singleton method: NArray.div( obj1, obj2 ).
-
.float(*args) ⇒ Object
class method: float(size1,size2,…,sizeN).
-
.int(*args) ⇒ Object
class method: int(size1,size2,…,sizeN).
-
.lint(*args) ⇒ Object
class method: int(size1,size2,…,sizeN).
-
.llint(*args) ⇒ Object
class method: llint(size1,size2,…,sizeN).
-
.mul(obj1, obj2) ⇒ Object
singleton method: NArray.mul( obj1, obj2 ).
-
.mul_add(*args) ⇒ Object
singleton method: NArray.mul_add( obj1, obj2, rank, … ).
-
.new(*args) ⇒ Object
class method: new(type, size1,size2,…,sizeN).
-
.object(*args) ⇒ Object
class method: object(size1,size2,…,sizeN).
-
.ref(self) ⇒ Object
singleton method: NArray.refer( other ).
-
.refer(self) ⇒ Object
singleton method: NArray.refer( other ).
-
.scomplex(*args) ⇒ Object
class method: scomplex(size1,size2,…,sizeN).
-
.sfloat(*args) ⇒ Object
class method: sfloat(size1,size2,…,sizeN).
-
.sint(*args) ⇒ Object
class method: sint(size1,size2,…,sizeN).
- .srand(*args) ⇒ Object
-
.to_na(*args) ⇒ Object
singleton method: NArray.to_na( string, type, size1,size2,…,sizeN ) NArray.to_na( array ).
-
.to_narray(*args) ⇒ Object
singleton method: NArray.to_na( string, type, size1,size2,…,sizeN ) NArray.to_na( array ).
Instance Method Summary collapse
-
#%(obj2) ⇒ Object
(also: #mod)
method: self / other.
-
#&(obj2) ⇒ Object
method: self & other.
-
#*(obj2) ⇒ Object
method: self * other.
- #**(val2) ⇒ Object
-
#+(obj2) ⇒ Object
method: self + other.
-
#-(obj2) ⇒ Object
method: self - other.
-
#-@ ⇒ Object
method: -self.
-
#/(obj2) ⇒ Object
method: self / other.
-
#<=>(obj2) ⇒ Object
method: self <=> other.
- #==(other) ⇒ Object
-
#[](*args) ⇒ Object
method: [](idx1,idx2,…,idxN).
-
#[]=(*idx, self) ⇒ Object
method: []=(idx1,idx2,…,idxN,val).
-
#^(obj2) ⇒ Object
method: self ^ other.
-
#abs ⇒ Object
method: self.abs.
-
#accum(*args) ⇒ Object
method: accum( rank, … ).
-
#add!(obj2) ⇒ Object
method: self.add!(other).
- #all? ⇒ Boolean
-
#and(obj2) ⇒ Object
method: self.and other.
-
#angle ⇒ Object
(also: #arg)
method: self.imag.
- #any? ⇒ Boolean
-
#ceil ⇒ Object
method: self.ceil.
-
#clone ⇒ Object
(also: #dup)
method: dup().
-
#coerce(other) ⇒ Object
method: coerce(other).
-
#collect ⇒ Object
(also: #map)
iterator: collect().
-
#collect! ⇒ Object
(also: #map!)
iterator: collect!().
- #complex? ⇒ Boolean
-
#conj ⇒ Object
(also: #conjugate)
method: self.conj.
-
#conj! ⇒ Object
(also: #conjugate!)
method: self.conj!.
-
#count_false ⇒ Integer
Returns the number of false (zero-value) in narray.
-
#count_true ⇒ Integer
Returns the number of true (non-zero) in narray.
-
#cumprod ⇒ Object
cumprod.
-
#cumprod! ⇒ Object
cumprod! [1 2 3 4 5] -> [1 3 6 10 15].
-
#cumsum ⇒ Object
cumsum.
-
#cumsum! ⇒ Object
cumsum! [1 2 3 4 5] -> [1 3 6 10 15].
-
#delete_at(*args) ⇒ Object
delete rows/columns.
-
#div!(obj2) ⇒ Object
method: self.div!(other).
-
#each ⇒ Object
iterator: each().
-
#element_size ⇒ Object
method: element_size – returns the element size of the array type.
-
#empty? ⇒ Boolean
method: empty? – returns true if empty array.
-
#eq(obj2) ⇒ Object
method: self.eq(other).
- #eql?(other) ⇒ Boolean
-
#fill!(val) ⇒ Object
(also: #fill)
method: fill!(val).
-
#flatten ⇒ Object
method: flatten.
-
#flatten! ⇒ Object
method: flatten!.
-
#floor ⇒ Object
method: self.floor.
-
#ge(obj2) ⇒ Object
(also: #>=)
method: self >= other.
-
#gt(obj2) ⇒ Object
(also: #>)
method: self > other.
- #hash ⇒ Object
-
#hton ⇒ Object
(also: #ntoh)
method: self.hton , self.ntoh.
-
#htov ⇒ Object
(also: #vtoh)
method: self.htov , self.vtoh.
-
#im ⇒ Object
method: self.im.
-
#imag ⇒ Object
(also: #image)
method: self.imag.
- #imag=(obj2) ⇒ Object
-
#indgen!(*args) ⇒ Object
(also: #indgen)
method: indgen!([start,]).
-
#inspect ⇒ Object
method: inspect() – returns the inspect of the array.
- #integer? ⇒ Boolean
-
#le(obj2) ⇒ Object
(also: #<=)
method: self <= other.
-
#lt(obj2) ⇒ Object
(also: #<)
method: self < other.
-
#mask(mask) ⇒ Object
:nodoc:.
-
#max(*args) ⇒ Object
method: max( rank, … ).
-
#mean(*ranks) ⇒ Object
Statistics.
- #median(rank = nil) ⇒ Object
-
#min(*args) ⇒ Object
method: min( rank, … ).
-
#mod!(obj2) ⇒ Object
method: self.mod!(other).
-
#mul!(obj2) ⇒ Object
method: self.mul!(other).
-
#mul_accum(*args) ⇒ Object
method: mul_accum( other, rank, … ).
-
#mul_add(*args) ⇒ Object
method: mul_add( other, rank, … ).
-
#ne(obj2) ⇒ Object
method: self.ne(other).
-
#newdim(*args) ⇒ Object
(also: #newrank)
method: newdim(size1,size2,…,sizeN).
-
#newdim!(*args) ⇒ Object
(also: #newdim=, #newrank!, #newrank=)
method: newdim!(size1,size2,…,sizeN).
- #none? ⇒ Boolean
-
#not ⇒ Object
method: self.not.
-
#or(obj2) ⇒ Object
method: self.or other.
-
#original ⇒ Object
method: self.original.
-
#prod(*args) ⇒ Object
method: prod( rank, … ).
- #random(*args) ⇒ Object
- #random!(*args) ⇒ Object
-
#randomn ⇒ Object
Normal distributed random number; valid for floating point types.
-
#randomn! ⇒ Object
alias randomn! randomn.
-
#rank ⇒ Object
(also: #dim, #dimension)
method: rank() – returns the rank of the array.
- #rank_total(*ranks) ⇒ Object
-
#real ⇒ Object
method: self.real.
-
#recip ⇒ Object
method: self.recip.
-
#refer ⇒ Object
method: self.refer.
-
#reshape(*args) ⇒ Object
method: reshape(size1,size2,…,sizeN).
-
#reshape!(*args) ⇒ Object
(also: #shape=)
method: reshape!(size1,size2,…,sizeN).
- #reverse(*ranks) ⇒ Object
- #rms(*ranks) ⇒ Object
- #rmsdev(*ranks) ⇒ Object
- #rot90(n_times = 1) ⇒ Object
-
#round ⇒ Object
method: self.round.
-
#sbt!(obj2) ⇒ Object
method: self.sbt!(other).
-
#shape ⇒ Object
(also: #sizes)
method: shape() – returns an array of shape of each rank.
-
#size ⇒ Object
(also: #total, #length)
method: size() – returns the total number of elements.
-
#slice(*args) ⇒ Object
method: slice(idx1,idx2,…,idxN).
-
#sort(*args) ⇒ Object
method: sort().
-
#sort!(*args) ⇒ Object
method: sort!().
-
#sort_index(*args) ⇒ Object
method: sort_index().
- #stddev(*ranks) ⇒ Object
-
#sum(*args) ⇒ Object
method: sum( rank, … ).
-
#swap_byte ⇒ Object
method: self.swap_byte.
-
#to_a ⇒ Object
method: to_a – convert itself to Array.
-
#to_binary ⇒ Object
method: to_binary – convert the data contents to a BYTE type NArray.
-
#to_f ⇒ Object
method: to_f().
-
#to_i ⇒ Object
method: to_i().
-
#to_s ⇒ Object
method: to_s – convert the data contents to a binary string.
-
#to_string ⇒ Object
method: to_string.
-
#to_type(vtype) ⇒ Object
method: to_type(type).
-
#to_type_as_binary(vtype) ⇒ Object
method: to_type_as_binary(type).
-
#transpose(*args) ⇒ Object
method: self.transpose( … ).
-
#typecode ⇒ Object
method: typecode – returns the type of the array.
-
#where ⇒ Object
method: where idx_true = narray.where.
-
#where2 ⇒ Object
method: where2 idx_true, idx_false = narray.where2.
-
#xor(obj2) ⇒ Object
method: self.xor other.
-
#|(obj2) ⇒ Object
method: self | other.
-
#~ ⇒ Object
method: ~self.
Class Method Details
.[](*args) ⇒ Object
singleton method:
NArray[object]
782 783 784 785 786 787 |
# File 'ext/narray/narray.c', line 782
static VALUE
na_s_bracket(int argc, VALUE *argv, VALUE klass)
{
VALUE v = rb_ary_new4(argc, argv);
return na_ary_to_nary( v, klass );
}
|
.byte(*args) ⇒ Object
class method: byte(size1,size2,…,sizeN)
412 413 414 |
# File 'ext/narray/narray.c', line 412
static VALUE
na_s_new_byte(int argc, VALUE *argv, VALUE klass)
{ return na_new2(argc, argv, NA_BYTE, klass); }
|
.cast(array, type = nil) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/narray_ext.rb', line 11 def self.cast(array,type=nil) case array when NArray when Array array = NArray.to_na(array) else raise ArgumentError, "1st argument must be NArray or Array" end type = array.typecode if type.nil? shape = array.shape na = self.new(type,*shape) na[] = array na end |
.complex(*args) ⇒ Object
class method: complex(size1,size2,…,sizeN)
447 448 449 |
# File 'ext/narray/narray.c', line 447
static VALUE
na_s_new_complex(int argc, VALUE *argv, VALUE klass)
{ return na_new2(argc, argv, NA_DCOMPLEX, klass); }
|
.dcomplex(*args) ⇒ Object
class method: complex(size1,size2,…,sizeN)
447 448 449 |
# File 'ext/narray/narray.c', line 447
static VALUE
na_s_new_complex(int argc, VALUE *argv, VALUE klass)
{ return na_new2(argc, argv, NA_DCOMPLEX, klass); }
|
.dfloat(*args) ⇒ Object
class method: float(size1,size2,…,sizeN)
437 438 439 |
# File 'ext/narray/narray.c', line 437
static VALUE
na_s_new_float(int argc, VALUE *argv, VALUE klass)
{ return na_new2(argc, argv, NA_DFLOAT, klass); }
|
.div(obj1, obj2) ⇒ Object
singleton method: NArray.div( obj1, obj2 )
786 787 788 |
# File 'ext/narray/na_func.c', line 786
static VALUE
na_s_div(VALUE klass, VALUE obj1, VALUE obj2)
{ return na_bifunc( obj1, obj2, klass, DivBFuncs ); }
|
.float(*args) ⇒ Object
class method: float(size1,size2,…,sizeN)
437 438 439 |
# File 'ext/narray/narray.c', line 437
static VALUE
na_s_new_float(int argc, VALUE *argv, VALUE klass)
{ return na_new2(argc, argv, NA_DFLOAT, klass); }
|
.int(*args) ⇒ Object
class method: int(size1,size2,…,sizeN)
422 423 424 |
# File 'ext/narray/narray.c', line 422
static VALUE
na_s_new_int(int argc, VALUE *argv, VALUE klass)
{ return na_new2(argc, argv, NA_LINT, klass); }
|
.lint(*args) ⇒ Object
class method: int(size1,size2,…,sizeN)
422 423 424 |
# File 'ext/narray/narray.c', line 422
static VALUE
na_s_new_int(int argc, VALUE *argv, VALUE klass)
{ return na_new2(argc, argv, NA_LINT, klass); }
|
.llint(*args) ⇒ Object
class method: llint(size1,size2,…,sizeN)
427 428 429 |
# File 'ext/narray/narray.c', line 427
static VALUE
na_s_new_llint(int argc, VALUE *argv, VALUE klass)
{ return na_new2(argc, argv, NA_LLINT, klass); }
|
.mul(obj1, obj2) ⇒ Object
singleton method: NArray.mul( obj1, obj2 )
781 782 783 |
# File 'ext/narray/na_func.c', line 781
static VALUE
na_s_mul(VALUE klass, VALUE obj1, VALUE obj2)
{ return na_bifunc( obj1, obj2, klass, MulBFuncs ); }
|
.mul_add(*args) ⇒ Object
singleton method: NArray.mul_add( obj1, obj2, rank, … )
1348 1349 1350 1351 1352 1353 1354 |
# File 'ext/narray/na_func.c', line 1348
static VALUE
na_s_mul_add(int argc, VALUE *argv, VALUE klass)
{
if (argc<3)
rb_raise(rb_eArgError, "wrong # of arguments (%d for >=3)", argc);
return na_mul_add_body(argc-2,argv+2,argv[0],argv[1],klass,0);
}
|
.new(*args) ⇒ Object
class method: new(type, size1,size2,…,sizeN)
403 404 405 406 407 408 409 |
# File 'ext/narray/narray.c', line 403
static VALUE
na_s_new(int argc, VALUE *argv, VALUE klass)
{
if (argc == 0)
rb_raise(rb_eArgError, "Argument required");
return na_new2(argc-1, argv+1, na_get_typecode(argv[0]), klass);
}
|
.object(*args) ⇒ Object
class method: object(size1,size2,…,sizeN)
452 453 454 |
# File 'ext/narray/narray.c', line 452
static VALUE
na_s_new_object(int argc, VALUE *argv, VALUE klass)
{ return na_new2(argc, argv, NA_ROBJ, klass); }
|
.ref(self) ⇒ Object
singleton method: NArray.refer( other )
317 318 319 320 321 |
# File 'ext/narray/narray.c', line 317
static VALUE
na_s_refer(VALUE klass, VALUE self)
{
return na_wrap_struct_class(na_ref_alloc_struct(self), klass);
}
|
.refer(self) ⇒ Object
singleton method: NArray.refer( other )
317 318 319 320 321 |
# File 'ext/narray/narray.c', line 317
static VALUE
na_s_refer(VALUE klass, VALUE self)
{
return na_wrap_struct_class(na_ref_alloc_struct(self), klass);
}
|
.scomplex(*args) ⇒ Object
class method: scomplex(size1,size2,…,sizeN)
442 443 444 |
# File 'ext/narray/narray.c', line 442
static VALUE
na_s_new_scomplex(int argc, VALUE *argv, VALUE klass)
{ return na_new2(argc, argv, NA_SCOMPLEX, klass); }
|
.sfloat(*args) ⇒ Object
class method: sfloat(size1,size2,…,sizeN)
432 433 434 |
# File 'ext/narray/narray.c', line 432
static VALUE
na_s_new_sfloat(int argc, VALUE *argv, VALUE klass)
{ return na_new2(argc, argv, NA_SFLOAT, klass); }
|
.sint(*args) ⇒ Object
class method: sint(size1,size2,…,sizeN)
417 418 419 |
# File 'ext/narray/narray.c', line 417
static VALUE
na_s_new_sint(int argc, VALUE *argv, VALUE klass)
{ return na_new2(argc, argv, NA_SINT, klass); }
|
.srand(*args) ⇒ Object
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'ext/narray/na_random.c', line 158
static VALUE
na_s_srand(int argc, VALUE *argv, VALUE obj)
{
VALUE sd;
u_int32_t seed, old;
rb_secure(4);
if (rb_scan_args(argc, argv, "01", &sd) == 0) {
seed = random_seed();
}
else {
seed = NUM2ULONG(sd);
}
old = rand_init(seed);
return ULONG2NUM(old);
}
|
.to_na(*args) ⇒ Object
singleton method:
NArray.to_na( string, type, size1,size2,...,sizeN )
NArray.to_na( array )
756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 |
# File 'ext/narray/narray.c', line 756
static VALUE
na_s_to_na(int argc, VALUE *argv, VALUE klass)
{
if (argc < 1) {
rb_raise(rb_eArgError, "Argument is required");
}
if (TYPE(argv[0]) == T_STRING) {
return na_str_to_na(argc-1,argv+1,argv[0]);
}
if (argc > 1) {
rb_raise(rb_eArgError, "Only one array argument must be provided");
}
if (TYPE(argv[0]) == T_ARRAY) {
return na_ary_to_nary( argv[0], klass );
}
if (NA_IsNArray(argv[0])) {
return argv[0];
}
rb_raise(rb_eTypeError, "Argument must be Array or String (or NArray)");
return Qnil;
}
|
.to_narray(*args) ⇒ Object
singleton method:
NArray.to_na( string, type, size1,size2,...,sizeN )
NArray.to_na( array )
756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 |
# File 'ext/narray/narray.c', line 756
static VALUE
na_s_to_na(int argc, VALUE *argv, VALUE klass)
{
if (argc < 1) {
rb_raise(rb_eArgError, "Argument is required");
}
if (TYPE(argv[0]) == T_STRING) {
return na_str_to_na(argc-1,argv+1,argv[0]);
}
if (argc > 1) {
rb_raise(rb_eArgError, "Only one array argument must be provided");
}
if (TYPE(argv[0]) == T_ARRAY) {
return na_ary_to_nary( argv[0], klass );
}
if (NA_IsNArray(argv[0])) {
return argv[0];
}
rb_raise(rb_eTypeError, "Argument must be Array or String (or NArray)");
return Qnil;
}
|
Instance Method Details
#%(obj2) ⇒ Object Also known as: mod
method: self / other
727 728 |
# File 'ext/narray/na_func.c', line 727
static VALUE na_mod(VALUE obj1, VALUE obj2)
{ return na_bifunc( obj1, obj2, Qnil, ModBFuncs ); }
|
#&(obj2) ⇒ Object
method: self & other
731 732 |
# File 'ext/narray/na_func.c', line 731
static VALUE na_bit_and(VALUE obj1, VALUE obj2)
{ return na_bifunc( obj1, obj2, Qnil, BAnFuncs ); }
|
#*(obj2) ⇒ Object
method: self * other
719 720 |
# File 'ext/narray/na_func.c', line 719
static VALUE na_mul(VALUE obj1, VALUE obj2)
{ return na_bifunc( obj1, obj2, Qnil, MulBFuncs ); }
|
#**(val2) ⇒ Object
611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 |
# File 'ext/narray/na_func.c', line 611
static VALUE
na_power(VALUE val1, VALUE val2)
{
volatile VALUE obj1, obj2, obj3;
struct NARRAY *a1, *a2;
obj1 = val1;
obj2 = val2;
GetNArray(obj1,a1);
obj2 = na_to_narray(obj2);
GetNArray(obj2,a2);
if (a1->type==NA_ROBJ && a2->type!=NA_ROBJ) {
obj2 = na_change_type(obj2,NA_ROBJ);
GetNArray(obj2,a2);
} else
if (a2->type==NA_ROBJ && a1->type!=NA_ROBJ) {
obj1 = na_change_type(obj1,NA_ROBJ);
GetNArray(obj1,a1);
} else
if (!NA_IsCOMPLEX(a1) && NA_IsCOMPLEX(a2)) {
obj1 = na_upcast_type(obj1,a2->type);
GetNArray(obj1,a1);
}
obj3 = na_make_object_extend( a1, a2, na_upcast[a1->type][a2->type],
CLASS_OF(obj1) );
na_exec_binary( NA_STRUCT(obj3), a1, a2,
PowFuncs[a1->type][a2->type] );
return obj3;
}
|
#+(obj2) ⇒ Object
method: self + other
711 712 |
# File 'ext/narray/na_func.c', line 711
static VALUE na_add(VALUE obj1, VALUE obj2)
{ return na_bifunc( obj1, obj2, Qnil, AddBFuncs ); }
|
#-(obj2) ⇒ Object
method: self - other
715 716 |
# File 'ext/narray/na_func.c', line 715
static VALUE na_sbt(VALUE obj1, VALUE obj2)
{ return na_bifunc( obj1, obj2, Qnil, SbtBFuncs ); }
|
#-@ ⇒ Object
method: -self
834 835 |
# File 'ext/narray/na_func.c', line 834
static VALUE na_neg(VALUE self)
{ return na_unary_func( self, na_no_cast, NegFuncs ); }
|
#/(obj2) ⇒ Object
method: self / other
723 724 |
# File 'ext/narray/na_func.c', line 723
static VALUE na_div(VALUE obj1, VALUE obj2)
{ return na_bifunc( obj1, obj2, Qnil, DivBFuncs ); }
|
#<=>(obj2) ⇒ Object
method: self <=> other
900 901 902 |
# File 'ext/narray/na_func.c', line 900
static VALUE
na_compare(VALUE obj1, VALUE obj2)
{ return na_compare_func( obj1, obj2, CmpFuncs ); }
|
#==(other) ⇒ Object
48 49 50 51 52 |
# File 'lib/narray_ext.rb', line 48 def ==(other) other.kind_of?(NArray) && shape == other.shape && eq(other).all? end |
#[](*args) ⇒ Object
method: [](idx1,idx2,…,idxN)
639 640 |
# File 'ext/narray/na_index.c', line 639
VALUE na_aref(int argc, VALUE *argv, VALUE self)
{ return na_aref_body(argc, argv, self, 0); }
|
#[]=(*idx, self) ⇒ Object
method: []=(idx1,idx2,…,idxN,val)
980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 |
# File 'ext/narray/na_index.c', line 980
VALUE
na_aset(int nidx, VALUE *idx, VALUE self)
{
--nidx;
if (nidx==0) {
na_aset_fill( self, idx[0] );
}
else
if (nidx==1) {
if ( NA_IsNArray(idx[0]) ) {
if( NA_TYPE(idx[0]) == NA_BYTE ) { /* then supposed to be a mask */
na_aset_mask(self, idx[0], idx[1]);
return(idx[1]);
}
}
if ( NA_IsArray(idx[0]) ) /* Array Index ? */
na_aset_array_index( self, idx[0], idx[1] );
else
na_aset_single_dim( self, idx[0], idx[1] );
}
else
if (nidx>1) {
na_aset_multi_dim( self, nidx, idx, idx[nidx] );
}
else /* if (nidx<0) */
rb_raise( rb_eArgError, "No value specified" );
return idx[nidx];
}
|
#^(obj2) ⇒ Object
method: self ^ other
739 740 |
# File 'ext/narray/na_func.c', line 739
static VALUE na_bit_xor(VALUE obj1, VALUE obj2)
{ return na_bifunc( obj1, obj2, Qnil, BXoFuncs ); }
|
#abs ⇒ Object
method: self.abs
842 843 |
# File 'ext/narray/na_func.c', line 842
static VALUE na_abs(VALUE self)
{ return na_unary_func( self, na_cast_real, AbsFuncs ); }
|
#accum(*args) ⇒ Object
method: accum( rank, … )
1228 1229 1230 |
# File 'ext/narray/na_func.c', line 1228
static VALUE
na_accum(int argc, VALUE *argv, VALUE self)
{ return na_sum_body(argc,argv,self,1); }
|
#add!(obj2) ⇒ Object
method: self.add!(other)
793 794 |
# File 'ext/narray/na_func.c', line 793
static VALUE na_add_bang(VALUE obj1, VALUE obj2)
{ return na_set_func( obj1, obj2, AddUFuncs ); }
|
#all? ⇒ Boolean
36 37 38 |
# File 'lib/narray_ext.rb', line 36 def all? where.size == size end |
#and(obj2) ⇒ Object
method: self.and other
883 884 885 |
# File 'ext/narray/na_func.c', line 883
static VALUE
na_cond_and(VALUE obj1, VALUE obj2)
{ return na_compare_func( obj1, obj2, AndFuncs ); }
|
#angle ⇒ Object Also known as: arg
method: self.imag
854 855 |
# File 'ext/narray/na_func.c', line 854
static VALUE na_angle(VALUE self)
{ return na_unary_func( self, na_cast_real, AnglFuncs ); }
|
#any? ⇒ Boolean
40 41 42 |
# File 'lib/narray_ext.rb', line 40 def any? where.size > 0 end |
#ceil ⇒ Object
method: self.ceil
870 871 |
# File 'ext/narray/na_func.c', line 870
static VALUE na_ceil(VALUE self)
{ return na_unary_func( self, na_cast_round, CeilFuncs ); }
|
#clone ⇒ Object Also known as: dup
method: dup()
459 460 461 462 463 464 465 466 467 468 |
# File 'ext/narray/narray.c', line 459
VALUE
na_clone(VALUE self)
{
struct NARRAY *org, *cpy;
GetNArray(self,org);
cpy = na_alloc_struct(org->type,org->rank,org->shape);
memcpy(cpy->ptr, org->ptr, na_sizeof[org->type] * org->total);
return na_wrap_struct(cpy,self);
}
|
#coerce(other) ⇒ Object
method: coerce(other)
791 792 793 794 795 796 797 |
# File 'ext/narray/narray.c', line 791
static VALUE na_coerce(VALUE self, VALUE other)
{
struct NARRAY *a1;
GetNArray(self,a1);
return rb_assoc_new( na_cast_object(other,a1->type), self );
}
|
#collect ⇒ Object Also known as: map
iterator: collect()
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 |
# File 'ext/narray/narray.c', line 1131
static VALUE
na_collect(VALUE obj1)
{
na_shape_t i;
int sz;
VALUE v, obj2;
struct NARRAY *a1, *a2;
char *p1, *p2;
void (*get)(), (*set)();
GetNArray(obj1,a1);
obj2 = na_make_object(a1->type, a1->rank, a1->shape, CLASS_OF(obj1));
GetNArray(obj2,a2);
p1 = a1->ptr;
p2 = a2->ptr;
sz = na_sizeof[a1->type];
get = SetFuncs[NA_ROBJ][a1->type];
set = SetFuncs[a1->type][NA_ROBJ];
for ( i=a1->total; i-->0; ) {
(*get)( 1, &v, 0, p1, 0 );
v = rb_yield(v);
(*set)( 1, p2, 0, &v, 0 );
p1 += sz;
p2 += sz;
}
return obj2;
}
|
#collect! ⇒ Object Also known as: map!
iterator: collect!()
1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 |
# File 'ext/narray/narray.c', line 1163
static VALUE
na_collect_bang(VALUE self)
{
na_shape_t i;
int sz;
VALUE v;
struct NARRAY *a1;
char *p1;
void (*get)(), (*set)();
GetNArray(self,a1);
p1 = a1->ptr;
sz = na_sizeof[a1->type];
get = SetFuncs[NA_ROBJ][a1->type];
set = SetFuncs[a1->type][NA_ROBJ];
for ( i=a1->total; i-->0; ) {
(*get)( 1, &v, 0, p1, 0 );
v = rb_yield(v);
(*set)( 1, p1, 0, &v, 0 );
p1 += sz;
}
return self;
}
|
#complex? ⇒ Boolean
31 32 33 34 |
# File 'lib/narray_ext.rb', line 31 def complex? self.typecode==NArray::DCOMPLEX || self.typecode==NArray::SCOMPLEX end |
#conj ⇒ Object Also known as: conjugate
method: self.conj
862 863 |
# File 'ext/narray/na_func.c', line 862
static VALUE na_conj(VALUE self)
{ return na_unary_func( self, na_no_cast, ConjFuncs ); }
|
#conj! ⇒ Object Also known as: conjugate!
method: self.conj!
813 814 |
# File 'ext/narray/na_func.c', line 813
static VALUE na_conj_bang(VALUE self)
{ return na_set_func( self, self, ConjFuncs ); }
|
#count_false ⇒ Integer
Returns the number of false (zero-value) in narray
571 572 573 574 575 |
# File 'ext/narray/na_index.c', line 571
VALUE
na_count_false(VALUE self)
{
return( SHAPE2NUM(na_count_false_body(self)) );
}
|
#count_true ⇒ Integer
Returns the number of true (non-zero) in narray
538 539 540 541 542 |
# File 'ext/narray/na_index.c', line 538
VALUE
na_count_true(VALUE self)
{
return( SHAPE2NUM(na_count_true_body(self)) );
}
|
#cumprod ⇒ Object
cumprod
1410 1411 1412 1413 1414 |
# File 'ext/narray/na_func.c', line 1410
static VALUE
na_cumprod(VALUE self)
{
return na_cumprod_bang(na_clone(self));
}
|
#cumprod! ⇒ Object
cumprod!
- 1 2 3 4 5
-
-> [1 3 6 10 15]
1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 |
# File 'ext/narray/na_func.c', line 1390
static VALUE
na_cumprod_bang(VALUE self)
{
struct NARRAY *a;
int step;
GetNArray(self,a);
if ( a->rank != 1 )
rb_raise( rb_eTypeError, "only for 1-dimensional array" );
if ( a->total < 2 )
return self; /* do nothing */
step = na_sizeof[a->type];
MulUFuncs[a->type](a->total-1, a->ptr+step,step, a->ptr,step);
return self;
}
|
#cumsum ⇒ Object
cumsum
1380 1381 1382 1383 1384 |
# File 'ext/narray/na_func.c', line 1380
static VALUE
na_cumsum(VALUE self)
{
return na_cumsum_bang(na_clone(self));
}
|
#cumsum! ⇒ Object
cumsum!
- 1 2 3 4 5
-
-> [1 3 6 10 15]
1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 |
# File 'ext/narray/na_func.c', line 1360
static VALUE
na_cumsum_bang(VALUE self)
{
struct NARRAY *a;
int step;
GetNArray(self,a);
if ( a->rank != 1 )
rb_raise( rb_eTypeError, "only for 1-dimensional array" );
if ( a->total < 2 )
return self; /* do nothing */
step = na_sizeof[a->type];
AddUFuncs[a->type](a->total-1, a->ptr+step,step, a->ptr,step);
return self;
}
|
#delete_at(*args) ⇒ Object
delete rows/columns
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/narray_ext.rb', line 90 def delete_at(*args) if args.size > self.rank raise ArgumentError, "too many arguments" end shp = self.shape ind = [] self.rank.times do |i| n = shp[i] case a=args[i] when Integer a = n+a if a<0 raise IndexError, "index(%d) out of range"%[a] if a<0 x = [0...a,a+1...n] when Range b = a.first b = n+b if b<0 raise IndexError, "index(%s) out of range"%[a] if b<0 e = a.last e = n+e if e<0 e -= 1 if a.exclude_end? raise IndexError, "index(%s) out of range"%[a] if e<0 x = [0...b,e+1...n] when Array x = (0...n).to_a x -= a.map do |j| raise IndexError, "contains non-integer" unless Integer===j (j<0) ? n+j : j end else if a raise ArgumentError, "invalid argument" else x = true end end ind << x end self[*ind] end |
#div!(obj2) ⇒ Object
method: self.div!(other)
801 802 |
# File 'ext/narray/na_func.c', line 801
static VALUE na_div_bang(VALUE obj1, VALUE obj2)
{ return na_set_func( obj1, obj2, DivUFuncs ); }
|
#each ⇒ Object
iterator: each()
1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 |
# File 'ext/narray/narray.c', line 1105
static VALUE
na_each(VALUE obj)
{
na_shape_t i;
int sz;
VALUE v;
struct NARRAY *ary;
char *p;
void (*func)();
GetNArray(obj,ary);
p = ary->ptr;
sz = na_sizeof[ary->type];
func = SetFuncs[NA_ROBJ][ary->type];
for ( i=ary->total; i-->0; ) {
(*func)( 1, &v, 0, p, 0 );
rb_yield(v);
p += sz;
}
return Qnil;
}
|
#element_size ⇒ Object
method: element_size – returns the element size of the array type
589 590 591 592 593 594 595 |
# File 'ext/narray/narray.c', line 589
static VALUE
na_element_size(VALUE self)
{
struct NARRAY *ary;
GetNArray(self,ary);
return INT2FIX(na_sizeof[ary->type]);
}
|
#empty? ⇒ Boolean
method: empty? – returns true if empty array
599 600 601 602 603 604 605 606 |
# File 'ext/narray/narray.c', line 599
static VALUE
na_is_empty(VALUE self)
{
struct NARRAY *ary;
GetNArray(self,ary);
if (ary->total==0) return Qtrue;
return Qfalse;
}
|
#eq(obj2) ⇒ Object
method: self.eq(other)
907 908 909 910 911 |
# File 'ext/narray/na_func.c', line 907
static VALUE
na_equal(VALUE obj1, VALUE obj2)
{
return na_compare_func( obj1, obj2, EqlFuncs );
}
|
#eql?(other) ⇒ Boolean
54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/narray_ext.rb', line 54 def eql?(other) self.class == other.class && typecode == other.typecode && shape == other.shape && case typecode when NArray::OBJECT to_a.eql? other.to_a else to_s.eql? other.to_s end end |
#fill!(val) ⇒ Object Also known as: fill
method: fill!(val)
1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 |
# File 'ext/narray/narray.c', line 1005
VALUE na_fill(VALUE self, volatile VALUE val)
{
struct NARRAY *a1, *a2;
GetNArray(self,a1);
val = na_cast_unless_narray(val,a1->type);
GetNArray(val,a2);
if (a2->total != 1)
rb_raise(rb_eArgError, "single-element argument required");
SetFuncs[a1->type][a2->type]( a1->total,
a1->ptr, na_sizeof[a1->type],
a2->ptr, 0 );
return self;
}
|
#flatten ⇒ Object
method: flatten
930 931 932 933 934 |
# File 'ext/narray/narray.c', line 930
static VALUE
na_flatten_ref(VALUE self)
{
return na_flatten_bang( na_wrap_struct( na_ref_alloc_struct(self), self ));
}
|
#flatten! ⇒ Object
method: flatten!
915 916 917 918 919 920 921 922 923 924 925 926 |
# File 'ext/narray/narray.c', line 915
static VALUE
na_flatten_bang(VALUE self)
{
struct NARRAY *ary;
GetNArray(self,ary);
if (ary->total==0 || ary->rank==0)
rb_raise(rb_eRuntimeError, "cannot reshape empty array");
ary->shape[0] = ary->total;
ary->rank = 1;
return self;
}
|
#floor ⇒ Object
method: self.floor
866 867 |
# File 'ext/narray/na_func.c', line 866
static VALUE na_floor(VALUE self)
{ return na_unary_func( self, na_cast_round, FloorFuncs ); }
|
#ge(obj2) ⇒ Object Also known as: >=
method: self >= other
949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 |
# File 'ext/narray/na_func.c', line 949
static VALUE
na_greater_equal(VALUE obj1, VALUE obj2)
{
VALUE obj;
na_shape_t i; char *p;
struct NARRAY *a;
obj = na_compare_func( obj1, obj2, CmpFuncs );
GetNArray(obj,a);
p = a->ptr;
for( i=a->total; i-->0; ) {
if (*p==1 || *p==0) *p=1;
else *p=0;
++p;
}
return obj;
}
|
#gt(obj2) ⇒ Object Also known as: >
method: self > other
932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 |
# File 'ext/narray/na_func.c', line 932
static VALUE
na_greater_than(VALUE self, VALUE obj2)
{
na_shape_t i; char *p;
struct NARRAY *a;
self = na_compare_func( self, obj2, CmpFuncs );
GetNArray(self,a);
p = a->ptr;
for( i=a->total; i-->0; ) {
if (*p!=1) *p=0;
++p;
}
return self;
}
|
#hash ⇒ Object
66 67 68 69 70 71 72 73 |
# File 'lib/narray_ext.rb', line 66 def hash case typecode when NArray::OBJECT [self.class, to_a].hash else [self.class, typecode, shape, to_s].hash end end |
#hton ⇒ Object Also known as: ntoh
method: self.hton , self.ntoh
822 823 |
# File 'ext/narray/na_func.c', line 822
static VALUE na_hton(VALUE self)
{ return na_unary_func( self, na_no_cast, H2NFuncs ); }
|
#htov ⇒ Object Also known as: vtoh
method: self.htov , self.vtoh
826 827 |
# File 'ext/narray/na_func.c', line 826
static VALUE na_htov(VALUE self)
{ return na_unary_func( self, na_no_cast, H2VFuncs ); }
|
#im ⇒ Object
method: self.im
858 859 |
# File 'ext/narray/na_func.c', line 858
static VALUE na_imag_mul(VALUE self)
{ return na_unary_func( self, na_cast_comp, ImagMulFuncs ); }
|
#imag ⇒ Object Also known as: image
method: self.imag
850 851 |
# File 'ext/narray/na_func.c', line 850
static VALUE na_imag(VALUE self)
{ return na_unary_func( self, na_cast_real, ImagFuncs ); }
|
#imag=(obj2) ⇒ Object
660 661 662 663 664 665 666 667 668 669 670 671 |
# File 'ext/narray/na_func.c', line 660
static VALUE
na_imag_set(VALUE obj1, volatile VALUE obj2)
{
struct NARRAY *a1;
GetNArray(obj1,a1);
obj2 = na_cast_object(obj2, na_cast_real[a1->type]);
na_exec_unary( NA_STRUCT(obj1), NA_STRUCT(obj2), ImgSetFuncs[a1->type] );
return obj1;
}
|
#indgen!(*args) ⇒ Object Also known as: indgen
method: indgen!([start,])
1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 |
# File 'ext/narray/narray.c', line 1024
VALUE
na_indgen(int argc, VALUE *argv, VALUE self)
{
na_shape_t start=0, step=1;
struct NARRAY *ary;
if (argc>0) {
start = NUM2SHAPE(argv[0]);
if (argc==2)
step = NUM2SHAPE(argv[1]);
else
if (argc>2)
rb_raise(rb_eArgError, "wrong # of arguments (%d for <= 2)", argc);
}
GetNArray(self,ary);
IndGenFuncs[ary->type]( ary->total,
ary->ptr, na_sizeof[ary->type],
start, step );
return self;
}
|
#inspect ⇒ Object
method: inspect() – returns the inspect of the array
801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 |
# File 'ext/narray/narray.c', line 801
static VALUE
na_inspect(VALUE self)
{
VALUE str;
struct NARRAY *ary;
int i;
char buf[256];
const char *classname;
const char *ref = "%s(ref).%s(%zd";
const char *org = "%s.%s(%zd";
GetNArray(self,ary);
classname = rb_class2name(CLASS_OF(self));
str = rb_str_new(0,0);
if (ary->rank < 1) {
sprintf(buf, "%s.%s(): []", classname, na_typestring[ary->type]);
rb_str_cat(str,buf,strlen(buf));
}
else {
sprintf(buf, (ary->ref==Qnil) ? org:ref,
classname, na_typestring[ary->type], ary->shape[0]);
rb_str_cat(str,buf,strlen(buf));
for (i=1; i<ary->rank; ++i) {
sprintf(buf,",%zd",ary->shape[i]);
rb_str_cat(str,buf,strlen(buf));
}
rb_str_cat(str,")",1);
rb_str_cat(str,": \n",3);
rb_str_concat(str, na_make_inspect(self));
}
return str;
}
|
#integer? ⇒ Boolean
26 27 28 29 30 |
# File 'lib/narray_ext.rb', line 26 def integer? self.typecode==NArray::BYTE || self.typecode==NArray::SINT || self.typecode==NArray::LINT end |
#le(obj2) ⇒ Object Also known as: <=
method: self <= other
987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 |
# File 'ext/narray/na_func.c', line 987
static VALUE
na_less_equal(VALUE obj1, VALUE obj2)
{
VALUE obj;
na_shape_t i; char *p;
struct NARRAY *a;
obj = na_compare_func( obj1, obj2, CmpFuncs );
GetNArray(obj,a);
p = a->ptr;
for( i=a->total; i-->0; ) {
if (*p==2 || *p==0) *p=1;
else *p=0;
++p;
}
return obj;
}
|
#lt(obj2) ⇒ Object Also known as: <
method: self < other
968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 |
# File 'ext/narray/na_func.c', line 968
static VALUE
na_less_than(VALUE obj1, VALUE obj2)
{
VALUE obj;
na_shape_t i; char *p;
struct NARRAY *a;
obj = na_compare_func( obj1, obj2, CmpFuncs );
GetNArray(obj,a);
p = a->ptr;
for( i=a->total; i-->0; ) {
if (*p==2) *p=1;
else *p=0;
++p;
}
return obj;
}
|
#mask(mask) ⇒ Object
:nodoc:
578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 |
# File 'ext/narray/na_index.c', line 578
VALUE
na_aref_mask(VALUE self, VALUE mask)
{
na_shape_t total;
int i;
struct NARRAY *a1, *am, *a2;
VALUE v;
GetNArray( self, a1 );
GetNArray( mask, am );
if (a1->total != am->total)
rb_raise(rb_eTypeError,"self.size(=%zd) != mask.size(=%zd)",
a1->total, am->total);
if (a1->rank != am->rank)
rb_raise(rb_eTypeError,"self.rank(=%i) != mask.rank(=%i)",
a1->rank, am->rank);
for (i=0; i<a1->rank; ++i)
if (a1->shape[i] != am->shape[i])
rb_raise(rb_eTypeError,"self.shape[%i](=%zd) != mask.shape[%i](=%zd)",
i, a1->shape[i], i, am->shape[i]);
total = na_count_true_body(mask);
v = na_make_object( a1->type, 1, &total, CLASS_OF(self) );
GetNArray(v,a2);
RefMaskFuncs[a1->type]
( a1->total, a2->ptr, na_sizeof[a2->type], a1->ptr,
na_sizeof[a1->type], am->ptr, (na_shape_t)1 );
return(v);
}
|
#max(*args) ⇒ Object
method: max( rank, … )
1487 1488 1489 |
# File 'ext/narray/na_func.c', line 1487
static VALUE
na_max(int argc, VALUE *argv, VALUE self)
{ return na_minmax_func(argc,argv,self,MaxFuncs); }
|
#mean(*ranks) ⇒ Object
Statistics
131 132 133 134 135 136 137 138 139 |
# File 'lib/narray_ext.rb', line 131 def mean(*ranks) if integer? a = self.to_type(NArray::DFLOAT) else a = self end a = NArray.ref(a) a.sum(*ranks) / (rank_total(*ranks)) end |
#median(rank = nil) ⇒ Object
186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/narray_ext.rb', line 186 def median(rank=nil) shape = self.shape rank = shape.size-1 if rank==nil s = sort(rank).reshape!(true,*shape[rank+1..-1]) n = s.shape[0] if n%2==1 s[n/2,false] else s[n/2-1..n/2,false].sum(0)/2 end end |
#min(*args) ⇒ Object
method: min( rank, … )
1482 1483 1484 |
# File 'ext/narray/na_func.c', line 1482
static VALUE
na_min(int argc, VALUE *argv, VALUE self)
{ return na_minmax_func(argc,argv,self,MinFuncs); }
|
#mod!(obj2) ⇒ Object
method: self.mod!(other)
809 810 |
# File 'ext/narray/na_func.c', line 809
static VALUE na_mod_bang(VALUE obj1, VALUE obj2)
{ return na_set_func( obj1, obj2, ModUFuncs ); }
|
#mul!(obj2) ⇒ Object
method: self.mul!(other)
805 806 |
# File 'ext/narray/na_func.c', line 805
static VALUE na_mul_bang(VALUE obj1, VALUE obj2)
{ return na_set_func( obj1, obj2, MulUFuncs ); }
|
#mul_accum(*args) ⇒ Object
method: mul_accum( other, rank, … )
1339 1340 1341 1342 1343 1344 1345 |
# File 'ext/narray/na_func.c', line 1339
static VALUE
na_mul_accum(int argc, VALUE *argv, VALUE self)
{
if (argc<2)
rb_raise(rb_eArgError, "wrong # of arguments (%d for >=2)", argc);
return na_mul_add_body(argc-1,argv+1,self,argv[0],Qnil,1);
}
|
#mul_add(*args) ⇒ Object
method: mul_add( other, rank, … )
1330 1331 1332 1333 1334 1335 1336 |
# File 'ext/narray/na_func.c', line 1330
static VALUE
na_mul_add(int argc, VALUE *argv, VALUE self)
{
if (argc<2)
rb_raise(rb_eArgError, "wrong # of arguments (%d for >=2)", argc);
return na_mul_add_body(argc-1,argv+1,self,argv[0],Qnil,0);
}
|
#ne(obj2) ⇒ Object
method: self.ne(other)
914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 |
# File 'ext/narray/na_func.c', line 914
static VALUE
na_not_equal(VALUE obj1, VALUE obj2)
{
VALUE obj;
na_shape_t i; char *p;
struct NARRAY *a;
obj = na_compare_func( obj1, obj2, EqlFuncs );
GetNArray(obj,a);
p = a->ptr;
for( i=a->total; i-->0; ) {
*p = *p==0 ? 1 : 0;
++p;
}
return obj;
}
|
#newdim(*args) ⇒ Object Also known as: newrank
method: newdim(size1,size2,…,sizeN)
992 993 994 995 996 997 998 999 1000 1001 |
# File 'ext/narray/narray.c', line 992
VALUE
na_newdim_ref(int argc, VALUE *argv, VALUE self)
{
struct NARRAY *ary;
GetNArray(self,ary);
ary = na_ref_alloc_struct(self);
na_newdim(argc, argv, ary);
return na_wrap_struct(ary,self);
}
|
#newdim!(*args) ⇒ Object Also known as: newdim=, newrank!, newrank=
method: newdim!(size1,size2,…,sizeN)
980 981 982 983 984 985 986 987 988 |
# File 'ext/narray/narray.c', line 980
static VALUE
na_newdim_bang(int argc, VALUE *argv, VALUE self)
{
struct NARRAY *ary;
GetNArray(self,ary);
na_newdim(argc, argv, ary);
return self;
}
|
#none? ⇒ Boolean
44 45 46 |
# File 'lib/narray_ext.rb', line 44 def none? where.size == 0 end |
#not ⇒ Object
method: self.not
878 879 |
# File 'ext/narray/na_func.c', line 878
static VALUE na_not(VALUE self)
{ return na_unary_func( self, na_cast_byte, NotFuncs ); }
|
#or(obj2) ⇒ Object
method: self.or other
888 889 890 |
# File 'ext/narray/na_func.c', line 888
static VALUE
na_cond_or(VALUE obj1, VALUE obj2)
{ return na_compare_func( obj1, obj2, Or_Funcs ); }
|
#original ⇒ Object
method: self.original
324 325 326 327 328 329 330 331 |
# File 'ext/narray/narray.c', line 324
static VALUE
na_original(VALUE self)
{
struct NARRAY *ary;
GetNArray(self,ary);
return ary->ref;
}
|
#prod(*args) ⇒ Object
method: prod( rank, … )
1272 1273 1274 |
# File 'ext/narray/na_func.c', line 1272
static VALUE
na_prod(int argc, VALUE *argv, VALUE self)
{ return na_prod_body(argc,argv,self,0); }
|
#random(*args) ⇒ Object
432 433 434 435 436 |
# File 'ext/narray/na_random.c', line 432
static VALUE
na_random(int argc, VALUE *argv, VALUE self)
{
return na_random_bang(argc, argv, na_clone(self));
}
|
#random!(*args) ⇒ Object
405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 |
# File 'ext/narray/na_random.c', line 405
static VALUE
na_random_bang(int argc, VALUE *argv, VALUE self)
{
VALUE vmax;
struct NARRAY *ary;
double rmax;
rb_scan_args(argc, argv, "01", &vmax);
if (first) {
rand_init(random_seed());
}
if (NIL_P(vmax)) {
rmax = 1;
} else {
rmax = NUM2DBL(vmax);
}
if (isinf(rmax) || isnan(rmax)) {
rb_raise(rb_eArgError, "rand-max must be regular value");
}
GetNArray(self,ary);
(*RndFuncs[ary->type])( ary->total, ary->ptr, na_sizeof[ary->type], rmax );
return self;
}
|
#randomn ⇒ Object
Normal distributed random number; valid for floating point types
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 |
# File 'lib/narray_ext.rb', line 200 def randomn size = self.size case type = self.typecode when COMPLEX; type=FLOAT when SCOMPLEX; type=SFLOAT when FLOAT when SFLOAT else raise TypeError, "NArray type must be (S)FLOAT or (S)COMPLEX." end rr = NArray.new(type,size) xx = NArray.new(type,size) i = 0 while i < size n = size-i m = ((n+Math::sqrt(n))*1.27).to_i x = NArray.new(type,m).random!(1) * 2 - 1 y = NArray.new(type,m).random!(1) * 2 - 1 r = x**2 + y**2 idx = (r<1).where idx = idx[0...n] if idx.size > n if idx.size>0 rr[i] = r[idx] xx[i] = x[idx] i += idx.size end end # Box-Muller transform rr = ( xx * NMath::sqrt( -2 * NMath::log(rr) / rr ) ) # finish rr.reshape!(*self.shape) if self.rank > 1 rr = rr.to_type(self.typecode) if type!=self.typecode if RUBY_VERSION < "1.8.0" self.type.refer(rr) else self.class.refer(rr) end end |
#randomn! ⇒ Object
alias randomn! randomn
240 241 242 243 |
# File 'lib/narray_ext.rb', line 240 def randomn! self[]= randomn self end |
#rank ⇒ Object Also known as: dim, dimension
method: rank() – returns the rank of the array
559 560 561 562 563 564 565 |
# File 'ext/narray/narray.c', line 559
static VALUE
na_rank(VALUE self)
{
struct NARRAY *ary;
GetNArray(self,ary);
return INT2FIX(ary->rank);
}
|
#rank_total(*ranks) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/narray_ext.rb', line 75 def rank_total(*ranks) if ranks.size>0 idx = [] ranks.each{|i| idx.push(*i)} # ranks is expected to be, e.g., [1, 3..5, 7] a = self.shape n = 1 idx.each{|i| n *= a[i]} n else self.total end end |
#real ⇒ Object
method: self.real
846 847 |
# File 'ext/narray/na_func.c', line 846
static VALUE na_real(VALUE self)
{ return na_unary_func( self, na_cast_real, RealFuncs ); }
|
#recip ⇒ Object
method: self.recip
838 839 |
# File 'ext/narray/na_func.c', line 838
static VALUE na_recip(VALUE self)
{ return na_unary_func( self, na_no_cast, RcpFuncs ); }
|
#refer ⇒ Object
method: self.refer
310 311 312 313 314 |
# File 'ext/narray/narray.c', line 310
static VALUE
na_refer(VALUE self)
{
return na_wrap_struct(na_ref_alloc_struct(self), self);
}
|
#reshape(*args) ⇒ Object
method: reshape(size1,size2,…,sizeN)
902 903 904 905 906 907 908 909 910 911 |
# File 'ext/narray/narray.c', line 902
static VALUE
na_reshape_ref(int argc, VALUE *argv, VALUE self)
{
struct NARRAY *ary;
GetNArray(self,ary);
ary = na_ref_alloc_struct(self);
na_reshape(argc, argv, ary, self);
return na_wrap_struct(ary,self);
}
|
#reshape!(*args) ⇒ Object Also known as: shape=
method: reshape!(size1,size2,…,sizeN)
890 891 892 893 894 895 896 897 898 |
# File 'ext/narray/narray.c', line 890
static VALUE
na_reshape_bang(int argc, VALUE *argv, VALUE self)
{
struct NARRAY *ary;
GetNArray(self,ary);
na_reshape(argc, argv, ary, self);
return self;
}
|
#reverse(*ranks) ⇒ Object
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 |
# File 'lib/narray_ext.rb', line 245 def reverse(*ranks) if self.rank==0 return self.dup elsif ranks.size==0 idx = (0...self.rank).map{-1..0} else idx = [true]*self.rank ranks.each do |i| if !i.kind_of?(Integer) raise ArgumentError, "Argument must be Integer" end if i >= self.rank raise ArgumentError, "dimension(%s) out of range"%[i] end idx[i] = -1..0 end end self[*idx] end |
#rms(*ranks) ⇒ Object
156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/narray_ext.rb', line 156 def rms(*ranks) if integer? a = self.to_type(NArray::DFLOAT) else a = self end a = NArray.ref(a) n = rank_total(*ranks) if complex? NMath::sqrt( (a.abs**2).sum(*ranks)/n ) else NMath::sqrt( (a**2).sum(*ranks)/n ) end end |
#rmsdev(*ranks) ⇒ Object
171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/narray_ext.rb', line 171 def rmsdev(*ranks) if integer? a = self.to_type(NArray::DFLOAT) else a = self end a = NArray.ref(a) n = rank_total(*ranks) if complex? NMath::sqrt( (( a-a.accum(*ranks).div!(n) ).abs**2).sum(*ranks)/n ) else NMath::sqrt( (( a-a.accum(*ranks).div!(n) )**2).sum(*ranks)/n ) end end |
#rot90(n_times = 1) ⇒ Object
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 |
# File 'lib/narray_ext.rb', line 265 def rot90(n_times=1) if self.rank < 2 raise "must be >= 2 dimensional array" end case n_times%4 when 0 self.dup when 1 self.transpose(1,0).reverse(0) when 2 self.reverse(0,1) when 3 self.transpose(1,0).reverse(1) end end |
#round ⇒ Object
method: self.round
874 875 |
# File 'ext/narray/na_func.c', line 874
static VALUE na_round(VALUE self)
{ return na_unary_func( self, na_cast_round, RoundFuncs ); }
|
#sbt!(obj2) ⇒ Object
method: self.sbt!(other)
797 798 |
# File 'ext/narray/na_func.c', line 797
static VALUE na_sbt_bang(VALUE obj1, VALUE obj2)
{ return na_set_func( obj1, obj2, SbtUFuncs ); }
|
#shape ⇒ Object Also known as: sizes
method: shape() – returns an array of shape of each rank
543 544 545 546 547 548 549 550 551 552 553 554 555 |
# File 'ext/narray/narray.c', line 543
static VALUE
na_shape(VALUE self)
{
struct NARRAY *ary;
VALUE *shape;
int i;
GetNArray(self,ary);
shape = ALLOCA_N(VALUE,ary->rank);
for (i = 0; i < ary->rank; ++i)
shape[i] = INT2FIX(ary->shape[i]);
return rb_ary_new4(ary->rank,shape);
}
|
#size ⇒ Object Also known as: total, length
method: size() – returns the total number of elements
569 570 571 572 573 574 575 |
# File 'ext/narray/narray.c', line 569
static VALUE
na_size(VALUE self)
{
struct NARRAY *ary;
GetNArray(self,ary);
return INT2FIX(ary->total);
}
|
#slice(*args) ⇒ Object
method: slice(idx1,idx2,…,idxN)
643 644 |
# File 'ext/narray/na_index.c', line 643
VALUE na_slice(int argc, VALUE *argv, VALUE self)
{ return na_aref_body(argc, argv, self, 1); }
|
#sort(*args) ⇒ Object
method: sort()
1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 |
# File 'ext/narray/na_func.c', line 1516
static VALUE
na_sort(int argc, VALUE *argv, VALUE self)
{
struct NARRAY *a1, *a2;
VALUE obj;
int (*func)(const void*, const void*);
na_shape_t i, size, step, nloop, nsort;
char *ptr;
GetNArray(self,a1);
nsort = na_sort_number(argc,argv,a1);
nloop = a1->total/nsort;
obj = na_make_object(a1->type,a1->rank,a1->shape,CLASS_OF(self));
GetNArray(obj,a2);
memcpy(a2->ptr, a1->ptr, a1->total*na_sizeof[a1->type]);
func = SortFuncs[a2->type];
size = na_sizeof[a2->type];
ptr = a2->ptr;
step = size * nsort;
for (i=0; i<nloop; ++i) {
qsort( ptr, nsort, size, func );
ptr += step;
}
return obj;
}
|
#sort!(*args) ⇒ Object
method: sort!()
1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 |
# File 'ext/narray/na_func.c', line 1547
static VALUE
na_sort_bang(int argc, VALUE *argv, VALUE self)
{
struct NARRAY *a1;
int (*func)(const void*, const void*);
na_shape_t i, size, step, nloop, nsort;
char *ptr;
GetNArray(self,a1);
nsort = na_sort_number(argc,argv,a1);
nloop = a1->total/nsort;
func = SortFuncs[a1->type];
size = na_sizeof[a1->type];
ptr = a1->ptr;
step = size * nsort;
for (i=0; i<nloop; ++i) {
qsort( ptr, nsort, size, func );
ptr += step;
}
return self;
}
|
#sort_index(*args) ⇒ Object
method: sort_index()
1574 1575 1576 1577 1578 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 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 |
# File 'ext/narray/na_func.c', line 1574
static VALUE
na_sort_index(int argc, VALUE *argv, VALUE self)
{
struct NARRAY *a1, *a2;
VALUE obj;
int (*func)(const void*, const void*);
na_shape_t i, size, nloop, nsort;
char **ptr_ptr, **ptr_p;
char *ptr_ary, *ptr_a;
GetNArray(self,a1);
nsort = na_sort_number(argc,argv,a1);
nloop = a1->total/nsort;
size = na_sizeof[a1->type];
ptr_p = ptr_ptr = ALLOC_N(char*, a1->total);
ptr_a = ptr_ary = a1->ptr;
for (i=a1->total; i>0; --i) {
*(ptr_p++) = ptr_a;
ptr_a += size;
}
func = SortIdxFuncs[a1->type];
ptr_p = ptr_ptr;
for (i=0; i<nloop; ++i) {
qsort( ptr_p, nsort, sizeof(char*), func );
ptr_p += nsort;
}
obj = na_make_object(NA_SIZE,a1->rank,a1->shape,CLASS_OF(self));
GetNArray(obj,a2);
ptr_p = ptr_ptr;
if ( NA_SIZE == NA_LINT ) {
int32_t *ptr_i;
ptr_i = (int32_t*)(a2->ptr);
for (i=a2->total; i>0; --i) {
*(ptr_i++) = (int32_t)(*(ptr_p++)-ptr_ary)/size;
}
} else if ( NA_SIZE == NA_LLINT ) {
int64_t *ptr_i;
ptr_i = (int64_t*)(a2->ptr);
for (i=a2->total; i>0; --i) {
*(ptr_i++) = (int64_t)(*(ptr_p++)-ptr_ary)/size;
}
}
xfree(ptr_ptr);
return obj;
}
|
#stddev(*ranks) ⇒ Object
141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/narray_ext.rb', line 141 def stddev(*ranks) if integer? a = self.to_type(NArray::DFLOAT) else a = self end a = NArray.ref(a) n = rank_total(*ranks) if complex? NMath::sqrt( (( a-a.accum(*ranks).div!(n) ).abs**2).sum(*ranks)/(n-1) ) else NMath::sqrt( (( a-a.accum(*ranks).div!(n) )**2).sum(*ranks)/(n-1) ) end end |
#sum(*args) ⇒ Object
method: sum( rank, … )
1223 1224 1225 |
# File 'ext/narray/na_func.c', line 1223
static VALUE
na_sum(int argc, VALUE *argv, VALUE self)
{ return na_sum_body(argc,argv,self,0); }
|
#swap_byte ⇒ Object
method: self.swap_byte
818 819 |
# File 'ext/narray/na_func.c', line 818
static VALUE na_swap_byte(VALUE self)
{ return na_unary_func( self, na_no_cast, SwpFuncs ); }
|
#to_a ⇒ Object
method: to_a – convert itself to Array
549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 |
# File 'ext/narray/na_array.c', line 549
VALUE
na_to_array(VALUE obj)
{
struct NARRAY *na;
na_shape_t *idx;
int i;
GetNArray(obj,na);
if (na->rank<1)
return rb_ary_new();
idx = ALLOCA_N(na_shape_t,na->rank);
for (i = 0; i<na->rank; ++i) idx[i] = 0;
return na_to_array0(na,idx,na->rank-1,SetFuncs[NA_ROBJ][na->type]);
}
|
#to_binary ⇒ Object
method: to_binary – convert the data contents to a BYTE type NArray
662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 |
# File 'ext/narray/narray.c', line 662
static VALUE
na_to_binary(VALUE self)
{
struct NARRAY *a1, *a2;
int i, rank;
na_shape_t *shape;
VALUE v;
GetNArray(self,a1);
rank = a1->rank+1;
shape = ALLOCA_N(na_shape_t,rank);
shape[0] = na_sizeof[a1->type];
for (i=1; i<rank; ++i)
shape[i] = a1->shape[i-1];
v = na_make_object( NA_BYTE, rank, shape, cNArray );
GetNArray(v,a2);
MEMCPY(a2->ptr,a1->ptr,char,a2->total);
return v;
}
|
#to_f ⇒ Object
method: to_f()
506 507 508 509 510 511 512 513 514 515 516 517 518 519 |
# File 'ext/narray/narray.c', line 506
static VALUE
na_to_float(VALUE self)
{
struct NARRAY *a1, *a2;
VALUE v;
GetNArray(self,a1);
v = na_make_object(na_upcast[NA_SFLOAT][a1->type], a1->rank, a1->shape,
CLASS_OF(self));
GetNArray(v,a2);
na_copy_nary(a2,a1);
return v;
}
|
#to_i ⇒ Object
method: to_i()
523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 |
# File 'ext/narray/narray.c', line 523
static VALUE
na_to_integer(VALUE self)
{
int type;
struct NARRAY *a1, *a2;
VALUE v;
GetNArray(self,a1);
if (!NA_IsINTEGER(a1))
type = NA_LINT;
else
type = a1->type;
v = na_make_object(type, a1->rank, a1->shape, CLASS_OF(self));
GetNArray(v,a2);
na_copy_nary(a2,a1);
return v;
}
|
#to_s ⇒ Object
method: to_s – convert the data contents to a binary string
650 651 652 653 654 655 656 657 658 |
# File 'ext/narray/narray.c', line 650
static VALUE
na_to_s(VALUE self)
{
struct NARRAY *ary;
GetNArray(self,ary);
if (NA_IsROBJ(ary))
rb_raise(rb_eTypeError,"cannot convert object-type NArray");
return rb_str_new(ary->ptr,ary->total*na_sizeof[ary->type]);
}
|
#to_string ⇒ Object
method: to_string
722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 |
# File 'ext/narray/narray.c', line 722
static VALUE
na_to_string(VALUE self)
{
VALUE v;
struct NARRAY *a1, *a2;
GetNArray(self,a1);
if (a1->total==0)
v = na_make_empty(NA_ROBJ, CLASS_OF(self));
else
if (a1->type==NA_BYTE) {
if (a1->rank==1)
return rb_str_new(a1->ptr,a1->shape[0]);
v = na_make_object(NA_ROBJ, a1->rank-1, a1->shape+1, cNArray);
GetNArray(v,a2);
na_to_string_binary( a2->total,
a2->ptr, sizeof(VALUE),
a1->ptr, a1->shape[0] );
} else {
v = na_make_object(NA_ROBJ, a1->rank, a1->shape, CLASS_OF(self));
GetNArray(v,a2);
ToStrFuncs[a1->type]( a2->total,
a2->ptr, sizeof(VALUE),
a1->ptr, na_sizeof[a1->type] );
}
return v;
}
|
#to_type(vtype) ⇒ Object
method: to_type(type)
489 490 491 492 493 494 495 496 497 498 499 500 501 502 |
# File 'ext/narray/narray.c', line 489
static VALUE
na_to_type(VALUE self, VALUE vtype)
{
struct NARRAY *a1, *a2;
VALUE v;
GetNArray(self,a1);
v = na_make_object(na_get_typecode(vtype), a1->rank, a1->shape,
CLASS_OF(self));
GetNArray(v,a2);
na_copy_nary(a2,a1);
return v;
}
|
#to_type_as_binary(vtype) ⇒ Object
method: to_type_as_binary(type)
687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 |
# File 'ext/narray/narray.c', line 687
static VALUE
na_to_type_as_binary(VALUE self, VALUE vtype)
{
struct NARRAY *a1, *a2;
na_shape_t size, total;
int type;
VALUE v;
type = na_get_typecode(vtype);
GetNArray(self,a1);
size = a1->total * na_sizeof[a1->type];
if ( size % na_sizeof[type] != 0 )
rb_raise(rb_eRuntimeError, "bina1 size mismatch");
total = size / na_sizeof[type];
v = na_make_object( type, 1, &total, cNArray );
GetNArray(v,a2);
MEMCPY(a2->ptr,a1->ptr,char,size);
return v;
}
|
#transpose(*args) ⇒ Object
method: self.transpose( … )
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 |
# File 'ext/narray/na_func.c', line 1102
static VALUE
na_transpose(int argc, VALUE *argv, VALUE self)
{
struct NARRAY *a2;
int i, rankc, *rankv;
na_shape_t *shape;
VALUE obj;
GetNArray(self,a2);
/* Parse Argument */
rankv = ALLOC_N( int, NA_MAX_RANK);
shape = ALLOC_N( na_shape_t, NA_MAX_RANK);
rankc = na_arg_to_rank( argc, argv, a2->rank, rankv, 1 );
if (rankc > a2->rank)
rb_raise(rb_eArgError, "too many args");
for ( ;rankc<a2->rank; ++rankc)
rankv[rankc] = rankc;
/* Argument Check */
MEMZERO(shape,na_shape_t,rankc);
for (i=0; i<rankc; ++i) {
if (shape[rankv[i]] != 0)
rb_raise(rb_eArgError,"rank doublebooking");
shape[rankv[i]] = 1;
}
for (i=0; i<a2->rank; ++i)
shape[i] = a2->shape[rankv[i]];
obj = na_make_object(a2->type, a2->rank, shape, CLASS_OF(self));
na_transpose_bifunc( NA_STRUCT(obj), a2, rankv );
xfree(rankv);
xfree(shape);
return obj;
}
|
#typecode ⇒ Object
method: typecode – returns the type of the array
579 580 581 582 583 584 585 |
# File 'ext/narray/narray.c', line 579
static VALUE
na_typecode(VALUE self)
{
struct NARRAY *ary;
GetNArray(self,ary);
return INT2FIX(ary->type);
}
|
#where ⇒ Object
method: where
idx_true = narray.where
1097 1098 1099 1100 1101 |
# File 'ext/narray/narray.c', line 1097
static VALUE
na_where(VALUE self)
{
return RARRAY_PTR( na_where2(self) )[0];
}
|
#where2 ⇒ Object
method: where2
idx_true, idx_false = narray.where2
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/narray/narray.c', line 1049
static VALUE
na_where2(volatile VALUE obj)
{
VALUE v1, v0;
na_shape_t n, i, n1, n0;
char *c;
int32_t *idx1, *idx0;
struct NARRAY *ary, *a1, *a0; /* a1=true, a0=false */
GetNArray(obj,ary);
/* Convert to NA_BYTE by calling "obj.ne(0)", if needed */
if(ary->type != NA_BYTE) {
obj = rb_funcall(obj, na_id_ne, 1, INT2FIX(0));
GetNArray(obj,ary);
}
n = ary->total;
/* Count true */
c = ary->ptr;
n1 = 0;
for (i=0; i<n; ++i)
if (*(c++)) ++n1;
n0 = n-n1;
/* partially true and false */
v1 = na_make_object( NA_LINT, 1, &n1, cNArray );
GetNArray(v1,a1);
idx1 = (int32_t*) a1->ptr;
v0 = na_make_object( NA_LINT, 1, &n0, cNArray );
GetNArray(v0,a0);
idx0 = (int32_t*) a0->ptr;
/* Get Indices */
c = ary->ptr;
for ( i=0; i<n; ++i ) {
if (*(c++))
*(idx1++) = i;
else
*(idx0++) = i;
}
return rb_assoc_new( v1, v0 );
}
|
#xor(obj2) ⇒ Object
method: self.xor other
893 894 895 |
# File 'ext/narray/na_func.c', line 893
static VALUE
na_cond_xor(VALUE obj1, VALUE obj2)
{ return na_compare_func( obj1, obj2, XorFuncs ); }
|
#|(obj2) ⇒ Object
method: self | other
735 736 |
# File 'ext/narray/na_func.c', line 735
static VALUE na_bit_or(VALUE obj1, VALUE obj2)
{ return na_bifunc( obj1, obj2, Qnil, BOrFuncs ); }
|
#~ ⇒ Object
method: ~self
830 831 |
# File 'ext/narray/na_func.c', line 830
static VALUE na_bit_rev(VALUE self)
{ return na_unary_func( self, na_no_cast, BRvFuncs ); }
|