Class: CArray
- Extended by:
- DataTypeExtension
- Defined in:
- lib/carray/mask.rb,
lib/carray/math.rb,
lib/carray/math.rb,
lib/carray/time.rb,
lib/carray/basic.rb,
lib/carray/basic.rb,
lib/carray/table.rb,
lib/carray/string.rb,
lib/carray/struct.rb,
lib/carray/compose.rb,
lib/carray/convert.rb,
lib/carray/inspect.rb,
lib/carray/testing.rb,
lib/carray/iterator.rb,
lib/carray/iterator.rb,
lib/carray/obsolete.rb,
lib/carray/ordering.rb,
lib/carray/broadcast.rb,
lib/carray/construct.rb,
lib/carray/construct.rb,
lib/carray/construct.rb,
lib/carray/construct.rb,
lib/carray/construct.rb,
lib/carray/serialize.rb,
lib/carray/transform.rb,
lib/carray/io/imagemagick.rb,
lib/carray/math/histogram.rb,
lib/carray/math/recurrence.rb,
lib/carray/object/ca_obj_pack.rb,
lib/carray/autoload/autoload_base.rb,
lib/carray/autoload/autoload_gem_ffi.rb,
lib/carray/autoload/autoload_gem_zimg.rb,
lib/carray/autoload/autoload_gem_io_pg.rb,
lib/carray/autoload/autoload_gem_io_csv.rb,
lib/carray/autoload/autoload_gem_narray.rb,
lib/carray/autoload/autoload_gem_opencv.rb,
lib/carray/autoload/autoload_gem_random.rb,
lib/carray/autoload/autoload_gem_rmagick.rb,
lib/carray/autoload/autoload_gem_io_sqlite3.rb,
lib/carray/autoload/autoload_io_imagemagick.rb,
lib/carray/autoload/autoload_math_histogram.rb,
lib/carray/autoload/autoload_gem_numo_narray.rb,
lib/carray/autoload/autoload_math_recurrence.rb,
ext/ruby_carray.c
Overview
carray/composition.rb
This file is part of Ruby/CArray extension library.
You can redistribute it and/or modify it under the terms of
the Ruby Licence.
Copyright (C) 2005 Hiroki Motoyoshi
Direct Known Subclasses
Defined Under Namespace
Modules: DataTypeExtension, DataTypeNewConstructor, TableMethods Classes: Boolean, Cmplx128, Cmplx256, Cmplx64, Complex128, Complex64, DataTypeError, Fixlen, Float128, Float32, Float64, Inspector, Int16, Int32, Int64, Int8, Object, Serializer, UInt16, UInt32, UInt64, UInt8
Constant Summary collapse
- SFloat =
Float32- DFloat =
Float64- SComplex =
Complex64- DComplex =
Complex128- RObject =
Object- TypeSymbol =
nil- DataType =
nil- VERSION =
rb_str_new2(CA_VERSION)
- VERSION_CODE =
INT2NUM(CA_VERSION_CODE)
- VERSION_MAJOR =
INT2NUM(CA_VERSION_MAJOR)
- VERSION_MINOR =
INT2NUM(CA_VERSION_MINOR)
- VERSION_TEENY =
INT2NUM(CA_VERSION_TEENY)
- VERSION_DATE =
rb_str_new2(CA_VERSION_DATE)
- DEFAULT_GC_INTERVAL =
rb_float_new(ca_default_gc_interval)
- HAVE_COMPLEX =
Qfalse
Class Method Summary collapse
-
.__new__(type, *args) ⇒ Object
Create new CArray object from the return value of the block with data type
type. - .__new_fixlen__(bytes, v) ⇒ Object
- .scan_float(str, fill_value = nil) ⇒ Object
- .scan_int(str, fill_value = nil) ⇒ Object
-
.attach(*arrays) ⇒ Object
(Internal) Guarantees that the reference memory block is attached.
-
.attach!(*arrays) ⇒ Object
(Internal) Guarantees that the reference memory block is attached.
-
.big_endian? ⇒ Boolean
(Inquiry) Returns true if the byte order of the architecture is big endian.
- .bind(data_type, list, at = 0) ⇒ Object
-
.boolean(*dim) ⇒ Object
(Construction) Short-Hand of ‘CArray.new(:boolean, dim, bytes: bytes) { … }`.
- .broadcast(*argv) ⇒ Object
-
.uint8(*dim) ⇒ Object
(Construction) Short-Hand of ‘CArray.new(:uint8, dim, bytes: bytes) { … }`.
-
.cast(value) ⇒ Object
[TBD].
-
.cast_self_or_other(other) ⇒ Object
[TBD].
-
.cmplx128(*dim) ⇒ Object
(Construction) Short-Hand of ‘CArray.new(:cmplx128, dim, bytes: bytes) { … }`.
-
.cmplx256(*dim) ⇒ Object
(Construction) Short-Hand of ‘CArray.new(:cmplx256, dim, bytes: bytes) { … }`.
-
.cmplx64(*dim) ⇒ Object
(Construction) Short-Hand of ‘CArray.new(:cmplx64, dim, bytes: bytes) { … }`.
- .combine(data_type, tdim, list, at = 0) ⇒ Object
-
.cmplx64(*dim) ⇒ Object
(Construction) Short-Hand of ‘CArray.new(:cmplx64, dim, bytes: bytes) { … }`.
- .composite(data_type, tdim, list, at = 0) ⇒ Object
-
.data_type?(data_type) ⇒ Boolean
(Inquiry) Returns true if the given data_type indicate the valid data_type.
-
.data_type_name(data_type) ⇒ Object
(Inquiry) Returns string representaion of the data_type specifier.
-
.cmplx128(*dim) ⇒ Object
(Construction) Short-Hand of ‘CArray.new(:cmplx128, dim, bytes: bytes) { … }`.
-
.float64(*dim) ⇒ Object
(Construction) Short-Hand of ‘CArray.new(:float64, dim, bytes: bytes) { … }`.
- .dump(ca, opt = {}) ⇒ Object
-
.each_index(*shape) ⇒ Object
(Iterator) Iterates with the multi-dimensional indeces for the given dimension numbers.
-
.endian ⇒ Object
(Inquiry) Returns the machine endianness.
-
.fixlen(*dim, bytes: ) ⇒ Object
(Construction) Short-Hand of ‘CArray.new(:fixlen, dim, bytes: ) { … }`.
-
.float32(*dim) ⇒ Object
(Construction) Short-Hand of ‘CArray.new(:float32, dim, bytes: bytes) { … }`.
-
.float128(*dim) ⇒ Object
(Construction) Short-Hand of ‘CArray.new(:float128, dim, bytes: bytes) { … }`.
-
.float32(*dim) ⇒ Object
(Construction) Short-Hand of ‘CArray.new(:float32, dim, bytes: bytes) { … }`.
-
.float64(*dim) ⇒ Object
(Construction) Short-Hand of ‘CArray.new(:float64, dim, bytes: bytes) { … }`.
-
.from_binary(io, opt = {}) ⇒ Object
:nodoc:.
- .from_bit_string(bstr, nb, data_type = CA_INT32, dim = nil) ⇒ Object
-
.gc_interval ⇒ Object
Returns the threshold of incremented memory (MB) used by carray object until start GC.
-
.gc_interval= ⇒ Object
Sets the threshold of incremented memory (MB) used by carray object until start GC.
-
.guess_array_shape ⇒ Object
yard: def CArray.guess_array_shape (arg) end.
- .guess_type_and_bytes ⇒ Object
-
.int32(*dim) ⇒ Object
(Construction) Short-Hand of ‘CArray.new(:int32, dim, bytes: bytes) { … }`.
-
.int16(*dim) ⇒ Object
(Construction) Short-Hand of ‘CArray.new(:int16, dim, bytes: bytes) { … }`.
-
.int32(*dim) ⇒ Object
(Construction) Short-Hand of ‘CArray.new(:int32, dim, bytes: bytes) { … }`.
-
.int64(*dim) ⇒ Object
(Construction) Short-Hand of ‘CArray.new(:int64, dim, bytes: bytes) { … }`.
-
.int8(*dim) ⇒ Object
(Construction) Short-Hand of ‘CArray.new(:int8, dim, bytes: bytes) { … }`.
- .join(*argv) ⇒ Object
-
.little_endian? ⇒ Boolean
(Inquiry) Returns true if the byte order of the architecture is little endian.
- .load(input, opt = {}) ⇒ Object
-
.load_binary(filename, opt = {}) ⇒ Object
:nodoc:.
-
.load_binary_io(io, opt = {}) ⇒ Object
:nodoc:.
- .load_by_magick(filename, imap = "rgb", data_type = nil) ⇒ Object
- .mem_usage ⇒ Object
- .merge(data_type, list, at = -1)) ⇒ Object
- .meshgrid(*args) ⇒ Object
-
.object(*dim) ⇒ Object
(Construction) Short-Hand of ‘CArray.new(:object, dim, bytes: bytes) { … }`.
- .pack(*argv) ⇒ Object
- .pickup(data_type, ref, args) ⇒ Object
-
.reset_gc_interval ⇒ Object
Reset the counter for the GC start when the incremented memory get larger than
CArray.gc_interval. - .save(ca, output, opt = {}) ⇒ Object
-
.scan_index ⇒ Object
yard: def CArray.scan_index(dim, idx) end.
-
.int16(*dim) ⇒ Object
(Construction) Short-Hand of ‘CArray.new(:int16, dim, bytes: bytes) { … }`.
-
.sizeof(data_type) ⇒ Object
(Inquiry) Returns the byte length of an element of the given data type.
-
.span(*argv) ⇒ Object
CArray.span(data_type, range[, step]) CArray.span(range[, step]) -> data_type guessed by range.first type.
- .summation(*dim) ⇒ Object
-
.uint16(*dim) ⇒ Object
(Construction) Short-Hand of ‘CArray.new(:uint16, dim, bytes: bytes) { … }`.
-
.uint32(*dim) ⇒ Object
(Construction) Short-Hand of ‘CArray.new(:uint32, dim, bytes: bytes) { … }`.
-
.uint64(*dim) ⇒ Object
(Construction) Short-Hand of ‘CArray.new(:uint64, dim, bytes: bytes) { … }`.
-
.uint8(*dim) ⇒ Object
(Construction) Short-Hand of ‘CArray.new(:uint8, dim, bytes: bytes) { … }`.
-
.wrap(data_type, dim, bytes = 0{ target }) ⇒ Object
- TBD
-
(Construction) target should have method “wrap_as_carray(obj)”.
-
.wrap_readonly(other, date_type = nil) ⇒ Object
[TBD].
-
.wrap_writable(other, date_type = nil) ⇒ Object
[TBD].
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
(also: #cmp)
comparison operators.
-
#==(other) ⇒ Object
(also: #eql?)
(Inquiry) Returns true if the object equals the given array.
-
#[] ⇒ Object
yard: class CArray def [] (*spec) end end.
-
#[]= ⇒ Object
yard: class CArray def []= (*spec) end end.
-
#__attach__ ⇒ Object
(Internal, DevelopperOnly) Attaches the reference memory block.
-
#__detach__ ⇒ Object
(Internal, DevelopperOnly) Detaches the reference memory block.
-
#__detach__ ⇒ Object
(Internal, DevelopperOnly) Syncs the reference memory block to the parent array.
-
#addr2index ⇒ Object
yard: class CArray # converts addr to index def addr2index (addr) end end.
-
#address ⇒ Object
index / indices / axes.
- #all_close? ⇒ Boolean
- #all_equal? ⇒ Boolean
- #all_equiv? ⇒ Boolean
-
#all_masked? ⇒ Boolean
(Masking, Inquiry) Returns true if all elements of self are masked.
-
#ancestors ⇒ Object
(Attribute) Returns the list of objects in the chain of reference.
- #anomaly(*argv) ⇒ Object (also: #anom)
- #any_close? ⇒ Boolean
- #any_equal? ⇒ Boolean
- #any_equiv? ⇒ Boolean
-
#any_masked? ⇒ Boolean
(Masking, Inquiry) Returns true if self has at least one masked element.
- #arg ⇒ Object
-
#as_boolean ⇒ Object
(Reference) Short-Hand of ‘CArray#as_type(:boolean)`.
-
#as_cmplx128 ⇒ Object
(also: #as_dcomplex)
(Reference) Short-Hand of ‘CArray#as_type(:cmplx128)`.
-
#as_cmplx256 ⇒ Object
(Reference) Short-Hand of ‘CArray#as_type(:cmplx256)`.
-
#as_cmplx64 ⇒ Object
(also: #as_complex)
(Reference) Short-Hand of ‘CArray#as_type(:cmplx64)`.
-
#as_fixlen(bytes: nil) ⇒ Object
(Reference) Short-Hand of ‘CArray#as_type(:fixlen, bytes: nil)`.
-
#as_float128 ⇒ Object
(Reference) Short-Hand of ‘CArray#as_type(:float128)`.
-
#as_float32 ⇒ Object
(also: #as_float)
(Reference) Short-Hand of ‘CArray#as_type(:float32)`.
-
#as_float64 ⇒ Object
(also: #as_double)
(Reference) Short-Hand of ‘CArray#as_type(:float64)`.
-
#as_int16 ⇒ Object
(also: #as_short)
(Reference) Short-Hand of ‘CArray#as_type(:int16)`.
-
#as_int32 ⇒ Object
(also: #as_int)
(Reference) Short-Hand of ‘CArray#as_type(:int32)`.
-
#as_int64 ⇒ Object
(Reference) Short-Hand of ‘CArray#as_type(:int64)`.
-
#as_int8 ⇒ Object
(Reference) Short-Hand of ‘CArray#as_type(:int8)`.
-
#as_object ⇒ Object
(Reference) Short-Hand of ‘CArray#as_type(:object)`.
-
#as_type ⇒ Object
CArray#as_type.
-
#as_uint16 ⇒ Object
(Reference) Short-Hand of ‘CArray#as_type(:uint16)`.
-
#as_uint32 ⇒ Object
(Reference) Short-Hand of ‘CArray#as_type(:uint32)`.
-
#as_uint64 ⇒ Object
(Reference) Short-Hand of ‘CArray#as_type(:uint64)`.
-
#as_uint8 ⇒ Object
(also: #as_byte)
(Reference) Short-Hand of ‘CArray#as_type(:uint8)`.
- #asign(*idx) ⇒ Object
-
#attach ⇒ Object
(Internal) Guarantees that the reference memory block is attached.
-
#attach! ⇒ Object
(Internal) Guarantees that the reference memory block is attached.
-
#attached? ⇒ Boolean
(Inquiry) Returns true if the object is attached.
- #attribute ⇒ Object
- #attribute=(obj) ⇒ Object
- #between(a, b) ⇒ Object
- #bin(val, include_upper, include_lowest, offset = 0) ⇒ Object
-
#bitarray ⇒ Object
yard: class CArray def bits end alias bitarray bits end.
-
#bitfield ⇒ Object
yard: class CArray def bitfield (range, type) end end.
-
#bits ⇒ Object
yard: class CArray def bits end alias bitarray bits end.
-
#block_iterator(*argv) ⇒ Object
:nodoc:.
-
#blocks ⇒ Object
yard: class CArray # Create block iterator.
-
#fixlen(bytes: ) ⇒ Object
(Conversion) Short-Hand of “CArray#to_type(:boolean)”.
-
#boolean? ⇒ Boolean
(Inquiry) Return true if
selfis boolean type array. - #broadcast_to(*new_dim) ⇒ Object
-
#bsearch ⇒ Object
Returns a new CArray object containing ca’s elements sorted.
-
#bsearch_index ⇒ Object
[TBD].
- #by(other) ⇒ Object
-
#bytes ⇒ Object
(Attribute) Returns the byte size of each element (e.g. 4 for CA_INT32, 8 for CA_FLOAT64).
-
#cast_with(other) ⇒ Object
[TBD].
- #classes(classifier = nil, &block) ⇒ Object
-
#classify(klass, outlier = nil) ⇒ Object
:nodoc:.
-
#clip(idx, ary) ⇒ Object
(copy) Clips the data at
idxfromselftoary. -
#cmplx128 ⇒ Object
(also: #dcomplex)
(Conversion) Short-Hand of “CArray#to_type(:cmplx128)”.
-
#cmplx256 ⇒ Object
(Conversion) Short-Hand of “CArray#to_type(:cmplx256)”.
-
#cmplx64 ⇒ Object
(also: #complex)
(Conversion) Short-Hand of “CArray#to_type(:cmplx64)”.
- #code ⇒ Object
-
#coerece(other) ⇒ Object
[TBD].
-
#map!({|elem| ... }) ⇒ Object
(Iterator, Destructive) Iterates all elements of the object and stores the return from the block to the element.
-
#map_addr!({|addr| ... }) ⇒ Object
[TBD].
-
#map_index!({|idx| ... }) ⇒ Object
[TBD].
-
#map_with_addr!({|elem, addr| ... }) ⇒ Object
[TBD].
-
#map_with_index({|elem, idx| ... }) ⇒ Object
[TBD].
-
#compact ⇒ Object
Returns the array which ndim is reduced by eliminating the dimensions which size == 1.
-
#compacted ⇒ Object
Reutrns the reference which ndim is reduced by eliminating the dimensions which size == 1.
-
#complex? ⇒ Boolean
(Inquiry) Returns true if
selfis complex type array. - #contains(*list) ⇒ Object
-
#convert(data_type = nil, dim = nil{ |elem| ... }) ⇒ Object
(Conversion) Returns new array which elements are caluculated in the iteration block.
- #correlation(y, min_count = nil, fill_value = nil) ⇒ Object
- #count ⇒ Object
- #count_close ⇒ Object
- #count_equal ⇒ Object
- #count_equiv ⇒ Object
- #count_false ⇒ Object
-
#count_masked(*axis) ⇒ Object
Returns the number of masked elements.
-
#count_not_masked(*axis) ⇒ Object
Returns the number of not-masked elements.
- #count_true ⇒ Object
- #covariance(y, min_count = nil, fill_value = nil) ⇒ Object
- #covariancep(y, min_count = nil, fill_value = nil) ⇒ Object
- #cummax ⇒ Object
- #cummin ⇒ Object
- #cumprod ⇒ Object
- #cumwsum ⇒ Object
-
#data_class ⇒ Object
(Attribute) Returns data_class if
selfis fixed-length type and it has the data class. -
#data_type ⇒ Object
(Attribute) Returns the data type of each element (e.g. CA_INT32, CA_FLOAT64, …).
-
#data_type_name ⇒ Object
(Attribute) Returns the string representaion of the data_type (e.g. “int32”, “fixlen”).
- #deg_180 ⇒ Object
- #deg_180! ⇒ Object
- #deg_360 ⇒ Object
- #deg_360! ⇒ Object
- #delete_block(offset, bsize) ⇒ Object
-
#dim ⇒ Object
(Attribute) Returns the Array object contains the dimensional shape of array (e.g. [2,3] for 2D 2x3 array, …).
-
#dim0 ⇒ Object
(Attribute) Short-hand for “dim”.
-
#dim1 ⇒ Object
(Attribute) Short-hand for “dim”.
-
#dim2 ⇒ Object
(Attribute) Short-hand for ‘dim’.
-
#dim3 ⇒ Object
(Attribute) Short-hand for “dim”.
- #display_by_magick(image_type = nil, options = "") ⇒ Object
-
#dump_binary ⇒ Object
(IO) Dumps the value array to the given IO stream.
-
#duplicated_values ⇒ Object
Returns the array eliminated all the duplicated elements.
-
#each({|elem| ... }) ⇒ Object
(Iterator) Iterates all the elements of the object.
-
#each_addr({|addr| ... }) ⇒ Object
(Iterator) Iterates all address of the object.
-
#each_index({|idx| ... }) ⇒ Object
(Iterator) Iterates all index of the object.
-
#each_with_addr({|elem, addr| ... }) ⇒ Object
(Iterator) Iterates all the elements of the object.
-
#each_with_index({|elem, idx| ... }) ⇒ Object
[TBD].
-
#elem_copy(idx1, idx2) ⇒ Object
(Element) Copies the value of the element of idx1 to the element of idx2.
-
#elem_decr(idx) ⇒ Object
(Element) Decrements the value by 1 at the element of idx.
-
#elem_fetch(idx) ⇒ Object
(Element) Fetches the object value at the element of idx.
-
#elem_incr(idx) ⇒ Object
(Element) Increments the value by 1 at the element of idx.
-
#elem_masked?(idx) ⇒ Boolean
(Masking, Element) Returns true if the element at given idx is masked.
-
#elem_store(idx, obj) ⇒ Object
(Element) Stores the object value in the element of idx.
-
#elem_swap(idx1, idx2) ⇒ Object
(Element) Swaps the values at the elements which are specified by arguments.
-
#elements ⇒ Object
(Attribute) Returns the number of elements.
-
#empty? ⇒ Boolean
(Inquiry) Returns true if the object is empty.
-
#entity? ⇒ Boolean
(Inquiry) Returns true if
selfis an entity array (not a virtual array). -
#extend_as_table(column_names) ⇒ Object
obsolete methods.
-
#fa ⇒ Object
:nodoc:.
-
#fake ⇒ Object
yard: class CArray def fake (data_type, options=:bytes=>0) end end.
-
#false ⇒ Object
Returns the 8-bit integer CArray object filled with 0 which dimension size is same as
self. -
#farray ⇒ Object
yard: class CArray # create the virtual transposed array which dimension order is reversed.
-
#field ⇒ Object
yard: class CArray # call-seq: # CArray#field(offset, data_type[, :bytes=>bytes]) # CArray#field(offset, data_class) # CArray#field(offset, template) # def field (offset, data_type) end end.
-
#fields ⇒ Object
(Reference) Returns an array of data class members (fields).
-
#fields_at(*names) ⇒ Object
Returns an array of data class members (fields) with names specified.
-
#fill ⇒ Object
yard: class CArray def fill end def fill_copy end end.
- #fill_copy ⇒ Object
- #first ⇒ Object
-
#fixlen(bytes: ) ⇒ Object
(Conversion) Short-Hand of “CArray#to_type(:fixlen, bytes:)”.
-
#fixlen? ⇒ Boolean
(Inquiry) Returns true if
selfis fixed-length type array. - #flatten ⇒ Object
-
#flattened ⇒ Object
flatten.
-
#float128 ⇒ Object
(Conversion) Short-Hand of “CArray#to_type(:float128)”.
-
#float32 ⇒ Object
(also: #float)
(Conversion) Short-Hand of “CArray#to_type(:float32)”.
-
#float64 ⇒ Object
(also: #double)
(Conversion) Short-Hand of “CArray#to_type(:float64)”.
-
#float? ⇒ Boolean
(Inquiry) Returns true if
selfis float type array. -
#freeze ⇒ Object
Freeze the object.
- #from_bit_string(bstr, nb) ⇒ Object
- #gradate ⇒ Object
-
#grade ⇒ Object
rb_define_method(rb_cCArray, “histogram”, rb_ca_histogram, -1);.
-
#grid ⇒ Object
yard: class CArray def grid end end.
- #has_attribute? ⇒ Boolean
-
#has_data_class? ⇒ Boolean
(Inquiry) Returns true if
selfis fixed-length type and has the data class. -
#has_mask? ⇒ Boolean
(Masking, Inquiry) Returns true if self has the mask array.
-
#hash ⇒ Object
(Inquiry) Returns the hash value of the object.
-
#imag ⇒ Object
Return the imaginary part of
self. - #imag=(val) ⇒ Object
-
#incr_addr(addr) ⇒ Object
(Element) Increment the value at the element of addr.
- #index(n = 0) ⇒ Object
-
#index2addr ⇒ Object
yard: class CArray def index2addr (*index) end end.
- #indices ⇒ Object
-
#inherit_mask(*others: ) ⇒ Object
(Masking, Destructive) Sets the mask array of
selfby the logical sum of the mask states ofselfand arrays given in arguments. -
#inherit_mask_replace(*others) ⇒ Object
Sets the mask array of
selfby the logical sum of the mask states of arrays given in arguments. -
#initialize(data_type, dim, bytes = 0) ⇒ Object
constructor
Constructs a new CArray object of data_type, which has the ndim and the dimensions specified by an
ArrayofIntegeror an argument list ofInteger. - #initialize_copy(other) ⇒ Object
-
#insert_block(offset, bsize, &block) ⇒ Object
insert.
- #inspect ⇒ Object
-
#int16 ⇒ Object
(also: #short)
(Conversion) Short-Hand of “CArray#to_type(:int16)”.
-
#int32 ⇒ Object
(also: #int)
(Conversion) Short-Hand of “CArray#to_type(:int32)”.
-
#int64 ⇒ Object
(Conversion) Short-Hand of “CArray#to_type(:int64)”.
-
#int8 ⇒ Object
(Conversion) Short-Hand of “CArray#to_type(:int8)”.
-
#integer? ⇒ Boolean
(Inquiry) Returns true if
selfis integer type array. -
#invert_mask ⇒ Object
(Masking, Destructive) Inverts mask state.
- #is_close(other, atol) ⇒ Object
- #is_divisible(n) ⇒ Object
- #is_equiv(other, rtol) ⇒ Object
-
#is_masked ⇒ Object
(Masking, Element-Wise Inquiry) Returns new boolean type array of same shape with
self. - #is_not_divisible(n) ⇒ Object
-
#is_not_masked ⇒ Object
(Masking, Element-Wise Inquiry) Returns new boolean type array of same shape with
self. - #is_real ⇒ Object
-
#join(*argv) ⇒ Object
Array#join like method.
- #last ⇒ Object
-
#elements ⇒ Object
(Attribute) Returns the number of elements.
-
#load_binary(io) ⇒ Object
(IO) Loads the value array from the given IO stream.
-
#map(&block) ⇒ Object
Returns map.
-
#map!({|elem| ... }) ⇒ Object
(Iterator, Destructive) Iterates all elements of the object and stores the return from the block to the element.
-
#map_addr!({|addr| ... }) ⇒ Object
[TBD].
-
#map_index!({|idx| ... }) ⇒ Object
[TBD].
-
#map_with_addr!({|elem, addr| ... }) ⇒ Object
[TBD].
-
#map_with_index({|elem, idx| ... }) ⇒ Object
[TBD].
-
#marshal_dump ⇒ Object
for Marshal.
- #marshal_load(data) ⇒ Object
-
#mask ⇒ Object
(Masking, Inquiry) Returns new array which refers the mask state of
self. -
#mask=(new_mask) ⇒ Object
(Mask, Modification) Asigns
new_maskto the mask array ofself. -
#mask_array? ⇒ Boolean
(Inquiry) Returns true if
selfis mask array (don’t confuse with “masked array”). - #maskout(*argv) ⇒ Object
- #maskout!(*argv) ⇒ Object
-
#matchup(ref) ⇒ Object
matchup.
- #matchup_nearest(ref, direction: "round") ⇒ Object
- #max_by(&block) ⇒ Object
- #max_with(*others) ⇒ Object
- #median(*argv) ⇒ Object
-
#members ⇒ Object
(Inquiry) Returns data class member names.
- #min_by(&block) ⇒ Object
- #min_with(*others) ⇒ Object
-
#mul_add(weight, min_count = nil, fill_value = nil) ⇒ Object
[TBD].
-
#ndim ⇒ Object
(Attribute) Returns the rank (e.g. 1 for 1D array, 3 for 3D array, …).
- #nlargest(n) ⇒ Object
- #nlargest_addr(n) ⇒ Object
- #none_close? ⇒ Boolean
- #none_equal? ⇒ Boolean
- #none_equiv? ⇒ Boolean
-
#normalize_index ⇒ Object
yard: class CArray def normalize_index (idx) end end.
- #nsmallest(n) ⇒ Object
- #nsmallest_addr(n) ⇒ Object
-
#numeric? ⇒ Boolean
(Inquiry) Returns true if
selfis numeric type array. -
#obj_type ⇒ Object
(Attribute) Returns the object type (e.g. CA_OBJ_ARRAY, CA_OBJ_BLOCK, …).
-
#object ⇒ Object
(Conversion) Short-Hand of “CArray#to_type(:object)”.
-
#object? ⇒ Boolean
(Inquiry) Returns true if
selfis object type array. - #order(dir = 1) ⇒ Object
-
#parent ⇒ Object
(Attribute) Returns the parent carray if
selfhas parent, or returns nil ifselfhas no parent. -
#paste(idx, ary) ⇒ Object
(Copy) Pastes
arytoselfat the indexidx. - #percentile(*argv) ⇒ Object
-
#project(idx, lval = nil, uval = nil) ⇒ Object
[TBD].
- #pull(*args) ⇒ Object
-
#pulled(*args) ⇒ Object
pulled.
- #quantile ⇒ Object
- #quantize ⇒ Object
- #quo(other) ⇒ Object
- #rad_2pi ⇒ Object
- #rad_2pi! ⇒ Object
- #rad_pi ⇒ Object
- #rad_pi! ⇒ Object
-
#random(*argv) ⇒ Object
statistics.
- #randomn ⇒ Object
- #randomn! ⇒ Object
- #range ⇒ Object
-
#ndim ⇒ Object
(Attribute) Returns the rank (e.g. 1 for 1D array, 3 for 3D array, …).
-
#read_only? ⇒ Boolean
(Inquiry) Returns true if the object is read-only.
-
#real ⇒ Object
Return the real part of
self. - #real=(val) ⇒ Object
- #real? ⇒ Boolean
- #recurrence(*argv, &block) ⇒ Object
- #recurrence!(init = {}, &block) ⇒ Object
-
#refer ⇒ Object
yard: class CArray # call-seq: # CArray.refer() # CArray.refer(data_type, dim[, :bytes=>bytes, :offset=>offset]) # CArray.refer(data_class, dim) # # Returns CARefer object which refers self.
- #replace_value(from, to) ⇒ Object
-
#reshape(*newdim) ⇒ Object
reshape.
-
#resize(*newdim, &block) ⇒ Object
Returns the array resized to the dimension given as
newdim. -
#reverse ⇒ Object
Returns a new CArray object containing ca’s elements in reverse order.
-
#reverse! ⇒ Object
Reverses the elements of
cain place. -
#reversed ⇒ Object
reversed.
- #roll(*argv) ⇒ Object
- #roll!(*argv) ⇒ Object
- #rolled(*argv) ⇒ Object
-
#root_array ⇒ Object
(Attribute) Returns the object at the root of chain of reference.
-
#rotate(*argv) ⇒ Object
:nodoc:.
-
#rotate!(*argv) ⇒ Object
:nodoc:.
-
#rotated(*argv) ⇒ Object
:nodoc:.
-
#has_same_shape? ⇒ Boolean
(Inquiry) Returns true if the object has the same shape with the given array.
-
#save_binary(filename, opt = {}) ⇒ Object
:nodoc:.
-
#save_binary_io(io, opt = {}) ⇒ Object
:nodoc:.
- #save_by_magick(filename, image_type = nil, options = "") ⇒ Object
-
#scalar? ⇒ Boolean
(Inquiry) Returns true if the object is a CScalar.
- #scale(xa, xb) ⇒ Object
- #scale!(xa, xb) ⇒ Object
-
#search ⇒ Object
[TBD].
-
#search_index ⇒ Object
[TBD].
-
#search_nearest ⇒ Object
[TBD].
-
#search_nearest_index ⇒ Object
[TBD].
-
#select(&block) ⇒ Object
:nodoc:.
-
#seq(init_val = 0, step = 1{|elem| ... }) ⇒ Object
(Conversion) Generates sequential data with initial value
init_valand step valuestep. -
#seq!(init_val = 0, step = 1{|elem| ... }) ⇒ Object
(Conversion, Destructive) Generates sequential data with initial value
init_valand step valuestep. -
#set(*idx) ⇒ Object
(Boolean, Modification) Sets true at the given index for the boolean array and returns self.
-
#dim ⇒ Object
(Attribute) Returns the Array object contains the dimensional shape of array (e.g. [2,3] for 2D 2x3 array, …).
- #shift(*argv, &block) ⇒ Object
-
#shift!(*argv, &block) ⇒ Object
roll / shift.
-
#shifted ⇒ Object
yard: class CArray def shifted end end.
- #sign ⇒ Object
-
#elements ⇒ Object
(Attribute) Returns the number of elements.
-
#sort ⇒ Object
Returns a new CArray object containing ca’s elements sorted.
-
#sort! ⇒ Object
Sorts ca’s elements in place.
-
#sort_addr(*args) ⇒ Object
(Sort) Returns index table for index sort This method same as,.
-
#sort_by(type = nil, opt = {}, &block) ⇒ Object
Returns the array which elements are sorted by the comparison method given as block.
- #sort_with(*others) ⇒ Object
-
#sorted_by(type = nil, opt = {}, &block) ⇒ Object
Returns the reference which elements are sorted by the comparison method given as block.
- #sorted_with(*others) ⇒ Object
- #span(range) ⇒ Object
- #span!(range) ⇒ Object
-
#split(*argv) ⇒ Object
Returns object carray has elements of splitted carray at dimensions which is given by arguments.
- #st ⇒ Object
- #str_bytesize ⇒ Object
- #str_capitalize ⇒ Object
- #str_center(*args) ⇒ Object
- #str_chomp(*args) ⇒ Object
- #str_chop ⇒ Object
- #str_chr ⇒ Object
- #str_clear ⇒ Object
- #str_count(*args) ⇒ Object
- #str_delete(*args) ⇒ Object
- #str_delete_prefix(prefix) ⇒ Object
- #str_delete_suffix(suffix) ⇒ Object
- #str_downcase ⇒ Object
- #str_dump ⇒ Object
- #str_encode(*args) ⇒ Object
- #str_encoding ⇒ Object
- #str_extract(regexp, replace = '\0') ⇒ Object
- #str_force_encoding(encoding) ⇒ Object
-
#str_format(*fmts) ⇒ Object
(Conversion) Creates object type array consist of string using the “::format” method.
- #str_gsub(*args, &block) ⇒ Object
- #str_includes(substr) ⇒ Object (also: #str_contains)
- #str_index(*args) ⇒ Object
- #str_intern ⇒ Object
- #str_is_empty ⇒ Object
- #str_is_end_with(*args) ⇒ Object
- #str_is_start_with(*args) ⇒ Object
- #str_len ⇒ Object
- #str_ljust(*args) ⇒ Object
- #str_lstrip ⇒ Object
- #str_matches(*args) ⇒ Object
- #str_rindex(*args) ⇒ Object
- #str_rjust(*args) ⇒ Object
- #str_rstrip ⇒ Object
- #str_scrub ⇒ Object
- #str_size ⇒ Object
- #str_strip ⇒ Object
-
#str_strptime(fmt) ⇒ Object
(Conversion) Creates object type array consist of Time objects which are created by ‘Time.strptime’ applied to the elements of the object.
- #str_sub(*args, &block) ⇒ Object
- #str_swapcase ⇒ Object
- #str_to_datetime(template = nil) ⇒ Object
- #str_to_f ⇒ Object
- #str_to_i ⇒ Object
- #str_to_r ⇒ Object
- #str_to_time(template = nil) ⇒ Object
- #str_upcase ⇒ Object
-
#swap_bytes ⇒ Object
(Conversion) Swaps the byte order of each element.
-
#swap_bytes! ⇒ Object
(Conversion, Destructive) Swaps the byte order of each element.
-
#t ⇒ Object
yard: class CArray # create the virtual transposed array which dimension order is reversed.
-
#template(data_type = self.data_type, bytes: 0) ⇒ Object
(Copy) Returns CArray object with same dimension with
selfThe data type of the new carray object can be specified bydata_type. - #test(&block) ⇒ Object
- #test_ca_to_cptr ⇒ Object
- #time_ajd ⇒ Object
- #time_day ⇒ Object
- #time_format(template = nil) ⇒ Object
- #time_hour ⇒ Object
- #time_is_leap ⇒ Object
- #time_jd ⇒ Object
- #time_minute ⇒ Object
- #time_month ⇒ Object
- #time_second ⇒ Object
-
#time_strptime(fmt) ⇒ Object
(Conversion) Creates object type array consist of strings which are created by ‘Time#strftime’ applied to the elements of the object.
- #time_year ⇒ Object
-
#to_a ⇒ Object
(Conversion) Converts the array to Ruby’s array.
-
#to_binary(io = "", opt = {}) ⇒ Object
:nodoc:.
- #to_bit_string(nb) ⇒ Object
-
#to_ca ⇒ Object
(Copy) Creates CArray object from
selfwith same contents includes mask state. -
#to_column ⇒ Object
Returns (n,1) array from 1-dimensional array.
-
#to_row ⇒ Object
Returns (1,n) array from 1-dimensional array.
-
#to_s ⇒ Object
(Conversion) Dumps the value array to a string.
-
#to_type(data_type, bytes: nil) ⇒ Object
(Conversion) Returns an array of elements that are converted to the given data type from the object.
-
#transform(type, dim, opt = {}) ⇒ Object
:nodoc:.
- #transpose(*argv) ⇒ Object
- #transpose!(*argv) ⇒ Object
-
#transposed ⇒ Object
yard: class CArray def transposed end end.
-
#trim(min, max, fill_value = nil) ⇒ Object
(Conversion) Trims the data into the range between min and max.
-
#trim!(min, max, fill_value = nil) ⇒ Object
(Conversion) Trims the data into the range between min and max.
-
#true ⇒ Object
Returns the 8-bit integer CArray object filled with 1 which dimension size is same as
self. -
#uint16 ⇒ Object
(Conversion) Short-Hand of “CArray#to_type(:uint16)”.
-
#uint32 ⇒ Object
(Conversion) Short-Hand of “CArray#to_type(:uint32)”.
-
#uint64 ⇒ Object
(Conversion) Short-Hand of “CArray#to_type(:uint64)”.
-
#uint8 ⇒ Object
(also: #byte)
(Conversion) Short-Hand of “CArray#to_type(:uint8)”.
- #unbound_repeat ⇒ Object
-
#uniq ⇒ Object
Returns the array eliminated all the duplicated elements.
-
#unmask(fill_value = nil) ⇒ Object
(Masking, Destructive) Unmask all elements of the object.
-
#unmask_copy(fill_value = nil) ⇒ Object
(Masking, Conversion) Returns new unmasked array.
-
#unset(*idx) ⇒ Object
(Boolean, Modification) Sets false at the given index for the boolean array and returns self.
-
#unsigned? ⇒ Boolean
(Inquiry) Return true if
selfis unsigned integer type array. -
#valid_addr?(*addr) ⇒ Boolean
(Inquiry) Returns true if the given number is valid as array address for the object.
-
#valid_index?(*idx) ⇒ Boolean
(Inquiry) Returns true if the given number list is valid as array index for the object.
-
#value ⇒ Object
(Masking, Inquiry) Returns new array which refers the data of
self. -
#value_array? ⇒ Boolean
(Inquiry) Returns true if
selfis a value array. - #variance ⇒ Object
- #variancep ⇒ Object
-
#virtual? ⇒ Boolean
(Inquiry) Returns true if
selfis a virtural array (not an entity array). -
#where ⇒ Object
(Conversion) Returns the 1d index array for non-zero elements of self.
- #where_range ⇒ Object
-
#window ⇒ Object
yard: class CArray def window (*argv) end end.
-
#window_iterator(*argv) ⇒ Object
:nodoc:.
- #windows(*args, &block) ⇒ Object
- #wmean ⇒ Object
- #wsum ⇒ Object
Methods included from DataTypeExtension
arange, eye, full, identity, linspace, ones, zeros
Constructor Details
#initialize(data_type, dim, bytes = 0) ⇒ Object
Constructs a new CArray object of data_type, which has the ndim and the dimensions specified by an Array of Integer or an argument list of Integer. The byte size of each element for the fixed length data type (data_type == CA_FIXLEN) is specified optional argument bytes. Otherwise, this optional argument has no effect. If the block is given, the new CArray object will be initialized by the value returned from the block.
721 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 750 751 752 753 754 |
# File 'ext/ca_obj_array.c', line 721
static VALUE
rb_ca_initialize (int argc, VALUE *argv, VALUE self)
{
volatile VALUE rtype, rdim, ropt, rbytes = Qnil;
CArray *ca;
int8_t data_type, ndim;
ca_size_t dim[CA_RANK_MAX];
ca_size_t bytes;
int8_t i;
rb_scan_args(argc, argv, "21", (VALUE *)&rtype, (VALUE *) &rdim, (VALUE *) &ropt);
rb_scan_options(ropt, "bytes", &rbytes);
rb_ca_guess_type_and_bytes(rtype, rbytes, &data_type, &bytes);
rb_ca_data_type_import(self, rtype);
Check_Type(rdim, T_ARRAY);
ndim = RARRAY_LEN(rdim);
for (i=0; i<ndim; i++) {
dim[i] = NUM2SIZE(rb_ary_entry(rdim, i));
}
Data_Get_Struct(self, CArray, ca);
carray_safe_setup(ca, data_type, ndim, dim, bytes, NULL);
if ( rb_block_given_p() ) {
volatile VALUE rval = rb_yield(self);
if ( rval != self ) {
rb_ca_store_all(self, rval);
}
}
return Qnil;
}
|
Class Method Details
.__new__(type, *args) ⇒ Object
Create new CArray object from the return value of the block with data type type. The dimensional size and the initialization value are guessed from the return value of the block. The block should return one of the following objects.
-
Numeric
-
Array
-
CArray
-
an object that has either method
to_caorto_aormap
When the return value of the block is a Numeric or CScalar object, CScalar object is returned.
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/carray/construct.rb', line 114 def self.__new__ (type, *args) # :nodoc: case v = args.first when CArray return ( v.data_type == type ) ? v.to_ca : v.to_type(type) when Array return CArray.new(type, CArray.guess_array_shape(v)) { v } when Range return CArray.span(type, *args) when String if type == CA_OBJECT return CScalar.new(CA_OBJECT) { v } elsif type == CA_BOOLEAN v = v.dup v.tr!('^01',"1") v.tr!('01',"\x0\x1") return CArray.boolean(v.length).load_binary(v) else case v when /;/ v = v.strip.split(/\s*;\s*/). map{|s| s.split(/\s+|\s*,\s*/).map{|x| x=='_' ? UNDEF : x} } else v = v.strip.split(/\s+|\s*,\s*/).map{|x| x=='_' ? UNDEF : x} end return CArray.new(type, CArray.guess_array_shape(v)) { v } end when NilClass return CArray.new(type, [0]) else if v.respond_to?(:to_ca) ca = v.to_ca return ( ca.data_type == type ) ? ca : ca.to_type(type) else return CScalar.new(type) { v } end end end |
.__new_fixlen__(bytes, v) ⇒ Object
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/carray/construct.rb', line 153 def self.__new_fixlen__ (bytes, v) # :nodoc: case v when CArray return ( v.data_type == :fixlen ) ? v.to_ca : v.to_type(:fixlen, :bytes=>bytes) when Array unless bytes bytes = v.map{|s| s.length}.max end return CArray.new(:fixlen, CArray.guess_array_shape(v), :bytes=>bytes) { v } when NilClass return CArray.new(type, [0]) else if v.respond_to?(:to_ca) ca = v.to_ca return ( ca.data_type == :fixlen ) ? ca : ca.to_type(:fixlen, :bytes=>bytes) else return CScalar.new(:fixlen, :bytes=>bytes) { v } end end end |
.scan_float(str, fill_value = nil) ⇒ Object
428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 |
# File 'ext/carray_utils.c', line 428
static VALUE
rb_ca_s_scan_float (int argc, VALUE *argv, VALUE self)
{
volatile VALUE rstr, rfval;
double value;
int count;
rb_scan_args(argc, argv, "11", (VALUE *)&rstr, (VALUE *)&rfval);
if ( NIL_P(rstr) ) {
return ( NIL_P(rfval) ) ? rb_float_new(0.0/0.0) : rfval;
}
Check_Type(rstr, T_STRING);
count = sscanf(StringValuePtr(rstr), "%lf", &value);
if ( count == 1 ) {
return rb_float_new(value);
}
else {
return ( NIL_P(rfval) ) ? rb_float_new(0.0/0.0) : rfval;
}
}
|
.scan_int(str, fill_value = nil) ⇒ Object
458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 |
# File 'ext/carray_utils.c', line 458
static VALUE
rb_ca_s_scan_int (int argc, VALUE *argv, VALUE self)
{
volatile VALUE rstr, rfval;
long value;
int count;
rb_scan_args(argc, argv, "11", (VALUE *) &rstr, (VALUE *) &rfval);
if ( NIL_P(rstr) ) {
return ( NIL_P(rfval) ) ? INT2NUM(0) : rfval;
}
Check_Type(rstr, T_STRING);
count = sscanf(StringValuePtr(rstr), "%li", &value);
if ( count == 1 ) {
return SIZE2NUM(value);
}
else {
return ( NIL_P(rfval) ) ? INT2NUM(0) : rfval;
}
}
|
.attach(*arrays) ⇒ Object
(Internal) Guarantees that the reference memory block is attached. The memory block is detached at the end of the block evaluation. It is not ensured the syncing the memory block at the end of the block evaluation.
1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 |
# File 'ext/carray_core.c', line 1008
static VALUE
rb_ca_s_attach (int argc, VALUE *argv, VALUE self)
{
volatile VALUE list, obj;
int i;
list = rb_ary_new4(argc, argv);
for (i=0; i<RARRAY_LEN(list); i++) {
obj = rb_ary_entry(list, i);
rb_ca_attach_i(obj);
}
return rb_ensure(rb_yield_splat, list, rb_ca_s_ensure_detach, list);
}
|
.attach!(*arrays) ⇒ Object
(Internal) Guarantees that the reference memory block is attached. The memory block is detached at the end of the block evaluation. It is ensured the syncing the memory block at the end of the block evaluation.
1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 |
# File 'ext/carray_core.c', line 1048
static VALUE
rb_ca_s_attach_bang (int argc, VALUE *argv, VALUE self)
{
volatile VALUE list, obj;
int i;
list = rb_ary_new4(argc, argv);
for (i=0; i<RARRAY_LEN(list); i++) {
obj = rb_ary_entry(list, i);
rb_ca_modify(obj);
rb_ca_attach_i(obj);
}
return rb_ensure(rb_yield_splat, list, rb_ca_s_ensure_sync_detach, list);
}
|
.big_endian? ⇒ Boolean
(Inquiry) Returns true if the byte order of the architecture is big endian.
33 34 35 36 37 |
# File 'ext/carray_class.c', line 33
static VALUE
rb_ca_s_big_endian_p (VALUE klass)
{
return ( ca_endian == CA_BIG_ENDIAN ) ? Qtrue : Qfalse;
}
|
.bind(data_type, list, at = 0) ⇒ Object
181 182 183 |
# File 'lib/carray/compose.rb', line 181 def self.bind (data_type, list, at = 0) return CArray.combine(data_type, [list.size], list, at) end |
.boolean(*dim) ⇒ Object
(Construction) Short-Hand of ‘CArray.new(:boolean, dim, bytes: bytes) { … }`
789 790 791 792 |
# File 'ext/ca_obj_array.c', line 789
static VALUE rb_ca_s_boolean (int argc, VALUE *argv, VALUE klass)
{
rb_ca_s_body(CA_BOOLEAN);
}
|
.broadcast(*argv) ⇒ Object
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/carray/broadcast.rb', line 36 def CArray.broadcast (*argv) sel = argv.select {|arg| arg.is_a?(CArray) } return argv if sel.empty? dim = [] ndim = sel.map(&:ndim).max ndim.times do |k| dim[k] = sel.map{|arg| arg.dim[k] || 1 }.max end return argv.map{|arg| arg.is_a?(CArray) ? arg.broadcast_to(*dim) : arg } end |
.uint8(*dim) ⇒ Object
(Construction) Short-Hand of ‘CArray.new(:uint8, dim, bytes: bytes) { … }`
809 810 811 812 |
# File 'ext/ca_obj_array.c', line 809
static VALUE rb_ca_s_uint8 (int argc, VALUE *argv, VALUE klass)
{
rb_ca_s_body(CA_UINT8);
}
|
.cast(value) ⇒ Object
- TBD
1016 1017 1018 1019 1020 |
# File 'ext/carray_cast.c', line 1016
static VALUE
rb_ca_s_cast (VALUE klass, VALUE val)
{
return rb_ca_cast(val);
}
|
.cast_self_or_other(other) ⇒ Object
- TBD
1176 1177 1178 1179 1180 1181 |
# File 'ext/carray_cast.c', line 1176
VALUE
rb_ca_s_cast_self_or_other (VALUE klass, VALUE self, VALUE other)
{
rb_ca_cast_self_or_other(&self, &other);
return rb_assoc_new(self, other);
}
|
.cmplx128(*dim) ⇒ Object
(Construction) Short-Hand of ‘CArray.new(:cmplx128, dim, bytes: bytes) { … }`
920 921 922 923 |
# File 'ext/ca_obj_array.c', line 920
static VALUE rb_ca_s_cmplx128 (int argc, VALUE *argv, VALUE klass)
{
rb_ca_s_body(CA_CMPLX128);
}
|
.cmplx256(*dim) ⇒ Object
(Construction) Short-Hand of ‘CArray.new(:cmplx256, dim, bytes: bytes) { … }`
930 931 932 933 |
# File 'ext/ca_obj_array.c', line 930
static VALUE rb_ca_s_cmplx256 (int argc, VALUE *argv, VALUE klass)
{
rb_ca_s_body(CA_CMPLX256);
}
|
.cmplx64(*dim) ⇒ Object
(Construction) Short-Hand of ‘CArray.new(:cmplx64, dim, bytes: bytes) { … }`
910 911 912 913 |
# File 'ext/ca_obj_array.c', line 910
static VALUE rb_ca_s_cmplx64 (int argc, VALUE *argv, VALUE klass)
{
rb_ca_s_body(CA_CMPLX64);
}
|
.combine(data_type, tdim, list, at = 0) ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/carray/compose.rb', line 117 def self.combine (data_type, tdim, list, at = 0) has_fill_value = false if block_given? fill_value = yield has_fill_value = true end if not tdim.is_a?(Array) or tdim.size == 0 raise "invalid binding dimension" end if not list.is_a?(Array) or list.size == 0 raise "invalid list" end list = list.map{|x| CArray.wrap_readonly(x, data_type) } ref = list.detect{|x| x.is_a?(CArray) or not x.scalar? } unless ref raise "at least one element in list should be a carray" end dim = ref.dim ndim = ref.ndim tndim = tdim.size if at < 0 at += ndim - tndim + 1 end unless at.between?(0, ndim - tndim) raise "concatnating position out of range" end list.map! do |x| if x.scalar? rdim = dim.clone rdim[at] = :% x = x[*rdim] # convert CScalar to CARepeat end x end block = CArray.object(*tdim){ list } edim = tdim.clone idx = Array.new(tdim) offset = Array.new(tdim.size) { [] } tdim.each_with_index do |td, i| edim[i] = 0 idx.map!{0} idx[i] = nil block[*idx].each do |e| offset[i] << edim[i] edim[i] += e.dim[at+i] # extended dimension size end end newdim = dim.clone newdim[at,tndim] = edim # extended dimension size if has_fill_value obj = CArray.new(data_type, newdim) { fill_value } else obj = CArray.new(data_type, newdim) end idx = newdim.map{0} block.each_with_index do |item, tidx| (at...at+tndim).each_with_index do |d,i| idx[d] = offset[i][tidx[i]] end obj.paste(idx, item) end obj end |
.cmplx64(*dim) ⇒ Object
(Construction) Short-Hand of ‘CArray.new(:cmplx64, dim, bytes: bytes) { … }`
910 911 912 913 |
# File 'ext/ca_obj_array.c', line 910
static VALUE rb_ca_s_cmplx64 (int argc, VALUE *argv, VALUE klass)
{
rb_ca_s_body(CA_CMPLX64);
}
|
.composite(data_type, tdim, list, at = 0) ⇒ Object
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
# File 'lib/carray/compose.rb', line 185 def self.composite (data_type, tdim, list, at = 0) if not tdim.is_a?(Array) or tdim.size == 0 raise "invalid tiling dimension" end if not list.is_a?(Array) or list.size == 0 raise "invalid carray list" end list = list.map{|x| CArray.wrap_readonly(x, data_type) } ref = list.detect{|x| x.is_a?(CArray) or not x.scalar? } unless ref raise "at least one element in list should be a carray" end dim = ref.dim ndim = ref.ndim if at < 0 at += ndim + 1 # "+ 1" is needed here end unless at.between?(0,ndim) raise "tiling position is out of range" end tndim = tdim.size list.map! do |x| if x.scalar? rdim = dim.clone rdim[at] = :% x = x[*rdim] # convert CScalar to CARepeat end x end newdim = dim.clone newdim[at,0] = tdim obj = CArray.new(data_type, newdim) idx = Array.new(ndim+tndim) { nil } CArray.each_index(*tdim) do |*tidx| idx[at,tndim] = tidx obj[*idx] = list.shift end obj end |
.data_type?(data_type) ⇒ Boolean
(Inquiry) Returns true if the given data_type indicate the valid data_type.
79 80 81 82 83 84 85 86 87 88 |
# File 'ext/carray_class.c', line 79
static VALUE
rb_ca_s_data_type (VALUE klass, VALUE rtype)
{
int8_t data_type = rb_ca_guess_type(rtype);
if ( data_type <= CA_NONE || data_type >= CA_NTYPE ) {
rb_raise(rb_eArgError,
"data type is out of range (%i..%i)", CA_NONE+1, CA_NTYPE-1);
}
return ca_valid[data_type] == 1 ? Qtrue : Qfalse;
}
|
.data_type_name(data_type) ⇒ Object
(Inquiry) Returns string representaion of the data_type specifier.
97 98 99 100 101 102 103 |
# File 'ext/carray_class.c', line 97
static VALUE
rb_ca_s_data_type_name (VALUE klass, VALUE type)
{
int8_t data_type = NUM2INT(type);
CA_CHECK_DATA_TYPE(data_type);
return rb_str_new2(ca_type_name[data_type]);
}
|
.cmplx128(*dim) ⇒ Object
(Construction) Short-Hand of ‘CArray.new(:cmplx128, dim, bytes: bytes) { … }`
920 921 922 923 |
# File 'ext/ca_obj_array.c', line 920
static VALUE rb_ca_s_cmplx128 (int argc, VALUE *argv, VALUE klass)
{
rb_ca_s_body(CA_CMPLX128);
}
|
.float64(*dim) ⇒ Object
(Construction) Short-Hand of ‘CArray.new(:float64, dim, bytes: bytes) { … }`
889 890 891 892 |
# File 'ext/ca_obj_array.c', line 889
static VALUE rb_ca_s_float64 (int argc, VALUE *argv, VALUE klass)
{
rb_ca_s_body(CA_FLOAT64);
}
|
.dump(ca, opt = {}) ⇒ Object
212 213 214 215 216 |
# File 'lib/carray/serialize.rb', line 212 def self.dump (ca, opt={}) io = StringIO.new("") Serializer.new(io).save(ca, opt) return io.string end |
.each_index(*shape) ⇒ Object
(Iterator) Iterates with the multi-dimensional indeces for the given dimension numbers.
CArray.each_index(3,2){|i,j| print "(#{i} #{j}) " }
produces:
(0 0) (0 1) (1 0) (1 1) (2 0) (2 1) (3 0) (3 1)
54 55 56 57 58 59 60 61 62 |
# File 'ext/carray_loop.c', line 54
static VALUE
rb_ca_s_each_index (int ndim, VALUE *dim, VALUE self)
{
volatile VALUE ridx = rb_ary_new2(ndim);
#if RUBY_VERSION_CODE >= 190
RETURN_ENUMERATOR(self, ndim, dim);
#endif
return rb_ca_s_each_index_internal(ndim, dim, 0, ridx);
}
|
.endian ⇒ Object
(Inquiry) Returns the machine endianness.
0 (CA_LITTLE_ENDIAN)
1 (CA_BIG_ENDIAN)
21 22 23 24 25 |
# File 'ext/carray_class.c', line 21
static VALUE
rb_ca_s_endian (VALUE klass)
{
return INT2NUM(ca_endian);
}
|
.fixlen(*dim, bytes: ) ⇒ Object
(Construction) Short-Hand of ‘CArray.new(:fixlen, dim, bytes: ) { … }`
762 763 764 765 766 767 768 769 |
# File 'ext/ca_obj_array.c', line 762
static VALUE
rb_ca_s_fixlen (int argc, VALUE *argv, VALUE klass)
{
volatile VALUE ropt = rb_pop_options(&argc, &argv);
volatile VALUE rdim = rb_ary_new4(argc, argv);
VALUE args[3] = { INT2NUM(CA_FIXLEN), rdim, ropt };
return rb_class_new_instance(3, args, klass);
}
|
.float32(*dim) ⇒ Object
(Construction) Short-Hand of ‘CArray.new(:float32, dim, bytes: bytes) { … }`
879 880 881 882 |
# File 'ext/ca_obj_array.c', line 879
static VALUE rb_ca_s_float32 (int argc, VALUE *argv, VALUE klass)
{
rb_ca_s_body(CA_FLOAT32);
}
|
.float128(*dim) ⇒ Object
(Construction) Short-Hand of ‘CArray.new(:float128, dim, bytes: bytes) { … }`
899 900 901 902 |
# File 'ext/ca_obj_array.c', line 899
static VALUE rb_ca_s_float128 (int argc, VALUE *argv, VALUE klass)
{
rb_ca_s_body(CA_FLOAT128);
}
|
.float32(*dim) ⇒ Object
(Construction) Short-Hand of ‘CArray.new(:float32, dim, bytes: bytes) { … }`
879 880 881 882 |
# File 'ext/ca_obj_array.c', line 879
static VALUE rb_ca_s_float32 (int argc, VALUE *argv, VALUE klass)
{
rb_ca_s_body(CA_FLOAT32);
}
|
.float64(*dim) ⇒ Object
(Construction) Short-Hand of ‘CArray.new(:float64, dim, bytes: bytes) { … }`
889 890 891 892 |
# File 'ext/ca_obj_array.c', line 889
static VALUE rb_ca_s_float64 (int argc, VALUE *argv, VALUE klass)
{
rb_ca_s_body(CA_FLOAT64);
}
|
.from_binary(io, opt = {}) ⇒ Object
:nodoc:
119 120 121 122 |
# File 'lib/carray/obsolete.rb', line 119 def self.from_binary (io, opt={}) # :nodoc: warn "CArray.from_binary will be obsolete, use CArray.load" return Serializer.new(io).load(opt) end |
.from_bit_string(bstr, nb, data_type = CA_INT32, dim = nil) ⇒ Object
104 105 106 107 108 109 110 111 112 113 |
# File 'lib/carray/convert.rb', line 104 def self.from_bit_string (bstr, nb, data_type=CA_INT32, dim=nil) if dim obj = CArray.new(data_type, dim) else dim0 = ((bstr.length*8)/nb.to_f).floor obj = CArray.new(data_type, [dim0]) end obj.from_bit_string(bstr, nb) return obj end |
.gc_interval ⇒ Object
Returns the threshold of incremented memory (MB) used by carray object until start GC.
66 67 68 69 70 |
# File 'ext/ca_obj_array.c', line 66
static VALUE
rb_ca_get_gc_interval (VALUE self)
{
return rb_float_new(ca_gc_interval);
}
|
.gc_interval= ⇒ Object
Sets the threshold of incremented memory (MB) used by carray object until start GC.
77 78 79 80 81 82 83 84 85 86 |
# File 'ext/ca_obj_array.c', line 77
static VALUE
rb_ca_set_gc_interval (VALUE self, VALUE rth)
{
double th = NUM2INT(rth);
if ( th <= 0 ) {
th = 0;
}
ca_gc_interval = th;
return rb_float_new(ca_gc_interval);
}
|
.guess_array_shape ⇒ Object
yard:
def CArray.guess_array_shape (arg)
end
299 300 301 302 303 304 305 306 307 308 309 310 311 312 |
# File 'ext/carray_access.c', line 299
static VALUE
rb_ca_s_guess_array_shape (VALUE self, VALUE ary)
{
volatile VALUE out;
ca_size_t dim[CA_RANK_MAX];
int max_level = -1;
int i;
ary_guess_shape(ary, 0, &max_level, dim);
out = rb_ary_new2(max_level);
for (i=0; i<max_level+1; i++) {
rb_ary_store(out, i, SIZE2NUM(dim[i]));
}
return out;
}
|
.guess_type_and_bytes ⇒ Object
580 581 582 583 584 585 586 587 588 589 |
# File 'ext/carray_utils.c', line 580
static VALUE
rb_ca_s_guess_type_and_bytes (int argc, VALUE *argv, VALUE klass)
{
VALUE rtype, rbytes;
int8_t data_type;
ca_size_t bytes;
rb_scan_args(argc, argv, "11", (VALUE *) &rtype, (VALUE *) &rbytes);
rb_ca_guess_type_and_bytes(rtype, rbytes, &data_type, &bytes);
return rb_assoc_new(INT2NUM(data_type), SIZE2NUM(bytes));
}
|
.int32(*dim) ⇒ Object
(Construction) Short-Hand of ‘CArray.new(:int32, dim, bytes: bytes) { … }`
839 840 841 842 |
# File 'ext/ca_obj_array.c', line 839
static VALUE rb_ca_s_int32 (int argc, VALUE *argv, VALUE klass)
{
rb_ca_s_body(CA_INT32);
}
|
.int16(*dim) ⇒ Object
(Construction) Short-Hand of ‘CArray.new(:int16, dim, bytes: bytes) { … }`
819 820 821 822 |
# File 'ext/ca_obj_array.c', line 819
static VALUE rb_ca_s_int16 (int argc, VALUE *argv, VALUE klass)
{
rb_ca_s_body(CA_INT16);
}
|
.int32(*dim) ⇒ Object
(Construction) Short-Hand of ‘CArray.new(:int32, dim, bytes: bytes) { … }`
839 840 841 842 |
# File 'ext/ca_obj_array.c', line 839
static VALUE rb_ca_s_int32 (int argc, VALUE *argv, VALUE klass)
{
rb_ca_s_body(CA_INT32);
}
|
.int64(*dim) ⇒ Object
(Construction) Short-Hand of ‘CArray.new(:int64, dim, bytes: bytes) { … }`
859 860 861 862 |
# File 'ext/ca_obj_array.c', line 859
static VALUE rb_ca_s_int64 (int argc, VALUE *argv, VALUE klass)
{
rb_ca_s_body(CA_INT64);
}
|
.int8(*dim) ⇒ Object
(Construction) Short-Hand of ‘CArray.new(:int8, dim, bytes: bytes) { … }`
799 800 801 802 |
# File 'ext/ca_obj_array.c', line 799
static VALUE rb_ca_s_int8 (int argc, VALUE *argv, VALUE klass)
{
rb_ca_s_body(CA_INT8);
}
|
.join(*argv) ⇒ Object
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 |
# File 'lib/carray/compose.rb', line 229 def self.join (*argv) # get options case argv.first when Integer, Symbol, String type, = *CArray.guess_type_and_bytes(argv.shift, 0) else type = argv.flatten.first.data_type end # process conc = argv.map do |list| case list when CArray if list.ndim == 1 list[:%,1] else list end when Array x0 = list.first if list.size == 1 and x0.is_a?(CArray) and x0.ndim == 1 list = [x0[:%,1]] else list = list.map { |x| case x when CArray if x.ndim == 1 x[:%,1] else x end when Array y = x.first if x.size == 1 and y.is_a?(CArray) and y.ndim == 1 y[1,:%] else CArray.join(*x) end else x end } end if block_given? CArray.bind(type, list, 1, &block) else CArray.bind(type, list, 1) end else list end end if conc.size > 1 return CArray.bind(type, conc) else return conc.first end end |
.little_endian? ⇒ Boolean
(Inquiry) Returns true if the byte order of the architecture is little endian.
46 47 48 49 50 |
# File 'ext/carray_class.c', line 46
static VALUE
rb_ca_s_little_endian_p (VALUE klass)
{
return ( ca_endian == CA_LITTLE_ENDIAN ) ? Qtrue : Qfalse;
}
|
.load(input, opt = {}) ⇒ Object
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 |
# File 'lib/carray/serialize.rb', line 196 def self.load (input, opt={}) case input when String if input.length >= 256 and input =~ /\A_CARRAY_.{8}_(LE|BE)_/ io = StringIO.new(input) return Serializer.new(io).load(opt) else open(input, "rb:ASCII-8BIT") { |io| return Serializer.new(io).load(opt) } end else return Serializer.new(input).load(opt) end end |
.load_binary(filename, opt = {}) ⇒ Object
:nodoc:
96 97 98 99 100 101 |
# File 'lib/carray/obsolete.rb', line 96 def self.load_binary (filename, opt={}) # :nodoc: warn "CArray.load_binary will be obsolete, use CArray.load" open(filename) { |io| return Serializer.new(io).load(opt) } end |
.load_binary_io(io, opt = {}) ⇒ Object
:nodoc:
108 109 110 111 |
# File 'lib/carray/obsolete.rb', line 108 def self.load_binary_io (io, opt={}) # :nodoc: warn "CArray#load_binary_io will be obsolete, use CArray.load" return Serializer.new(io).load(opt) end |
.load_by_magick(filename, imap = "rgb", data_type = nil) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 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 |
# File 'lib/carray/io/imagemagick.rb', line 48 def self.load_by_magick (filename, imap = "rgb", data_type = nil) if not File.exist?(filename) raise "can't find image file '#{filename}'" end identify_command = [ "identify", "-format " + "'" + [ "---", "height: %h", "width: %w", "depth: %z", ].join("\n") + "'", filename, "2>/dev/null" ].join(" ") ident = YAML.load(`#{identify_command}`) if ident.empty? raise "ImageMagick's identify command failed to read image file '#{filename}'" end height, width, depth = ident.values_at('height', 'width', 'depth') unless data_type case depth when 8 data_type = CA_UINT8 when 16 data_type = CA_UINT16 when 32 data_type = CA_UINT32 end end storage_type = case data_type when CA_UINT8, CA_INT8 "char" when CA_UINT16, CA_INT16 "short" when CA_UINT32, CA_INT32 "integer" when CA_FLOAT32 "float" when CA_FLOAT64 "double" else raise "invalid data_type" end tempfile = "CA_Magick_#{$$}_#{@@magick_tempfile_count}.dat" @@magick_tempfile_count += 1 stream_command = [ "stream", "-storage-type #{storage_type}", "-map #{imap}", filename, tempfile, "2>/dev/null" ].join(" ") begin system stream_command return open(tempfile) { |io| if imap.size == 1 CArray.new(data_type, [height, width]).load_binary(io) else CArray.new(data_type, [height, width, imap.size]).load_binary(io) end } rescue raise "ImageMagick's stream command failed to read image file '#{filename}'" ensure if File.exist?(tempfile) File.unlink(tempfile) end end end |
.mem_usage ⇒ Object
1301 1302 1303 1304 1305 |
# File 'ext/ca_obj_array.c', line 1301
static VALUE
rb_ca_mem_usage (VALUE self)
{
return rb_float_new(ca_mem_usage);
}
|
.merge(data_type, list, at = -1)) ⇒ Object
225 226 227 |
# File 'lib/carray/compose.rb', line 225 def self.merge (data_type, list, at = -1) return CArray.composite(data_type, [list.size], list, at) end |
.meshgrid(*args) ⇒ Object
451 452 453 454 455 456 457 458 459 460 |
# File 'lib/carray/construct.rb', line 451 def self.meshgrid (*args) dim = args.map(&:size) out = [] args.each_with_index do |arg, i| newdim = dim.dup newdim[i] = :% out[i] = arg[*newdim].to_ca end return *out end |
.object(*dim) ⇒ Object
(Construction) Short-Hand of ‘CArray.new(:object, dim, bytes: bytes) { … }`
941 942 943 944 |
# File 'ext/ca_obj_array.c', line 941
static VALUE rb_ca_s_VALUE (int argc, VALUE *argv, VALUE klass)
{
rb_ca_s_body(CA_OBJECT);
}
|
.pack(*argv) ⇒ Object
98 99 100 |
# File 'lib/carray/object/ca_obj_pack.rb', line 98 def self.pack (*argv) return CAPack.new(argv) end |
.pickup(data_type, ref, args) ⇒ Object
a = CArray.int(3,3).seq(1)
b = CArray.int(3,3).seq(11)
c = CArray.int(3,3).seq(21)
CArray.pickup(CA_OBJECT, ref, [a,b,c])
=> <CArray.object(3,3): elem=9 mem=72b
[ [ 1, 12, 23 ],
[ 14, 25, 6 ],
[ 27, 8, 19 ] ]>
CArray.pickup(CA_OBJECT, ref, ["a","b","c"])
=> <CArray.object(3,3): elem=9 mem=36b
[ [ "a", "b", "c" ],
[ "b", "c", "a" ],
[ "c", "a", "b" ] ]>
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/carray/convert.rb', line 47 def self.pickup (data_type, ref, args) out = ref.template(data_type) args.each_with_index do |v, i| s = ref.eq(i) case v when CArray out[s] = v[s] else out[s] = v end end return out end |
.reset_gc_interval ⇒ Object
Reset the counter for the GC start when the incremented memory get larger than CArray.gc_interval.
93 94 95 96 97 98 |
# File 'ext/ca_obj_array.c', line 93
static VALUE
rb_ca_reset_gc_interval (VALUE self)
{
ca_gc_interval = ca_default_gc_interval;
return rb_float_new(ca_gc_interval);
}
|
.save(ca, output, opt = {}) ⇒ Object
185 186 187 188 189 190 191 192 193 194 |
# File 'lib/carray/serialize.rb', line 185 def self.save(ca, output, opt={}) case output when String open(output, "wb:ASCII-8BIT") { |io| return Serializer.new(io).save(ca, opt) } else return Serializer.new(output).save(ca, opt) end end |
.scan_index ⇒ Object
yard:
def CArray.scan_index(dim, idx)
end
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 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 |
# File 'ext/carray_access.c', line 1584
static VALUE
rb_ca_s_scan_index (VALUE self, VALUE rdim, VALUE ridx)
{
volatile VALUE rtype, rndim, rindex;
CAIndexInfo info;
int ndim;
ca_size_t dim[CA_RANK_MAX];
ca_size_t elements;
int i;
Check_Type(rdim, T_ARRAY);
Check_Type(ridx, T_ARRAY);
elements = 1;
ndim = (int) RARRAY_LEN(rdim);
for (i=0; i<ndim; i++) {
dim[i] = NUM2SIZE(rb_ary_entry(rdim, i));
elements *= dim[i];
}
CA_CHECK_RANK(ndim);
CA_CHECK_DIM(ndim, dim);
info.range_check = 1;
rb_ca_scan_index(ndim, dim, elements,
RARRAY_LEN(ridx), RARRAY_PTR(ridx), &info);
rtype = INT2NUM(info.type);
rndim = INT2NUM(info.ndim);
rindex = rb_ary_new2(info.ndim);
switch ( info.type ) {
case CA_REG_NONE:
case CA_REG_ALL:
break;
case CA_REG_ADDRESS:
rb_ary_store(rindex, 0, SIZE2NUM(info.index[0].scalar));
break;
case CA_REG_FLATTEN:
break;
case CA_REG_ADDRESS_COMPLEX: {
volatile VALUE rinfo;
ca_size_t elements = 1;
for (i=0; i<ndim; i++) {
elements *= dim[i];
}
rinfo = rb_ca_s_scan_index(self, rb_ary_new3(1, SIZE2NUM(elements)), ridx);
rtype = INT2NUM(CA_REG_ADDRESS_COMPLEX);
rindex = rb_struct_aref(rinfo, rb_str_new2("index"));
break;
}
case CA_REG_POINT:
for (i=0; i<ndim; i++) {
rb_ary_store(rindex, i, SIZE2NUM(info.index[i].scalar));
}
break;
case CA_REG_SELECT:
break;
case CA_REG_BLOCK:
case CA_REG_ITERATOR:
for (i=0; i<ndim; i++) {
switch ( info.index_type[i] ) {
case CA_IDX_SCALAR:
rb_ary_store(rindex, i, SIZE2NUM(info.index[i].scalar));
break;
case CA_IDX_ALL:
rb_ary_store(rindex, i,
rb_ary_new3(3,
INT2NUM(0),
rb_ary_entry(rdim, i),
INT2NUM(1)));
break;
case CA_IDX_BLOCK:
rb_ary_store(rindex, i,
rb_ary_new3(3,
SIZE2NUM(info.index[i].block.start),
SIZE2NUM(info.index[i].block.count),
SIZE2NUM(info.index[i].block.step)));
break;
case CA_IDX_SYMBOL:
rb_ary_store(rindex, i,
rb_ary_new3(2,
ID2SYM(info.index[i].symbol.id),
info.index[i].symbol.spec));
break;
default:
rb_raise(rb_eRuntimeError, "unknown index spec");
}
}
break;
case CA_REG_REPEAT:
case CA_REG_GRID:
case CA_REG_MAPPING:
case CA_REG_METHOD_CALL:
case CA_REG_UNBOUND_REPEAT:
case CA_REG_MEMBER:
case CA_REG_ATTRIBUTE:
break;
default:
rb_raise(rb_eArgError, "unknown index specification");
}
return rb_struct_new(S_CAInfo, rtype, rindex);
}
|
.int16(*dim) ⇒ Object
(Construction) Short-Hand of ‘CArray.new(:int16, dim, bytes: bytes) { … }`
819 820 821 822 |
# File 'ext/ca_obj_array.c', line 819
static VALUE rb_ca_s_int16 (int argc, VALUE *argv, VALUE klass)
{
rb_ca_s_body(CA_INT16);
}
|
.sizeof(data_type) ⇒ Object
63 64 65 66 67 68 69 70 |
# File 'ext/carray_class.c', line 63
static VALUE
rb_ca_s_sizeof (VALUE klass, VALUE rtype)
{
int8_t data_type;
ca_size_t bytes;
rb_ca_guess_type_and_bytes(rtype, INT2NUM(0), &data_type, &bytes);
return SIZE2NUM(bytes);
}
|
.span(*argv) ⇒ Object
CArray.span(data_type, range[, step]) CArray.span(range[, step]) -> data_type guessed by range.first type
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/carray/construct.rb', line 20 def self.span (*argv) if argv.first.is_a?(Range) type = nil else type, = *CArray.guess_type_and_bytes(argv.shift, nil) end range, step = argv[0], argv[1] start, stop = range.begin, range.end if step == 0 raise "step should not be 0" end if not type case start when Integer type = CA_INT32 when Float type = CA_FLOAT64 else type = CA_OBJECT end end if type == CA_OBJECT and not step return CA_OBJECT(range.to_a) else step ||= 1 if range.exclude_end? n = ((stop - start).abs/step).floor else n = ((stop - start).abs/step).floor + 1 end if start <= stop return CArray.new(type, [n]).seq(start, step) else return CArray.new(type, [n]).seq(start, -step.abs) end end end |
.summation(*dim) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/carray/obsolete.rb', line 64 def self.summation (*dim) warn "CArray.summation will be obsolete" out = nil first = true CArray.each_index(*dim) { |*idx| if first out = yield(*idx) first = false else out += yield(*idx) end } return out end |
.uint16(*dim) ⇒ Object
(Construction) Short-Hand of ‘CArray.new(:uint16, dim, bytes: bytes) { … }`
829 830 831 832 |
# File 'ext/ca_obj_array.c', line 829
static VALUE rb_ca_s_uint16 (int argc, VALUE *argv, VALUE klass)
{
rb_ca_s_body(CA_UINT16);
}
|
.uint32(*dim) ⇒ Object
(Construction) Short-Hand of ‘CArray.new(:uint32, dim, bytes: bytes) { … }`
849 850 851 852 |
# File 'ext/ca_obj_array.c', line 849
static VALUE rb_ca_s_uint32 (int argc, VALUE *argv, VALUE klass)
{
rb_ca_s_body(CA_UINT32);
}
|
.uint64(*dim) ⇒ Object
(Construction) Short-Hand of ‘CArray.new(:uint64, dim, bytes: bytes) { … }`
869 870 871 872 |
# File 'ext/ca_obj_array.c', line 869
static VALUE rb_ca_s_uint64 (int argc, VALUE *argv, VALUE klass)
{
rb_ca_s_body(CA_UINT64);
}
|
.uint8(*dim) ⇒ Object
(Construction) Short-Hand of ‘CArray.new(:uint8, dim, bytes: bytes) { … }`
809 810 811 812 |
# File 'ext/ca_obj_array.c', line 809
static VALUE rb_ca_s_uint8 (int argc, VALUE *argv, VALUE klass)
{
rb_ca_s_body(CA_UINT8);
}
|
.wrap(data_type, dim, bytes = 0{ target }) ⇒ Object
- TBD
-
(Construction)
target should have method “wrap_as_carray(obj)”
973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 |
# File 'ext/ca_obj_array.c', line 973
static VALUE
rb_ca_s_wrap (int argc, VALUE *argv, VALUE self)
{
volatile VALUE obj, target, rtype, rdim, ropt, rbytes = Qnil;
CArray *ca;
int8_t data_type, ndim;
ca_size_t dim[CA_RANK_MAX];
ca_size_t bytes;
int8_t i;
rb_scan_args(argc, argv, "21", (VALUE *) &rtype, (VALUE *) &rdim, (VALUE *) &ropt);
rb_scan_options(ropt, "bytes", &rbytes);
rb_ca_guess_type_and_bytes(rtype, rbytes, &data_type, &bytes);
Check_Type(rdim, T_ARRAY);
ndim = RARRAY_LEN(rdim);
for (i=0; i<ndim; i++) {
dim[i] = NUM2SIZE(rb_ary_entry(rdim, i));
}
target = rb_yield_values(0);
obj = Data_Make_Struct(rb_cCAWrap, CAWrap, ca_mark, ca_free, ca);
ca_wrap_setup_null(ca, data_type, ndim, dim, bytes, NULL);
rb_funcall(target, rb_intern("wrap_as_carray"), 1, obj);
rb_ivar_set(obj, rb_intern("referred_object"), target);
return obj;
}
|
.wrap_readonly(other, date_type = nil) ⇒ Object
- TBD
965 966 967 968 969 970 971 |
# File 'ext/carray_cast.c', line 965
static VALUE
rb_ca_s_wrap_readonly (int argc, VALUE *argv, VALUE klass)
{
volatile VALUE obj, rtype;
rb_scan_args(argc, argv, "11", (VALUE *) &obj, (VALUE *) &rtype);
return rb_ca_wrap_readonly(obj, rtype);
}
|
.wrap_writable(other, date_type = nil) ⇒ Object
- TBD
842 843 844 845 846 847 848 |
# File 'ext/carray_cast.c', line 842
static VALUE
rb_ca_s_wrap_writable (int argc, VALUE *argv, VALUE klass)
{
volatile VALUE obj, rtype;
rb_scan_args(argc, argv, "11", (VALUE *) &obj, (VALUE *) &rtype);
return rb_ca_wrap_writable(obj, rtype);
}
|
Instance Method Details
#<=>(other) ⇒ Object Also known as: cmp
comparison operators
83 84 85 86 87 88 89 90 |
# File 'lib/carray/math.rb', line 83 def <=> (other) lower = self < other upper = self > other out = CArray.new(CA_INT8, lower.dim) out[lower] = -1 out[upper] = 1 return out end |
#==(other) ⇒ Object Also known as: eql?
(Inquiry) Returns true if the object equals the given array.
457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 |
# File 'ext/carray_test.c', line 457
static VALUE
rb_ca_equal (VALUE self, VALUE other)
{
CArray *ca, *cb;
if ( ! rb_obj_is_carray(other) ) { /* check kind_of?(CArray) */
return Qfalse;
}
if ( rb_ca_has_data_class(self) || rb_ca_has_data_class(other) ) {
if ( rb_ca_has_data_class(self) ^ rb_ca_has_data_class(other) ) {
return Qfalse;
}
else {
VALUE dc1 = rb_ca_data_class(self);
VALUE dc2 = rb_ca_data_class(other);
if ( ! rb_funcall(dc1, rb_intern("=="), 1, dc2) ) {
return Qfalse;
}
}
}
Data_Get_Struct(self, CArray, ca);
Data_Get_Struct(other, CArray, cb);
return ( ca_equal(ca, cb) ) ? Qtrue : Qfalse;
}
|
#[] ⇒ Object
yard:
class CArray
def [] (*spec)
end
end
1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 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 |
# File 'ext/carray_access.c', line 1271
static VALUE
rb_ca_fetch_method (int argc, VALUE *argv, VALUE self)
{
volatile VALUE obj = Qnil;
CArray *ca;
CAIndexInfo info;
retry:
Data_Get_Struct(self, CArray, ca);
info.range_check = 1;
rb_ca_scan_index(ca->ndim, ca->dim, ca->elements, argc, argv, &info);
switch ( info.type ) {
case CA_REG_ADDRESS_COMPLEX:
self = rb_ca_refer_new_flatten(self);
goto retry;
case CA_REG_ADDRESS:
obj = rb_ca_ref_address(self, &info);
break;
case CA_REG_FLATTEN:
obj = rb_ca_refer_new_flatten(self);
break;
case CA_REG_POINT:
obj = rb_ca_ref_point(self, &info);
break;
case CA_REG_ALL:
obj = rb_ca_ref_all(self, &info);
break;
case CA_REG_BLOCK:
obj = rb_ca_ref_block(self, &info);
break;
case CA_REG_SELECT:
obj = rb_ca_select_new(self, argv[0]);
break;
case CA_REG_ITERATOR:
obj = rb_dim_iter_new(self, &info);
break;
case CA_REG_REPEAT:
obj = rb_ca_repeat(argc, argv, self);
break;
case CA_REG_UNBOUND_REPEAT:
obj = rb_funcall2(self, rb_intern("unbound_repeat"), (int) argc, argv);
break;
case CA_REG_MAPPING:
obj = rb_ca_mapping(argc, argv, self);
break;
case CA_REG_GRID:
obj = rb_ca_grid(argc, argv, self);
break;
case CA_REG_METHOD_CALL: {
volatile VALUE idx;
idx = rb_funcall2(self, SYM2ID(info.symbol), argc-1, argv+1);
obj = rb_ca_fetch(self, idx);
break;
}
case CA_REG_MEMBER: {
volatile VALUE data_class = rb_ca_data_class(self);
if ( ! NIL_P(data_class) ) {
obj = rb_ca_field_as_member(self, info.symbol);
break;
}
else {
rb_raise(rb_eIndexError,
"can't refer member of carray doesn't have data_class");
}
break;
}
case CA_REG_ATTRIBUTE: {
obj = rb_funcall(self, rb_intern("attribute"), 0);
obj = rb_hash_aref(obj, info.symbol);
break;
}
default:
rb_raise(rb_eIndexError, "invalid index specified");
}
return obj;
}
|
#[]= ⇒ Object
yard:
class CArray
def []= (*spec)
end
end
1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 |
# File 'ext/carray_access.c', line 1438
static VALUE
rb_ca_store_method (int argc, VALUE *argv, VALUE self)
{
volatile VALUE obj = Qnil, rval;
CArray *ca;
CAIndexInfo info;
rb_ca_modify(self);
obj = rval = argv[argc-1];
argc -= 1;
retry:
Data_Get_Struct(self, CArray, ca);
info.range_check = 1;
rb_ca_scan_index(ca->ndim, ca->dim, ca->elements, argc, argv, &info);
switch ( info.type ) {
case CA_REG_ADDRESS_COMPLEX:
self = rb_ca_refer_new_flatten(self);
goto retry;
case CA_REG_ADDRESS:
obj = rb_ca_store_address(self, &info, rval);
break;
case CA_REG_FLATTEN:
self = rb_ca_refer_new_flatten(self);
obj = rb_ca_store_all(self, rval);
break;
case CA_REG_POINT:
obj = rb_ca_store_point(self, &info, rval);
break;
case CA_REG_ALL:
obj = rb_ca_store_all(self, rval);
break;
case CA_REG_BLOCK: {
volatile VALUE block;
block = rb_ca_ref_block(self, &info);
obj = rb_ca_store_all(block, rval);
break;
}
case CA_REG_SELECT: {
obj = rb_ca_select_new(self, argv[0]);
obj = rb_ca_store_all(obj, rval);
break;
}
case CA_REG_ITERATOR: {
obj = rb_dim_iter_new(self, &info);
obj = rb_funcall(obj, rb_intern("asign!"), 1, rval);
break;
}
case CA_REG_REPEAT: {
obj = rb_ca_repeat(argc, argv, self);
obj = rb_ca_store_all(obj, rval);
break;
}
case CA_REG_UNBOUND_REPEAT:
obj = rb_funcall2(self, rb_intern("unbound_repeat"), (int) argc, argv);
obj = rb_ca_store_all(obj, rval);
break;
case CA_REG_MAPPING: {
obj = rb_ca_mapping(argc, argv, self);
obj = rb_ca_store_all(obj, rval);
break;
}
case CA_REG_GRID: {
obj = rb_ca_grid(argc, argv, self);
obj = rb_ca_store_all(obj, rval);
break;
}
case CA_REG_METHOD_CALL: {
volatile VALUE idx;
Data_Get_Struct(self, CArray, ca);
ca_attach(ca);
idx = rb_funcall2(self, SYM2ID(info.symbol), (int)(argc-1), argv+1);
obj = rb_ca_store(self, idx, rval);
ca_detach(ca);
break;
}
case CA_REG_MEMBER: {
volatile VALUE data_class = rb_ca_data_class(self);
if ( ! NIL_P(data_class) ) {
obj = rb_ca_field_as_member(self, info.symbol);
obj = rb_ca_store_all(obj, rval);
}
else {
rb_raise(rb_eIndexError,
"can't store member of carray doesn't have data_class");
}
break;
}
case CA_REG_ATTRIBUTE: {
obj = rb_funcall(self, rb_intern("attribute"), 0);
obj = rb_hash_aset(obj, info.symbol, rval);
break;
}
}
return obj;
}
|
#__attach__ ⇒ Object
(Internal, DevelopperOnly) Attaches the reference memory block. User must call “CArray#__detach__” appropreate timing.
1119 1120 1121 1122 1123 1124 |
# File 'ext/carray_core.c', line 1119
static VALUE
rb_ca__attach__ (VALUE self)
{
rb_ca_attach_i(self);
return self;
}
|
#__detach__ ⇒ Object
(Internal, DevelopperOnly) Detaches the reference memory block.
1144 1145 1146 1147 1148 1149 |
# File 'ext/carray_core.c', line 1144
static VALUE
rb_ca__detach__ (VALUE self)
{
rb_ca_detach_i(self);
return self;
}
|
#__detach__ ⇒ Object
(Internal, DevelopperOnly) Syncs the reference memory block to the parent array.
1131 1132 1133 1134 1135 1136 1137 |
# File 'ext/carray_core.c', line 1131
static VALUE
rb_ca__sync__ (VALUE self)
{
rb_ca_modify(self);
rb_ca_sync_i(self);
return self;
}
|
#addr2index ⇒ Object
yard:
class CArray
# converts addr to index
def addr2index (addr)
end
end
1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 |
# File 'ext/carray_access.c', line 1770
VALUE
rb_ca_addr2index (VALUE self, VALUE raddr)
{
volatile VALUE out;
CArray *ca;
ca_size_t *dim;
ca_size_t addr;
int i;
Data_Get_Struct(self, CArray, ca);
addr = NUM2SIZE(raddr);
if ( addr < 0 || addr >= ca->elements ) {
rb_raise(rb_eArgError,
"address %lld is out of range (0..%lld)",
(ca_size_t) addr, (ca_size_t) (ca->elements-1));
}
dim = ca->dim;
out = rb_ary_new2(ca->ndim);
for (i=ca->ndim-1; i>=0; i--) { /* in descending order */
rb_ary_store(out, i, SIZE2NUM(addr % dim[i]));
addr /= dim[i];
}
return out;
}
|
#address ⇒ Object
index / indices / axes
115 116 117 |
# File 'lib/carray/basic.rb', line 115 def address () return CArray.int32(*dim).seq! end |
#all_close? ⇒ Boolean
1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 |
# File 'ext/carray_stat.c', line 1555
static VALUE
rb_ca_all_close_p (int argc, VALUE *argv, VALUE self)
{
volatile VALUE value, aeps;
volatile VALUE flag = Qtrue;
CArray *ca;
rb_scan_args(argc, argv, "2", (VALUE *) &value, (VALUE *) &aeps);
Data_Get_Struct(self, CArray, ca);
ca_attach(ca);
switch ( ca->data_type ) {
case CA_BOOLEAN:
case CA_INT8: proc_all_close(int8_t,NUM2LONG,fabs); break;
case CA_UINT8: proc_all_close(uint8_t,NUM2ULONG,fabs); break;
case CA_INT16: proc_all_close(int16_t,NUM2LONG,fabs); break;
case CA_UINT16: proc_all_close(uint16_t,NUM2ULONG,fabs); break;
case CA_INT32: proc_all_close(int32_t,NUM2LONG,fabs); break;
case CA_UINT32: proc_all_close(uint32_t,NUM2ULONG,fabs); break;
case CA_INT64: proc_all_close(int64_t,NUM2LL,fabs); break;
case CA_UINT64: proc_all_close(uint64_t,NUM2ULL,fabs); break;
case CA_FLOAT32: proc_all_close(float32_t,NUM2DBL,fabs); break;
case CA_FLOAT64: proc_all_close(float64_t,NUM2DBL,fabs); break;
case CA_FLOAT128: proc_all_close(float128_t,NUM2DBL,fabs); break;
#ifdef HAVE_COMPLEX_H
case CA_CMPLX64: proc_all_close(cmplx64_t,NUM2CC,cabs); break;
case CA_CMPLX128: proc_all_close(cmplx128_t,NUM2CC,cabs); break;
case CA_CMPLX256: proc_all_close(cmplx256_t,NUM2CC,cabs); break;
#endif
default: rb_raise(rb_eCADataTypeError, "invalid data type");
}
ca_detach(ca);
return flag;
}
|
#all_equal? ⇒ Boolean
1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 |
# File 'ext/carray_stat.c', line 1414
static VALUE
rb_ca_all_equal_p (int argc, VALUE *argv, VALUE self)
{
volatile VALUE value;
volatile VALUE flag = Qtrue;
CArray *ca;
rb_scan_args(argc, argv, "1", (VALUE *) &value);
Data_Get_Struct(self, CArray, ca);
ca_attach(ca);
switch ( ca->data_type ) {
case CA_FIXLEN: proc_all_equal_data(); break;
case CA_BOOLEAN:
case CA_INT8: proc_all_equal(int8_t,NUM2LONG); break;
case CA_UINT8: proc_all_equal(uint8_t,NUM2ULONG); break;
case CA_INT16: proc_all_equal(int16_t,NUM2LONG); break;
case CA_UINT16: proc_all_equal(uint16_t,NUM2ULONG); break;
case CA_INT32: proc_all_equal(int32_t,NUM2LONG); break;
case CA_UINT32: proc_all_equal(uint32_t,NUM2ULONG); break;
case CA_INT64: proc_all_equal(int64_t,NUM2LL); break;
case CA_UINT64: proc_all_equal(uint64_t,NUM2ULL); break;
case CA_FLOAT32: proc_all_equal(float32_t,NUM2DBL); break;
case CA_FLOAT64: proc_all_equal(float64_t,NUM2DBL); break;
case CA_FLOAT128: proc_all_equal(float128_t,NUM2DBL); break;
#ifdef HAVE_COMPLEX_H
case CA_CMPLX64: proc_all_equal(cmplx64_t,NUM2CC); break;
case CA_CMPLX128: proc_all_equal(cmplx128_t,NUM2CC); break;
case CA_CMPLX256: proc_all_equal(cmplx256_t,NUM2CC); break;
#endif
case CA_OBJECT: proc_all_equal_object(); break;
default: rb_raise(rb_eCADataTypeError, "invalid data type");
}
ca_detach(ca);
return flag;
}
|
#all_equiv? ⇒ Boolean
1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 |
# File 'ext/carray_stat.c', line 1487
static VALUE
rb_ca_all_equiv_p (int argc, VALUE *argv, VALUE self)
{
volatile VALUE value, reps;
volatile VALUE flag = Qtrue;
CArray *ca;
rb_scan_args(argc, argv, "2", (VALUE *) &value, (VALUE *) &reps);
Data_Get_Struct(self, CArray, ca);
ca_attach(ca);
switch ( ca->data_type ) {
case CA_BOOLEAN:
case CA_INT8: proc_all_equiv(int8_t,NUM2LONG,fabs); break;
case CA_UINT8: proc_all_equiv(uint8_t,NUM2ULONG,fabs); break;
case CA_INT16: proc_all_equiv(int16_t,NUM2LONG,fabs); break;
case CA_UINT16: proc_all_equiv(uint16_t,NUM2ULONG,fabs); break;
case CA_INT32: proc_all_equiv(int32_t,NUM2LONG,fabs); break;
case CA_UINT32: proc_all_equiv(uint32_t,NUM2ULONG,fabs); break;
case CA_INT64: proc_all_equiv(int64_t,NUM2LL,fabs); break;
case CA_UINT64: proc_all_equiv(uint64_t,NUM2ULL,fabs); break;
case CA_FLOAT32: proc_all_equiv(float32_t,NUM2DBL,fabs); break;
case CA_FLOAT64: proc_all_equiv(float64_t,NUM2DBL,fabs); break;
case CA_FLOAT128: proc_all_equiv(float128_t,NUM2DBL,fabs); break;
#ifdef HAVE_COMPLEX_H
case CA_CMPLX64: proc_all_equiv(cmplx64_t,NUM2CC,cabs); break;
case CA_CMPLX128: proc_all_equiv(cmplx128_t,NUM2CC,cabs); break;
case CA_CMPLX256: proc_all_equiv(cmplx256_t,NUM2CC,cabs); break;
#endif
default: rb_raise(rb_eCADataTypeError, "invalid data type");
}
ca_detach(ca);
return flag;
}
|
#all_masked? ⇒ Boolean
(Masking, Inquiry) Returns true if all elements of self are masked.
600 601 602 603 604 605 606 |
# File 'ext/carray_mask.c', line 600
VALUE
rb_ca_is_all_masked (VALUE self)
{
CArray *ca;
Data_Get_Struct(self, CArray, ca);
return ( ca_is_all_masked(ca) ) ? Qtrue : Qfalse;
}
|
#ancestors ⇒ Object
(Attribute) Returns the list of objects in the chain of reference.
789 790 791 792 793 794 795 796 797 |
# File 'ext/carray_attribute.c', line 789
static VALUE
rb_ca_ancestors (VALUE self)
{
volatile VALUE list;
CArray *ca;
Data_Get_Struct(self, CArray, ca);
list = rb_ary_new();
return rb_ca_ancestors_loop(self, list);
}
|
#anomaly(*argv) ⇒ Object Also known as: anom
227 228 229 230 231 232 233 234 235 |
# File 'lib/carray/math.rb', line 227 def anomaly (*argv) opt = argv.last.is_a?(Hash) ? argv.pop : {} idxs = Array.new(self.ndim) { |i| argv.include?(i) ? :* : nil } if mn = opt[:mean] return self - mn[*idxs] else return self - self.mean(*argv)[*idxs] end end |
#any_close? ⇒ Boolean
1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 |
# File 'ext/carray_stat.c', line 1808
static VALUE
rb_ca_any_close_p (int argc, VALUE *argv, VALUE self)
{
volatile VALUE value, aeps;
volatile VALUE flag = Qfalse;
CArray *ca;
rb_scan_args(argc, argv, "2", (VALUE *) &value, (VALUE *) &aeps);
Data_Get_Struct(self, CArray, ca);
ca_attach(ca);
switch ( ca->data_type ) {
case CA_BOOLEAN:
case CA_INT8: proc_any_close(int8_t,NUM2LONG,fabs); break;
case CA_UINT8: proc_any_close(uint8_t,NUM2ULONG,fabs); break;
case CA_INT16: proc_any_close(int16_t,NUM2LONG,fabs); break;
case CA_UINT16: proc_any_close(uint16_t,NUM2ULONG,fabs); break;
case CA_INT32: proc_any_close(int32_t,NUM2LONG,fabs); break;
case CA_UINT32: proc_any_close(uint32_t,NUM2ULONG,fabs); break;
case CA_INT64: proc_any_close(int64_t,NUM2LL,fabs); break;
case CA_UINT64: proc_any_close(uint64_t,NUM2ULL,fabs); break;
case CA_FLOAT32: proc_any_close(float32_t,NUM2DBL,fabs); break;
case CA_FLOAT64: proc_any_close(float64_t,NUM2DBL,fabs); break;
case CA_FLOAT128: proc_any_close(float128_t,NUM2DBL,fabsl); break;
#ifdef HAVE_COMPLEX_H
case CA_CMPLX64: proc_any_close(cmplx64_t,NUM2CC,cabs); break;
case CA_CMPLX128: proc_any_close(cmplx128_t,NUM2CC,cabs); break;
case CA_CMPLX256: proc_any_close(cmplx256_t,NUM2CC,cabsl); break;
#endif
default: rb_raise(rb_eCADataTypeError, "invalid data type");
}
ca_detach(ca);
return flag;
}
|
#any_equal? ⇒ Boolean
1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 |
# File 'ext/carray_stat.c', line 1667
static VALUE
rb_ca_any_equal_p (int argc, VALUE *argv, VALUE self)
{
volatile VALUE value;
volatile VALUE flag = Qfalse;
CArray *ca;
rb_scan_args(argc, argv, "1", (VALUE *) &value);
Data_Get_Struct(self, CArray, ca);
ca_attach(ca);
switch ( ca->data_type ) {
case CA_FIXLEN: proc_any_equal_data(); break;
case CA_BOOLEAN:
case CA_INT8: proc_any_equal(int8_t,NUM2LONG); break;
case CA_UINT8: proc_any_equal(uint8_t,NUM2ULONG); break;
case CA_INT16: proc_any_equal(int16_t,NUM2LONG); break;
case CA_UINT16: proc_any_equal(uint16_t,NUM2ULONG); break;
case CA_INT32: proc_any_equal(int32_t,NUM2LONG); break;
case CA_UINT32: proc_any_equal(uint32_t,NUM2ULONG); break;
case CA_INT64: proc_any_equal(int64_t,NUM2LL); break;
case CA_UINT64: proc_any_equal(uint64_t,NUM2ULL); break;
case CA_FLOAT32: proc_any_equal(float32_t,NUM2DBL); break;
case CA_FLOAT64: proc_any_equal(float64_t,NUM2DBL); break;
case CA_FLOAT128: proc_any_equal(float128_t,NUM2DBL); break;
#ifdef HAVE_COMPLEX_H
case CA_CMPLX64: proc_any_equal(cmplx64_t,NUM2CC); break;
case CA_CMPLX128: proc_any_equal(cmplx128_t,NUM2CC); break;
case CA_CMPLX256: proc_any_equal(cmplx256_t,NUM2CC); break;
#endif
case CA_OBJECT: proc_any_equal_object(); break;
default: rb_raise(rb_eCADataTypeError, "invalid data type");
}
ca_detach(ca);
return flag;
}
|
#any_equiv? ⇒ Boolean
1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 |
# File 'ext/carray_stat.c', line 1740
static VALUE
rb_ca_any_equiv_p (int argc, VALUE *argv, VALUE self)
{
volatile VALUE value, reps;
volatile VALUE flag = Qfalse;
CArray *ca;
rb_scan_args(argc, argv, "2", (VALUE *) &value, (VALUE *) &reps);
Data_Get_Struct(self, CArray, ca);
ca_attach(ca);
switch ( ca->data_type ) {
case CA_BOOLEAN:
case CA_INT8: proc_any_equiv(int8_t,NUM2LONG,fabs); break;
case CA_UINT8: proc_any_equiv(uint8_t,NUM2ULONG,fabs); break;
case CA_INT16: proc_any_equiv(int16_t,NUM2LONG,fabs); break;
case CA_UINT16: proc_any_equiv(uint16_t,NUM2ULONG,fabs); break;
case CA_INT32: proc_any_equiv(int32_t,NUM2LONG,fabs); break;
case CA_UINT32: proc_any_equiv(uint32_t,NUM2ULONG,fabs); break;
case CA_INT64: proc_any_equiv(int64_t,NUM2LL,fabs); break;
case CA_UINT64: proc_any_equiv(uint64_t,NUM2ULL,fabs); break;
case CA_FLOAT32: proc_any_equiv(float32_t,NUM2DBL,fabs); break;
case CA_FLOAT64: proc_any_equiv(float64_t,NUM2DBL,fabs); break;
case CA_FLOAT128: proc_any_equiv(float128_t,NUM2DBL,fabs); break;
#ifdef HAVE_COMPLEX_H
case CA_CMPLX64: proc_any_equiv(cmplx64_t,NUM2CC,cabs); break;
case CA_CMPLX128: proc_any_equiv(cmplx128_t,NUM2CC,cabs); break;
case CA_CMPLX256: proc_any_equiv(cmplx256_t,NUM2CC,cabs); break;
#endif
default: rb_raise(rb_eCADataTypeError, "invalid data type");
}
ca_detach(ca);
return flag;
}
|
#any_masked? ⇒ Boolean
(Masking, Inquiry) Returns true if self has at least one masked element.
586 587 588 589 590 591 592 |
# File 'ext/carray_mask.c', line 586
VALUE
rb_ca_is_any_masked (VALUE self)
{
CArray *ca;
Data_Get_Struct(self, CArray, ca);
return ( ca_is_any_masked(ca) ) ? Qtrue : Qfalse;
}
|
#arg ⇒ Object
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'ext/carray_numeric.c', line 161
static VALUE
rb_ca_arg (VALUE self)
{
volatile VALUE obj;
CArray *ca, *co;
Data_Get_Struct(self, CArray, ca);
co = carray_new(CA_FLOAT64, ca->ndim, ca->dim, 0, NULL);
obj = ca_wrap_struct(co);
if ( ca_has_mask(ca) ) {
ca_copy_mask_overlay(co, co->elements, 1, ca);
}
ca_attach(ca);
switch ( ca->data_type ) {
case CA_FLOAT32: proc_arg_cmplx(float32_t); break;
case CA_FLOAT64: proc_arg_cmplx(float64_t); break;
case CA_FLOAT128: proc_arg_cmplx(float128_t); break;
case CA_CMPLX64: proc_arg_cmplx(cmplx64_t); break;
case CA_CMPLX128: proc_arg_cmplx(cmplx128_t); break;
case CA_CMPLX256: proc_arg_cmplx(cmplx256_t); break;
default: rb_raise(rb_eRuntimeError, "invalid data type");
}
ca_detach(ca);
return obj;
}
|
#as_boolean ⇒ Object
(Reference) Short-Hand of ‘CArray#as_type(:boolean)`
581 582 583 584 |
# File 'ext/carray_cast.c', line 581
VALUE rb_ca_as_boolean (VALUE self)
{
rb_ca_as_type_method_body(CA_BOOLEAN);
}
|
#as_cmplx128 ⇒ Object Also known as: as_dcomplex
(Reference) Short-Hand of ‘CArray#as_type(:cmplx128)`
698 699 700 701 |
# File 'ext/carray_cast.c', line 698
VALUE rb_ca_as_cmplx128 (VALUE self)
{
rb_ca_as_type_method_body(CA_CMPLX128);
}
|
#as_cmplx256 ⇒ Object
(Reference) Short-Hand of ‘CArray#as_type(:cmplx256)`
707 708 709 710 |
# File 'ext/carray_cast.c', line 707
VALUE rb_ca_as_cmplx256 (VALUE self)
{
rb_ca_as_type_method_body(CA_CMPLX256);
}
|
#as_cmplx64 ⇒ Object Also known as: as_complex
(Reference) Short-Hand of ‘CArray#as_type(:cmplx64)`
689 690 691 692 |
# File 'ext/carray_cast.c', line 689
VALUE rb_ca_as_cmplx64 (VALUE self)
{
rb_ca_as_type_method_body(CA_CMPLX64);
}
|
#as_fixlen(bytes: nil) ⇒ Object
(Reference) Short-Hand of ‘CArray#as_type(:fixlen, bytes: nil)`
566 567 568 569 570 571 572 573 574 575 |
# File 'ext/carray_cast.c', line 566
VALUE
rb_ca_as_fixlen (int argc, VALUE *argv, VALUE self)
{
volatile VALUE rtype, ropt = rb_pop_options(&argc, &argv);
VALUE list[2];
rb_scan_args(argc, argv, "01", (VALUE *) &rtype);
list[0] = ( NIL_P(rtype) ) ? INT2NUM(CA_FIXLEN) : rtype;
list[1] = ropt;
return rb_ca_as_type_internal(2, list, self);
}
|
#as_float128 ⇒ Object
(Reference) Short-Hand of ‘CArray#as_type(:float128)`
680 681 682 683 |
# File 'ext/carray_cast.c', line 680
VALUE rb_ca_as_float128 (VALUE self)
{
rb_ca_as_type_method_body(CA_FLOAT128);
}
|
#as_float32 ⇒ Object Also known as: as_float
(Reference) Short-Hand of ‘CArray#as_type(:float32)`
662 663 664 665 |
# File 'ext/carray_cast.c', line 662
VALUE rb_ca_as_float32 (VALUE self)
{
rb_ca_as_type_method_body(CA_FLOAT32);
}
|
#as_float64 ⇒ Object Also known as: as_double
(Reference) Short-Hand of ‘CArray#as_type(:float64)`
671 672 673 674 |
# File 'ext/carray_cast.c', line 671
VALUE rb_ca_as_float64 (VALUE self)
{
rb_ca_as_type_method_body(CA_FLOAT64);
}
|
#as_int16 ⇒ Object Also known as: as_short
(Reference) Short-Hand of ‘CArray#as_type(:int16)`
608 609 610 611 |
# File 'ext/carray_cast.c', line 608
VALUE rb_ca_as_int16 (VALUE self)
{
rb_ca_as_type_method_body(CA_INT16);
}
|
#as_int32 ⇒ Object Also known as: as_int
(Reference) Short-Hand of ‘CArray#as_type(:int32)`
626 627 628 629 |
# File 'ext/carray_cast.c', line 626
VALUE rb_ca_as_int32 (VALUE self)
{
rb_ca_as_type_method_body(CA_INT32);
}
|
#as_int64 ⇒ Object
(Reference) Short-Hand of ‘CArray#as_type(:int64)`
644 645 646 647 |
# File 'ext/carray_cast.c', line 644
VALUE rb_ca_as_int64 (VALUE self)
{
rb_ca_as_type_method_body(CA_INT64);
}
|
#as_int8 ⇒ Object
(Reference) Short-Hand of ‘CArray#as_type(:int8)`
590 591 592 593 |
# File 'ext/carray_cast.c', line 590
VALUE rb_ca_as_int8 (VALUE self)
{
rb_ca_as_type_method_body(CA_INT8);
}
|
#as_object ⇒ Object
(Reference) Short-Hand of ‘CArray#as_type(:object)`
716 717 718 719 |
# File 'ext/carray_cast.c', line 716
VALUE rb_ca_as_VALUE (VALUE self)
{
rb_ca_as_type_method_body(CA_OBJECT);
}
|
#as_type ⇒ Object
CArray#as_type
516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 |
# File 'ext/carray_cast.c', line 516
static VALUE
rb_ca_as_type_internal (int argc, VALUE *argv, VALUE self)
{
volatile VALUE obj, rtype = Qnil, ropt, rbytes = Qnil;
CArray *ca;
int8_t data_type;
ca_size_t bytes;
rb_scan_args(argc, argv, "11", (VALUE *) &rtype, (VALUE *) &ropt);
rb_scan_options(ropt, "bytes", &rbytes);
rb_ca_guess_type_and_bytes(rtype, rbytes, &data_type, &bytes);
Data_Get_Struct(self, CArray, ca);
if ( ca->data_type == data_type ) {
if ( ! ca_is_fixlen_type(ca) ) {
return self;
}
}
obj = rb_ca_fake_type(self, rtype, rbytes);
rb_ca_data_type_import(obj, rtype);
return obj;
}
|
#as_uint16 ⇒ Object
(Reference) Short-Hand of ‘CArray#as_type(:uint16)`
617 618 619 620 |
# File 'ext/carray_cast.c', line 617
VALUE rb_ca_as_uint16 (VALUE self)
{
rb_ca_as_type_method_body(CA_UINT16);
}
|
#as_uint32 ⇒ Object
(Reference) Short-Hand of ‘CArray#as_type(:uint32)`
635 636 637 638 |
# File 'ext/carray_cast.c', line 635
VALUE rb_ca_as_uint32 (VALUE self)
{
rb_ca_as_type_method_body(CA_UINT32);
}
|
#as_uint64 ⇒ Object
(Reference) Short-Hand of ‘CArray#as_type(:uint64)`
653 654 655 656 |
# File 'ext/carray_cast.c', line 653
VALUE rb_ca_as_uint64 (VALUE self)
{
rb_ca_as_type_method_body(CA_UINT64);
}
|
#as_uint8 ⇒ Object Also known as: as_byte
(Reference) Short-Hand of ‘CArray#as_type(:uint8)`
599 600 601 602 |
# File 'ext/carray_cast.c', line 599
VALUE rb_ca_as_uint8 (VALUE self)
{
rb_ca_as_type_method_body(CA_UINT8);
}
|
#asign(*idx) ⇒ Object
130 131 132 133 134 |
# File 'lib/carray/obsolete.rb', line 130 def asign (*idx) warn "CArray#asign will be obsolete" self[*idx] = yield return self end |
#attach ⇒ Object
(Internal) Guarantees that the reference memory block is attached. The memory block is detached at the end of the block evaluation. It is ensured the syncing the memory block at the end of the block evaluation.
1081 1082 1083 1084 1085 1086 |
# File 'ext/carray_core.c', line 1081
static VALUE
rb_ca_attach (VALUE self)
{
rb_ca_attach_i(self);
return rb_ensure(rb_yield, self, rb_ca_ensure_detach, self);
}
|
#attach! ⇒ Object
(Internal) Guarantees that the reference memory block is attached. The memory block is detached at the end of the block evaluation. It is ensured the syncing the memory block at the end of the block evaluation.
1105 1106 1107 1108 1109 1110 1111 |
# File 'ext/carray_core.c', line 1105
static VALUE
rb_ca_attach_bang (VALUE self)
{
rb_ca_modify(self);
rb_ca_attach_i(self);
return rb_ensure(rb_yield, self, rb_ca_ensure_sync_detach, self);
}
|
#attached? ⇒ Boolean
(Inquiry) Returns true if the object is attached.
264 265 266 267 268 269 270 |
# File 'ext/carray_attribute.c', line 264
VALUE
rb_ca_is_attached (VALUE self)
{
CArray *ca;
Data_Get_Struct(self, CArray, ca);
return ( ca_is_attached(ca) ) ? Qtrue : Qfalse;
}
|
#attribute ⇒ Object
82 83 84 85 |
# File 'lib/carray/basic.rb', line 82 def attribute @attribute ||= {} return @attribute end |
#attribute=(obj) ⇒ Object
75 76 77 78 79 80 |
# File 'lib/carray/basic.rb', line 75 def attribute= (obj) unless obj.is_a?(Hash) raise "attribute should be a hash object" end @attribute = obj end |
#between(a, b) ⇒ Object
27 28 29 |
# File 'lib/carray/testing.rb', line 27 def between (a, b) return (self >= a) & (self <= b) end |
#bin(val, include_upper, include_lowest, offset = 0) ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/carray/math/histogram.rb', line 120 def bin (val, include_upper, include_lowest, offset=0) scales = CArray.wrap_readonly(self, CA_DOUBLE) x = scales.section(val) # x.inherit_mask(val) unless x.is_a?(CArray) x = CA_DOUBLE(x) end if include_upper if include_lowest x[:eq, 0] = 0.5 end xi = x.ceil.int32 - 1 else xi = x.floor.int32 end case offset when 0 xi[:gt, elements-1] = elements - 1 xi[:lt, 0] = UNDEF when 1 xi.add!(1) xi[:gt, elements] = elements xi[:lt, 1] = 0 else raise "invalid offset value" end return xi end |
#bitarray ⇒ Object
yard:
class CArray
def bits
end
alias bitarray bits
end
473 474 475 476 477 478 479 480 481 482 483 484 |
# File 'ext/ca_obj_bitarray.c', line 473
VALUE
rb_ca_bitarray (VALUE self)
{
volatile VALUE obj;
CArray *ca;
Data_Get_Struct(self, CArray, ca);
obj = rb_ca_bitarray_new(self);
return obj;
}
|
#bitfield ⇒ Object
yard:
class CArray
def bitfield (range, type)
end
end
567 568 569 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 597 |
# File 'ext/ca_obj_bitfield.c', line 567
VALUE
rb_ca_bitfield (int argc, VALUE *argv, VALUE self)
{
volatile VALUE rrange, rtype;
CArray *ca;
ca_size_t offset, bitlen, step;
int data_type = CA_NONE;
ca_size_t bitsize;
rb_scan_args(argc, argv, "11", (VALUE *) &rrange, (VALUE *) &rtype);
Data_Get_Struct(self, CArray, ca);
if ( TYPE(rrange) == T_FIXNUM ) {
offset = NUM2INT(rrange);
bitlen = 1;
}
else {
bitsize = ca->bytes * 8;
ca_parse_range(rrange, bitsize, &offset, &bitlen, &step);
if ( step != 1 ) {
rb_raise(rb_eIndexError, "invalid bit range specified for bit field");
}
}
if ( ! NIL_P(rtype) ) {
data_type = rb_ca_guess_type(rtype);
}
return rb_ca_bitfield_new(self, offset, bitlen);
}
|
#bits ⇒ Object
yard:
class CArray
def bits
end
alias bitarray bits
end
473 474 475 476 477 478 479 480 481 482 483 484 |
# File 'ext/ca_obj_bitarray.c', line 473
VALUE
rb_ca_bitarray (VALUE self)
{
volatile VALUE obj;
CArray *ca;
Data_Get_Struct(self, CArray, ca);
obj = rb_ca_bitarray_new(self);
return obj;
}
|
#block_iterator(*argv) ⇒ Object
:nodoc:
141 142 143 144 |
# File 'lib/carray/obsolete.rb', line 141 def block_iterator (*argv) # :nodoc: warn "CArray#block_iterator will be obsolete, use CArray#blocks" return blocks(*argv) end |
#blocks ⇒ Object
yard:
class CArray
# Create block iterator.
def blocks (*args)
end
end
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
# File 'ext/ca_iter_block.c', line 211
static VALUE
rb_ca_block_iterator (int argc, VALUE *argv, VALUE self)
{
VALUE obj, rker;
CArray *ker;
rker = rb_ca_fetch2(self, argc, argv);
rb_check_carray_object(rker);
Data_Get_Struct(rker, CArray, ker);
if ( ker->obj_type != CA_OBJ_BLOCK ) {
rb_raise(rb_eRuntimeError, "kernel must be CABlock object");
}
obj = rb_bi_s_allocate(rb_cCABlockIterator);
ca_bi_setup(obj, self, rker);
return obj;
}
|
#fixlen(bytes: ) ⇒ Object
(Conversion) Short-Hand of “CArray#to_type(:boolean)”
372 373 374 375 |
# File 'ext/carray_cast.c', line 372
VALUE rb_ca_to_boolean (VALUE self)
{
rb_ca_to_type_method_body(CA_BOOLEAN);
}
|
#boolean? ⇒ Boolean
(Inquiry) Return true if self is boolean type array
422 423 424 425 426 427 428 |
# File 'ext/carray_attribute.c', line 422
VALUE
rb_ca_is_boolean_type (VALUE self)
{
CArray *ca;
Data_Get_Struct(self, CArray, ca);
return ca_is_boolean_type(ca) ? Qtrue : Qfalse;
}
|
#broadcast_to(*new_dim) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/carray/broadcast.rb', line 3 def broadcast_to (*new_dim) if new_dim.size < ndim raise "can't broadcast to #{new_dim.inspect} because of mismatch in rank" end flag_unbound_repeat = false sdim = [] ([1]*(new_dim.size-ndim) + dim).each_with_index do |d, k| if new_dim[k] == 1 sdim << 1 elsif d == 1 flag_unbound_repeat = true sdim << :* elsif d != new_dim[k] raise "can't broadcast to #{new_dim.inspect} because of mismatch in #{d} for #{new_dim[k]} in #{k}th dim" else sdim << nil end end return self[*sdim].bind(*new_dim) if flag_unbound_repeat return self end |
#bsearch ⇒ Object
Returns a new CArray object containing ca’s elements sorted.
444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 |
# File 'ext/carray_order.c', line 444
static VALUE
rb_ca_binary_search (VALUE self, volatile VALUE rval)
{
volatile VALUE out;
CArray *ca;
char *val;
Data_Get_Struct(self, CArray, ca);
/* FIXME : treat mask */
/*
if ( ca_has_mask(ca) && ca_is_any_masked(self) ) {
VALUE val = rb_funcall(self, rb_intern("value"), 0);
VALUE select = rb_ca_is_not_masked(self);
VALUE obj = rb_funcall(val, rb_intern("[]"), 1, select);
return rb_ca_binary_search(obj, rval);
}
*/
if ( ca_is_any_masked(ca) ) {
rb_raise(rb_eRuntimeError,
"CArray#bsearch can't be applied to carray with masked element.");
}
ca_attach(ca);
if ( rb_obj_is_carray(rval) ) {
volatile VALUE vidx;
CArray *cv, *co;
char *ptr, *val;
ca_size_t i, idx;
Data_Get_Struct(rval, CArray, cv);
if ( ca->data_type != cv->data_type ) {
cv = ca_wrap_readonly(rval, ca->data_type);
}
co = carray_new(CA_SIZE, cv->ndim, cv->dim, 0, NULL);
out = ca_wrap_struct(co);
ca_attach(cv);
if ( ca_is_fixlen_type(ca) ) {
cmp_data *cmp_ptr, *p, *ptr, cmp_val;
char *q;
ca_size_t i;
cmp_val.bytes = ca->bytes;
cmp_ptr = malloc_with_check(sizeof(cmp_data)*ca->elements);
for (i=0, p=cmp_ptr, q=ca->ptr; i<ca->elements; i++, p++, q+=ca->bytes) {
p->bytes = ca->bytes;
p->ptr = q;
}
for (i=0; i<cv->elements; i++) {
cmp_val.ptr = ca_ptr_at_addr(cv, i);
ptr = bsearch(&cmp_val, cmp_ptr, ca->elements, sizeof(cmp_data),
ca_qsort_cmp[CA_FIXLEN]);
vidx = ( ! ptr ) ? CA_UNDEF : SIZE2NUM(ptr - cmp_ptr);
rb_ca_store_addr(out, i, vidx);
}
free(cmp_ptr);
}
else {
for (i=0; i<cv->elements; i++) {
val = ca_ptr_at_addr(cv, i);
ptr = bsearch(val, ca->ptr, ca->elements, ca->bytes,
ca_qsort_cmp[ca->data_type]);
if ( ! ptr ) {
rb_ca_store_addr(out, i, CA_UNDEF);
}
else {
idx = (ptr - ca->ptr)/ca->bytes;
ca_store_addr(co, i, &idx);
}
}
}
ca_detach(cv);
}
else {
val = ALLOCA_N(char, ca->bytes);
rb_ca_obj2ptr(self, rval, val);
if ( ca_is_fixlen_type(ca) ) {
cmp_data *cmp_ptr, *p, *ptr, cmp_val;
char *q;
ca_size_t i;
cmp_val.bytes = ca->bytes;
cmp_val.ptr = val;
cmp_ptr = malloc_with_check(sizeof(cmp_data)*ca->elements);
for (i=0, p=cmp_ptr, q=ca->ptr; i<ca->elements; i++, p++, q+=ca->bytes) {
p->bytes = ca->bytes;
p->ptr = q;
}
ptr = bsearch(&cmp_val, cmp_ptr, ca->elements, sizeof(cmp_data),
ca_qsort_cmp[CA_FIXLEN]);
out = ( ! ptr ) ? Qnil : SIZE2NUM((ptr - cmp_ptr));
free(cmp_ptr);
}
else {
char *ptr;
ptr = bsearch(val, ca->ptr, ca->elements, ca->bytes,
ca_qsort_cmp[ca->data_type]);
out = ( ! ptr ) ? Qnil : SIZE2NUM((ptr - ca->ptr)/ca->bytes);
}
}
ca_detach(ca);
return out;
}
|
#bsearch_index ⇒ Object
[TBD].
551 552 553 554 555 556 |
# File 'ext/carray_order.c', line 551
static VALUE
rb_ca_binary_search_index (VALUE self, volatile VALUE rval)
{
VALUE raddr = rb_ca_binary_search(self, rval);
return ( NIL_P(raddr) ) ? Qnil : rb_ca_addr2index(self, raddr);
}
|
#by(other) ⇒ Object
79 80 81 82 83 84 85 86 87 |
# File 'lib/carray/obsolete.rb', line 79 def by (other) warn "CArray#by will be obsolete" case other when CArray return (self[nil][nil,:*]*other[nil][:*,nil]).reshape(*(dim+other.dim)) else return self * other end end |
#bytes ⇒ Object
(Attribute) Returns the byte size of each element (e.g. 4 for CA_INT32, 8 for CA_FLOAT64). The byte size can be known using CArray.sizeof(data_type) for the numerical data types, but the byte size of fixed-length data type can be known only by this method.
69 70 71 72 73 74 75 |
# File 'ext/carray_attribute.c', line 69
VALUE
rb_ca_bytes (VALUE self)
{
CArray *ca;
Data_Get_Struct(self, CArray, ca);
return SIZE2NUM(ca->bytes);
}
|
#cast_with(other) ⇒ Object
- TBD
1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 |
# File 'ext/carray_cast.c', line 1268
VALUE
rb_ca_cast_with (VALUE self, VALUE other)
{
if ( rb_obj_is_carray(self) ) {
rb_ca_cast_self_or_other(&self, &other);
}
else {
rb_raise(rb_eRuntimeError, "first argument should be a carray");
}
return rb_assoc_new(self, other);
}
|
#classes(classifier = nil, &block) ⇒ Object
307 308 309 |
# File 'lib/carray/iterator.rb', line 307 def classes (classifier=nil, &block) return CAClassIterator.new(self, classifier).__build__(&block) end |
#classify(klass, outlier = nil) ⇒ Object
:nodoc:
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'lib/carray/obsolete.rb', line 185 def classify (klass, outlier = nil) # :nodoc: warn "CArray#classify will be obsolete" b = CArray.int32(*dim) f = CArray.boolean(*dim) { 1 } attach { (klass.elements-1).times do |i| r = f.and(self < klass[i+1]) b[r] = i f[r] = 0 end if outlier b[self < klass[0]] = outlier b[f] = outlier else b[self < klass[0]] = -1 b[f] = klass.elements-1 end } return b end |
#clip(idx, ary) ⇒ Object
(copy) Clips the data at idx from self to ary.
397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 |
# File 'ext/carray_copy.c', line 397
static VALUE
rb_ca_clip (VALUE self, VALUE roffset, VALUE rsrc)
{
CArray *ca, *cs;
ca_size_t offset[CA_RANK_MAX];
int i;
Data_Get_Struct(self, CArray, ca);
Check_Type(roffset, T_ARRAY);
if ( RARRAY_LEN(roffset) != ca->ndim ) {
rb_raise(rb_eArgError,
"# of arguments should equal to the ndim");
}
for (i=0; i<ca->ndim; i++) {
offset[i] = NUM2SIZE(rb_ary_entry(roffset, i));
}
cs = ca_wrap_writable(rsrc, ca->data_type);
ca_clip(ca, offset, cs);
return rsrc;
}
|
#cmplx128 ⇒ Object Also known as: dcomplex
(Conversion) Short-Hand of “CArray#to_type(:cmplx128)”
489 490 491 492 |
# File 'ext/carray_cast.c', line 489
VALUE rb_ca_to_cmplx128 (VALUE self)
{
rb_ca_to_type_method_body(CA_CMPLX128);
}
|
#cmplx256 ⇒ Object
(Conversion) Short-Hand of “CArray#to_type(:cmplx256)”
498 499 500 501 |
# File 'ext/carray_cast.c', line 498
VALUE rb_ca_to_cmplx256 (VALUE self)
{
rb_ca_to_type_method_body(CA_CMPLX256);
}
|
#cmplx64 ⇒ Object Also known as: complex
(Conversion) Short-Hand of “CArray#to_type(:cmplx64)”
480 481 482 483 |
# File 'ext/carray_cast.c', line 480
VALUE rb_ca_to_cmplx64 (VALUE self)
{
rb_ca_to_type_method_body(CA_CMPLX64);
}
|
#code ⇒ Object
238 239 240 241 242 243 244 245 246 247 248 |
# File 'lib/carray/inspect.rb', line 238 def code text = [ desc, " { ", self.to_a.pretty_inspect.split("\n").map{|s| " " * (desc.length+3) + s }.join("\n").lstrip, " }" ].join return text end |
#coerece(other) ⇒ Object
- TBD
476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 |
# File 'ext/carray_operator.c', line 476
static VALUE
rb_ca_coerce (VALUE self, VALUE other)
{
CArray *ca;
Data_Get_Struct(self, CArray, ca);
if ( rb_obj_is_carray(other) ) {
return Qnil;
}
else if ( rb_respond_to(other, rb_intern("ca")) ) {
return rb_ca_coerce(self, rb_funcall(other,rb_intern("ca"),0));
}
else if ( rb_respond_to(other, rb_intern("to_ca")) ) {
return rb_ca_coerce(self, rb_funcall(other,rb_intern("to_ca"),0));
}
else {
/* do implicit casting and resolving unbound repeat array */
rb_ca_cast_self_or_other(&self, &other);
return rb_assoc_new(other, self);
}
}
|
#map!({|elem| ... }) ⇒ Object
(Iterator, Destructive) Iterates all elements of the object and stores the return from the block to the element.
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'ext/carray_loop.c', line 179
static VALUE
rb_ca_map_bang (VALUE self)
{
volatile VALUE obj;
CArray *ca;
ca_size_t elements = NUM2SIZE(rb_ca_elements(self));
ca_size_t i;
#if RUBY_VERSION_CODE >= 190
RETURN_ENUMERATOR(self, 0, 0);
#endif
rb_ca_modify(self);
Data_Get_Struct(self, CArray, ca);
ca_attach(ca);
for (i=0; i<elements; i++) {
obj = rb_yield(rb_ca_fetch_addr(self, i));
rb_ca_store_addr(self, i, obj);
}
ca_sync(ca);
ca_detach(ca);
return self;
}
|
#map_addr!({|addr| ... }) ⇒ Object
- TBD
388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 |
# File 'ext/carray_loop.c', line 388
static VALUE
rb_ca_map_addr_bang (VALUE self)
{
volatile VALUE obj;
CArray *ca;
ca_size_t elements = NUM2SIZE(rb_ca_elements(self));
ca_size_t i;
#if RUBY_VERSION_CODE >= 190
RETURN_ENUMERATOR(self, 0, 0);
#endif
rb_ca_modify(self);
Data_Get_Struct(self, CArray, ca);
ca_attach(ca);
for (i=0; i<elements; i++) {
obj = rb_yield(SIZE2NUM(i));
rb_ca_store_addr(self, i, obj);
}
ca_sync(ca);
ca_detach(ca);
return self;
}
|
#map_index!({|idx| ... }) ⇒ Object
- TBD
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 |
# File 'ext/carray_loop.c', line 333
static VALUE
rb_ca_map_index_bang (VALUE self)
{
volatile VALUE ridx;
CArray *ca;
ca_size_t idx[CA_RANK_MAX];
int8_t ndim = NUM2INT(rb_ca_ndim(self));
#if RUBY_VERSION_CODE >= 190
RETURN_ENUMERATOR(self, 0, 0);
#endif
rb_ca_modify(self);
Data_Get_Struct(self, CArray, ca);
ca_attach(ca);
ridx = rb_ary_new2(ndim);
rb_ca_map_index_bang_internal(self, 0, idx, ridx);
ca_sync(ca);
ca_detach(ca);
return self;
}
|
#map_with_addr!({|elem, addr| ... }) ⇒ Object
- TBD
359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 |
# File 'ext/carray_loop.c', line 359
static VALUE
rb_ca_map_with_addr_bang (VALUE self)
{
volatile VALUE obj;
CArray *ca;
ca_size_t elements = NUM2SIZE(rb_ca_elements(self));
ca_size_t i;
#if RUBY_VERSION_CODE >= 190
RETURN_ENUMERATOR(self, 0, 0);
#endif
rb_ca_modify(self);
Data_Get_Struct(self, CArray, ca);
ca_attach(ca);
for (i=0; i<elements; i++) {
obj = rb_yield_values(2, rb_ca_fetch_addr(self, i), SIZE2NUM(i));
rb_ca_store_addr(self, i, obj);
}
ca_sync(ca);
ca_detach(ca);
return self;
}
|
#map_with_index({|elem, idx| ... }) ⇒ Object
- TBD
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 |
# File 'ext/carray_loop.c', line 281
static VALUE
rb_ca_map_with_index_bang (VALUE self)
{
volatile VALUE ridx;
CArray *ca;
ca_size_t idx[CA_RANK_MAX];
int8_t ndim = NUM2INT(rb_ca_ndim(self));
#if RUBY_VERSION_CODE >= 190
RETURN_ENUMERATOR(self, 0, 0);
#endif
rb_ca_modify(self);
Data_Get_Struct(self, CArray, ca);
ca_attach(ca);
ridx = rb_ary_new2(ndim);
rb_ca_map_with_index_bang_internal(self, 0, idx, ridx);
ca_sync(ca);
ca_detach(ca);
return self;
}
|
#compact ⇒ Object
Returns the array which ndim is reduced by eliminating the dimensions which size == 1
74 75 76 77 78 79 80 81 |
# File 'lib/carray/transform.rb', line 74 def compact if ndim == 1 return self.to_ca else newdim = dim.reject{|x| x == 1 } return ( ndim != newdim.size ) ? reshape(*newdim).to_ca : self.to_ca end end |
#compacted ⇒ Object
Reutrns the reference which ndim is reduced by eliminating the dimensions which size == 1
63 64 65 66 67 68 69 70 |
# File 'lib/carray/transform.rb', line 63 def compacted if ndim == 1 return self[] else newdim = dim.reject{|x| x == 1 } return ( ndim != newdim.size ) ? reshape(*newdim) : self[] end end |
#complex? ⇒ Boolean
(Inquiry) Returns true if self is complex type array
544 545 546 547 548 549 550 |
# File 'ext/carray_attribute.c', line 544
VALUE
rb_ca_is_complex_type (VALUE self)
{
CArray *ca;
Data_Get_Struct(self, CArray, ca);
return ca_is_complex_type(ca) ? Qtrue : Qfalse;
}
|
#contains(*list) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/carray/testing.rb', line 19 def contains (*list) result = self.false() list.each do |item| result = result | self.eq(item) end return result end |
#convert(data_type = nil, dim = nil{ |elem| ... }) ⇒ Object
(Conversion) Returns new array which elements are caluculated in the iteration block. The output array is internally created using ‘CArray#template` to which the arguments is passed.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'ext/carray_conversion.c', line 74
static VALUE
rb_ca_convert (int argc, VALUE *argv, VALUE self)
{
volatile VALUE obj;
CArray *ca;
ca_size_t i;
obj = rb_apply(self, rb_intern("template"), rb_ary_new4(argc, argv));
Data_Get_Struct(self, CArray, ca);
ca_attach(ca);
if ( ca_has_mask(ca) ) {
for (i=0; i<ca->elements; i++) {
if ( ! ca->mask->ptr[i] ) {
rb_ca_store_addr(obj, i, rb_yield(rb_ca_fetch_addr(self, i)));
}
else {
rb_ca_store_addr(obj, i, CA_UNDEF);
}
}
}
else {
for (i=0; i<ca->elements; i++) {
rb_ca_store_addr(obj, i, rb_yield(rb_ca_fetch_addr(self, i)));
}
}
ca_detach(ca);
return obj;
}
|
#correlation(y, min_count = nil, fill_value = nil) ⇒ Object
350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 |
# File 'lib/carray/math.rb', line 350 def correlation (y, min_count = nil, fill_value = nil) x = self.double y = y.double if x.has_mask? or y.has_mask? x.inherit_mask(y) y.inherit_mask(x) xm = x.mean(:min_count=>min_count) ym = y.mean(:min_count=>min_count) if ( xm.undef? or ym.undef? ) return fill_value || UNDEF else xd, yd = x-xm, y-ym return xd.wsum(yd)/(xd.wsum(xd)*yd.wsum(yd)).sqrt end else xd, yd = x-x.mean, y-y.mean return xd.wsum(yd)/(xd.wsum(xd)*yd.wsum(yd)).sqrt end end |
#count ⇒ Object
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 |
# File 'ext/carray_stat.c', line 1103
static VALUE
rb_ca_count_equal (int argc, VALUE *argv, VALUE self)
{
volatile VALUE out, value, rmin_count = Qnil, rfval = Qnil;
CArray *ca;
ca_size_t min_count;
rb_scan_args(argc, argv, "12", (VALUE *) &value, (VALUE *) &rmin_count, (VALUE *) &rfval);
Data_Get_Struct(self, CArray, ca);
if ( ca->elements == 0 ) {
return ( NIL_P(rfval) ) ? CA_UNDEF : rfval;
}
min_count = ( NIL_P(rmin_count) || ! ca_has_mask(ca) ) ?
ca->elements - 1 : NUM2SIZE(rmin_count);
if ( min_count < 0 ) {
min_count += ca->elements;
}
ca_attach(ca);
switch ( ca->data_type ) {
case CA_FIXLEN: proc_count_equal_data(); break;
case CA_BOOLEAN:
case CA_INT8: proc_count_equal(int8_t,NUM2LONG); break;
case CA_UINT8: proc_count_equal(uint8_t,NUM2ULONG); break;
case CA_INT16: proc_count_equal(int16_t,NUM2LONG); break;
case CA_UINT16: proc_count_equal(uint16_t,NUM2ULONG); break;
case CA_INT32: proc_count_equal(int32_t,NUM2LONG); break;
case CA_UINT32: proc_count_equal(uint32_t,NUM2LONG); break;
case CA_INT64: proc_count_equal(int64_t,NUM2LL); break;
case CA_UINT64: proc_count_equal(uint64_t,NUM2LL); break;
case CA_FLOAT32: proc_count_equal(float32_t,NUM2DBL); break;
case CA_FLOAT64: proc_count_equal(float64_t,NUM2DBL); break;
case CA_FLOAT128: proc_count_equal(float128_t,NUM2DBL); break;
#ifdef HAVE_COMPLEX_H
case CA_CMPLX64: proc_count_equal(cmplx64_t,NUM2CC); break;
case CA_CMPLX128: proc_count_equal(cmplx128_t,NUM2CC); break;
case CA_CMPLX256: proc_count_equal(cmplx256_t,NUM2CC); break;
#endif
case CA_OBJECT: proc_count_equal_object(); break;
default: rb_raise(rb_eCADataTypeError, "invalid data type");
}
ca_detach(ca);
return out;
}
|
#count_close ⇒ Object
1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 |
# File 'ext/carray_stat.c', line 1286
static VALUE
rb_ca_count_close (int argc, VALUE *argv, VALUE self)
{
volatile VALUE out, value = argv[0], aeps = argv[1],
rmin_count = Qnil, rfval = Qnil;
CArray *ca;
ca_size_t min_count;
if ( argc > 2 ) {
rb_scan_args(argc, argv, "22", (VALUE *) &value, (VALUE *) &aeps, (VALUE *) &rmin_count, (VALUE *) &rfval);
}
Data_Get_Struct(self, CArray, ca);
if ( ca->elements == 0 ) {
return ( NIL_P(rfval) ) ? CA_UNDEF : rfval;
}
min_count = ( NIL_P(rmin_count) || ! ca_has_mask(ca) ) ?
ca->elements - 1 : NUM2SIZE(rmin_count);
if ( min_count < 0 ) {
min_count += ca->elements;
}
ca_attach(ca);
switch ( ca->data_type ) {
case CA_BOOLEAN:
case CA_INT8: proc_count_close(int8_t,NUM2LONG,fabs); break;
case CA_UINT8: proc_count_close(uint8_t,NUM2ULONG,fabs); break;
case CA_INT16: proc_count_close(int16_t,NUM2LONG,fabs); break;
case CA_UINT16: proc_count_close(uint16_t,NUM2ULONG,fabs); break;
case CA_INT32: proc_count_close(int32_t,NUM2LONG,fabs); break;
case CA_UINT32: proc_count_close(uint32_t,NUM2LONG,fabs); break;
case CA_INT64: proc_count_close(int64_t,NUM2LL,fabs); break;
case CA_UINT64: proc_count_close(uint64_t,NUM2LL,fabs); break;
case CA_FLOAT32: proc_count_close(float32_t,NUM2DBL,fabs); break;
case CA_FLOAT64: proc_count_close(float64_t,NUM2DBL,fabs); break;
case CA_FLOAT128: proc_count_close(float128_t,NUM2DBL,fabs); break;
#ifdef HAVE_COMPLEX_H
case CA_CMPLX64: proc_count_close(cmplx64_t,NUM2CC,cabs); break;
case CA_CMPLX128: proc_count_close(cmplx128_t,NUM2CC,cabs); break;
case CA_CMPLX256: proc_count_close(cmplx256_t,NUM2CC,cabs); break;
#endif
default: rb_raise(rb_eCADataTypeError, "invalid data type");
}
ca_detach(ca);
return out;
}
|
#count_equal ⇒ Object
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 |
# File 'ext/carray_stat.c', line 1103
static VALUE
rb_ca_count_equal (int argc, VALUE *argv, VALUE self)
{
volatile VALUE out, value, rmin_count = Qnil, rfval = Qnil;
CArray *ca;
ca_size_t min_count;
rb_scan_args(argc, argv, "12", (VALUE *) &value, (VALUE *) &rmin_count, (VALUE *) &rfval);
Data_Get_Struct(self, CArray, ca);
if ( ca->elements == 0 ) {
return ( NIL_P(rfval) ) ? CA_UNDEF : rfval;
}
min_count = ( NIL_P(rmin_count) || ! ca_has_mask(ca) ) ?
ca->elements - 1 : NUM2SIZE(rmin_count);
if ( min_count < 0 ) {
min_count += ca->elements;
}
ca_attach(ca);
switch ( ca->data_type ) {
case CA_FIXLEN: proc_count_equal_data(); break;
case CA_BOOLEAN:
case CA_INT8: proc_count_equal(int8_t,NUM2LONG); break;
case CA_UINT8: proc_count_equal(uint8_t,NUM2ULONG); break;
case CA_INT16: proc_count_equal(int16_t,NUM2LONG); break;
case CA_UINT16: proc_count_equal(uint16_t,NUM2ULONG); break;
case CA_INT32: proc_count_equal(int32_t,NUM2LONG); break;
case CA_UINT32: proc_count_equal(uint32_t,NUM2LONG); break;
case CA_INT64: proc_count_equal(int64_t,NUM2LL); break;
case CA_UINT64: proc_count_equal(uint64_t,NUM2LL); break;
case CA_FLOAT32: proc_count_equal(float32_t,NUM2DBL); break;
case CA_FLOAT64: proc_count_equal(float64_t,NUM2DBL); break;
case CA_FLOAT128: proc_count_equal(float128_t,NUM2DBL); break;
#ifdef HAVE_COMPLEX_H
case CA_CMPLX64: proc_count_equal(cmplx64_t,NUM2CC); break;
case CA_CMPLX128: proc_count_equal(cmplx128_t,NUM2CC); break;
case CA_CMPLX256: proc_count_equal(cmplx256_t,NUM2CC); break;
#endif
case CA_OBJECT: proc_count_equal_object(); break;
default: rb_raise(rb_eCADataTypeError, "invalid data type");
}
ca_detach(ca);
return out;
}
|
#count_equiv ⇒ Object
1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 |
# File 'ext/carray_stat.c', line 1195
static VALUE
rb_ca_count_equiv (int argc, VALUE *argv, VALUE self)
{
volatile VALUE out, value = argv[0], reps = argv[1],
rmin_count = Qnil, rfval = Qnil;
CArray *ca;
ca_size_t min_count;
if ( argc > 2 ) {
rb_scan_args(argc, argv, "22", (VALUE *) &value, (VALUE *) &reps, (VALUE *) &rmin_count, (VALUE *) &rfval);
}
Data_Get_Struct(self, CArray, ca);
if ( ca->elements == 0 ) {
return ( NIL_P(rfval) ) ? CA_UNDEF : rfval;
}
min_count = ( NIL_P(rmin_count) || ! ca_has_mask(ca) ) ?
ca->elements - 1 : NUM2SIZE(rmin_count);
if ( min_count < 0 ) {
min_count += ca->elements;
}
ca_attach(ca);
switch ( ca->data_type ) {
case CA_BOOLEAN:
case CA_INT8: proc_count_equiv(int8_t,NUM2LONG,fabs); break;
case CA_UINT8: proc_count_equiv(uint8_t,NUM2ULONG,fabs); break;
case CA_INT16: proc_count_equiv(int16_t,NUM2LONG,fabs); break;
case CA_UINT16: proc_count_equiv(uint16_t,NUM2ULONG,fabs); break;
case CA_INT32: proc_count_equiv(int32_t,NUM2LONG,fabs); break;
case CA_UINT32: proc_count_equiv(uint32_t,NUM2LONG,fabs); break;
case CA_INT64: proc_count_equiv(int64_t,NUM2LL,fabs); break;
case CA_UINT64: proc_count_equiv(uint64_t,NUM2LL,fabs); break;
case CA_FLOAT32: proc_count_equiv(float32_t,NUM2DBL,fabs); break;
case CA_FLOAT64: proc_count_equiv(float64_t,NUM2DBL,fabs); break;
case CA_FLOAT128: proc_count_equiv(float128_t,NUM2DBL,fabs); break;
#ifdef HAVE_COMPLEX_H
case CA_CMPLX64: proc_count_equiv(cmplx64_t,NUM2CC,cabs); break;
case CA_CMPLX128: proc_count_equiv(cmplx128_t,NUM2CC,cabs); break;
case CA_CMPLX256: proc_count_equiv(cmplx256_t,NUM2CC,cabs); break;
#endif
default: rb_raise(rb_eCADataTypeError, "invalid data type");
}
ca_detach(ca);
return out;
}
|
#count_false ⇒ Object
924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 |
# File 'ext/carray_stat.c', line 924
static VALUE
rb_ca_count_false (int argc, VALUE *argv, VALUE self)
{
volatile VALUE out, rmin_count = Qnil, rfval = Qnil;
CArray *ca;
ca_size_t min_count;
if ( argc > 1 ) {
rb_scan_args(argc, argv, "02", (VALUE *) &rmin_count, (VALUE *) &rfval);
}
Data_Get_Struct(self, CArray, ca);
if ( ! ca_is_boolean_type(ca) ) {
rb_raise(rb_eCADataTypeError,
"data_type should be CA_BOOLEAN for this method");
}
if ( ca->elements == 0 ) {
return INT2NUM(0);
}
min_count = ( NIL_P(rmin_count) || ! ca_has_mask(ca) ) ?
ca->elements - 1 : NUM2SIZE(rmin_count);
if ( min_count < 0 ) {
min_count += ca->elements;
}
ca_attach(ca);
{
boolean8_t *ptr = (boolean8_t *) ca->ptr;
boolean8_t *m = (ca->mask) ? (boolean8_t*) ca->mask->ptr : NULL;
ca_size_t count = 0;
ca_size_t value_count = 0;
ca_size_t i;
if ( m ) {
for (i=0; i<ca->elements; i++) {
if ( *m ) {
count++;
}
else if ( !(*ptr) ) {
value_count++;
}
ptr++; m++;
}
}
else {
for (i=0; i<ca->elements; i++) {
if ( !(*ptr) ) {
value_count++;
}
ptr++;
}
}
if ( ( ! NIL_P(rmin_count) ) && count > min_count ) {
out = ( NIL_P(rfval) ) ? CA_UNDEF : rfval;
}
else {
out = SIZE2NUM(value_count);
}
}
ca_detach(ca);
return out;
}
|
#count_masked(*axis) ⇒ Object
Returns the number of masked elements.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/carray/mask.rb', line 21 def count_masked (*axis) if has_mask? return mask.int64.accumulate(*axis) else if axis.empty? return 0 else spec = shape.map{:i} axis.each do |k| spec[k] = nil end return self[*spec].ca.template(:int64) { 0 } end end end |
#count_not_masked(*axis) ⇒ Object
Returns the number of not-masked elements.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/carray/mask.rb', line 40 def count_not_masked (*axis) if has_mask? return mask.not.int64.accumulate(*axis) else if axis.empty? return elements else spec = shape.map {:i} axis.each do |k| spec[k] = nil end it = self[*spec].ca count = self.elements/it.elements return it.template(:int64) { count } end end end |
#count_true ⇒ Object
855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 |
# File 'ext/carray_stat.c', line 855
static VALUE
rb_ca_count_true (int argc, VALUE *argv, VALUE self)
{
volatile VALUE out, rmin_count = Qnil, rfval = Qnil;
CArray *ca;
ca_size_t min_count;
if ( argc > 1 ) {
rb_scan_args(argc, argv, "02", (VALUE *) &rmin_count, (VALUE *) &rfval);
}
Data_Get_Struct(self, CArray, ca);
if ( ! ca_is_boolean_type(ca) ) {
rb_raise(rb_eCADataTypeError,
"data_type should be CA_BOOLEAN for this method");
}
if ( ca->elements == 0 ) {
return INT2NUM(0);
}
min_count = ( NIL_P(rmin_count) || ! ca_has_mask(ca) ) ?
ca->elements - 1 : NUM2SIZE(rmin_count);
if ( min_count < 0 ) {
min_count += ca->elements;
}
ca_attach(ca);
{
boolean8_t *ptr = (boolean8_t *) ca->ptr;
boolean8_t *m = (ca->mask) ? (boolean8_t*) ca->mask->ptr : NULL;
ca_size_t count = 0;
ca_size_t value_count = 0;
ca_size_t i;
if ( m ) {
for (i=0; i<ca->elements; i++) {
if ( *m ) {
count++;
}
else if ( *ptr ) {
value_count++;
}
ptr++; m++;
}
}
else {
for (i=0; i<ca->elements; i++) {
if ( *ptr ) {
value_count++;
}
ptr++;
}
}
if ( ( ! NIL_P(rmin_count) ) && count > min_count ) {
out = ( NIL_P(rfval) ) ? CA_UNDEF : rfval;
}
else {
out = SIZE2NUM(value_count);
}
}
ca_detach(ca);
return out;
}
|
#covariance(y, min_count = nil, fill_value = nil) ⇒ Object
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 |
# File 'lib/carray/math.rb', line 331 def covariance (y, min_count = nil, fill_value = nil) x = self.double y = y.double if x.has_mask? or y.has_mask? x.inherit_mask(y) y.inherit_mask(x) count = x.count_not_masked xm = x.mean(:min_count=>min_count) ym = y.mean(:min_count=>min_count) if ( xm.undef? or ym.undef? ) return fill_value || UNDEF else return (x-xm).wsum(y-ym)/(count-1) end else return (x-x.mean).wsum(y-y.mean)/(elements-1) end end |
#covariancep(y, min_count = nil, fill_value = nil) ⇒ Object
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 |
# File 'lib/carray/math.rb', line 312 def covariancep (y, min_count = nil, fill_value = nil) x = self.double y = y.double if x.has_mask? or y.has_mask? x.inherit_mask(y) y.inherit_mask(x) count = x.count_not_masked xm = x.mean(:min_count => min_count) ym = y.mean(:min_count => min_count) if ( xm.undef? or ym.undef? ) return fill_value || UNDEF else return (x-xm).wsum(y-ym)/count end else return (x-x.mean).wsum(y-y.mean)/elements end end |
#cummax ⇒ Object
188 189 190 191 192 193 194 195 196 197 198 199 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 |
# File 'ext/carray_stat.c', line 188
static VALUE
rb_ca_cummax (int argc, VALUE *argv, VALUE self)
{
volatile VALUE rmin_count = Qnil, rfval = Qnil, obj;
CArray *ca, *co;
ca_size_t min_count;
if ( argc > 0 ) {
rb_scan_args(argc, argv, "02", (VALUE *) &rmin_count, (VALUE *) &rfval);
}
Data_Get_Struct(self, CArray, ca);
co = ca_template(ca);
obj = ca_wrap_struct(co);
min_count = ( NIL_P(rmin_count) || ! ca_has_mask(ca) ) ?
ca->elements - 1 : NUM2SIZE(rmin_count);
if ( min_count < 0 ) {
min_count += ca->elements;
}
ca_attach(ca);
switch ( ca->data_type ) {
case CA_BOOLEAN:
case CA_INT8: proc_cummax(int8_t, NUM2LONG,); break;
case CA_UINT8: proc_cummax(uint8_t, NUM2ULONG,); break;
case CA_INT16: proc_cummax(int16_t, NUM2LONG,); break;
case CA_UINT16: proc_cummax(uint16_t, NUM2ULONG,); break;
case CA_INT32: proc_cummax(int32_t, NUM2LONG,); break;
case CA_UINT32: proc_cummax(uint32_t, NUM2ULONG,); break;
case CA_INT64: proc_cummax(int64_t, NUM2LL,); break;
case CA_UINT64: proc_cummax(uint64_t, NUM2ULL,); break;
case CA_FLOAT32: proc_cummax(float32_t, NUM2DBL,); break;
case CA_FLOAT64: proc_cummax(float64_t, NUM2DBL,); break;
case CA_FLOAT128: proc_cummax(float128_t, NUM2DBL,); break;
case CA_OBJECT: proc_cummax(VALUE, NUM2DBL, NUM2DBL); break;
default: rb_raise(rb_eRuntimeError, "invalid data type");
}
ca_detach(ca);
return obj;
}
|
#cummin ⇒ Object
81 82 83 84 85 86 87 88 89 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 |
# File 'ext/carray_stat.c', line 81
static VALUE
rb_ca_cummin (int argc, VALUE *argv, VALUE self)
{
volatile VALUE rmin_count = Qnil, rfval = Qnil, obj;
CArray *ca, *co;
ca_size_t min_count;
if ( argc > 0 ) {
rb_scan_args(argc, argv, "02", (VALUE *) &rmin_count, (VALUE *) &rfval);
}
Data_Get_Struct(self, CArray, ca);
co = ca_template(ca);
obj = ca_wrap_struct(co);
min_count = ( NIL_P(rmin_count) || ! ca_has_mask(ca) ) ?
ca->elements - 1 : NUM2SIZE(rmin_count);
if ( min_count < 0 ) {
min_count += ca->elements;
}
ca_attach(ca);
switch ( ca->data_type ) {
case CA_BOOLEAN:
case CA_INT8: proc_cummin(int8_t, NUM2LONG,); break;
case CA_UINT8: proc_cummin(uint8_t, NUM2ULONG,); break;
case CA_INT16: proc_cummin(int16_t, NUM2LONG,); break;
case CA_UINT16: proc_cummin(uint16_t, NUM2ULONG,); break;
case CA_INT32: proc_cummin(int32_t, NUM2LONG,); break;
case CA_UINT32: proc_cummin(uint32_t, NUM2ULONG,); break;
case CA_INT64: proc_cummin(int64_t, NUM2LL,); break;
case CA_UINT64: proc_cummin(uint64_t, NUM2ULL,); break;
case CA_FLOAT32: proc_cummin(float32_t, NUM2DBL,); break;
case CA_FLOAT64: proc_cummin(float64_t, NUM2DBL,); break;
case CA_FLOAT128: proc_cummin(float128_t, NUM2DBL,); break;
case CA_OBJECT: proc_cummin(VALUE, NUM2DBL, NUM2DBL); break;
default: rb_raise(rb_eRuntimeError, "invalid data type");
}
ca_detach(ca);
return obj;
}
|
#cumprod ⇒ Object
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 |
# File 'ext/carray_stat.c', line 280
static VALUE
rb_ca_cumprod (int argc, VALUE *argv, VALUE self)
{
volatile VALUE rmin_count = Qnil, rfval = Qnil;
CArray *ca, *co;
ca_size_t min_count;
if ( argc > 0 ) {
rb_scan_args(argc, argv, "02", (VALUE *) &rmin_count, (VALUE *) &rfval);
}
Data_Get_Struct(self, CArray, ca);
if ( ca_is_complex_type(ca) ) {
co = carray_new(CA_CMPLX128, ca->ndim, ca->dim, 0, NULL);
}
else {
co = carray_new(CA_FLOAT64, ca->ndim, ca->dim, 0, NULL);
}
min_count = ( NIL_P(rmin_count) || ! ca_has_mask(ca) ) ?
ca->elements - 1 : NUM2SIZE(rmin_count);
if ( min_count < 0 ) {
min_count += ca->elements;
}
ca_attach(ca);
switch ( ca->data_type ) {
case CA_BOOLEAN:
case CA_INT8: proc_cumprod(int8_t, double, NUM2DBL,); break;
case CA_UINT8: proc_cumprod(uint8_t, double, NUM2DBL,); break;
case CA_INT16: proc_cumprod(int16_t, double, NUM2DBL,); break;
case CA_UINT16: proc_cumprod(uint16_t, double, NUM2DBL,); break;
case CA_INT32: proc_cumprod(int32_t, double, NUM2DBL,); break;
case CA_UINT32: proc_cumprod(uint32_t, double, NUM2DBL,); break;
case CA_INT64: proc_cumprod(int64_t, double, NUM2DBL,); break;
case CA_UINT64: proc_cumprod(uint64_t, double, NUM2DBL,); break;
case CA_FLOAT32: proc_cumprod(float32_t, double, NUM2DBL,); break;
case CA_FLOAT64: proc_cumprod(float64_t, double, NUM2DBL,); break;
case CA_FLOAT128: proc_cumprod(float128_t, double, NUM2DBL,); break;
#ifdef HAVE_COMPLEX_H
case CA_CMPLX64: proc_cumprod(cmplx64_t, cmplx128_t, NUM2CC,); break;
case CA_CMPLX128: proc_cumprod(cmplx128_t, cmplx128_t, NUM2CC,); break;
case CA_CMPLX256: proc_cumprod(cmplx256_t, cmplx128_t, NUM2CC,); break;
#endif
case CA_OBJECT: proc_cumprod(VALUE, double, NUM2DBL, NUM2DBL); break;
default: rb_raise(rb_eRuntimeError, "invalid data type");
}
ca_detach(ca);
return ca_wrap_struct(co);
}
|
#cumwsum ⇒ Object
482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 |
# File 'ext/carray_stat.c', line 482
static VALUE
rb_ca_cumwsum (int argc, VALUE *argv, VALUE self)
{
volatile VALUE weight = argv[0], rmin_count = Qnil, rfval = Qnil, tmp;
CArray *ca, *cw, *co;
ca_size_t min_count;
if ( argc > 1 ) {
rb_scan_args(argc, argv, "12", (VALUE *) &weight, (VALUE *) &rmin_count, (VALUE *) &rfval);
}
Data_Get_Struct(self, CArray, ca);
cw = ca_wrap_readonly(weight, ca->data_type);
ca_check_same_elements(ca, cw);
if ( ca_has_mask(cw) ) {
ca = ca_copy(ca);
tmp = ca_wrap_struct(ca);
ca_copy_mask_overlay(ca, ca->elements, 1, cw);
}
if ( ca_is_complex_type(ca) ) {
co = carray_new(CA_CMPLX128, ca->ndim, ca->dim, 0, NULL);
}
else {
co = carray_new(CA_FLOAT64, ca->ndim, ca->dim, 0, NULL);
}
min_count = ( NIL_P(rmin_count) || ( ! ca_has_mask(ca) ) ) ?
ca->elements - 1 : NUM2SIZE(rmin_count);
if ( min_count < 0 ) {
min_count += ca->elements;
}
ca_attach(ca);
switch ( ca->data_type ) {
case CA_BOOLEAN:
case CA_INT8: proc_cumwsum(int8_t, double, NUM2DBL,); break;
case CA_UINT8: proc_cumwsum(uint8_t, double, NUM2DBL,); break;
case CA_INT16: proc_cumwsum(int16_t, double, NUM2DBL,); break;
case CA_UINT16: proc_cumwsum(uint16_t, double, NUM2DBL,); break;
case CA_INT32: proc_cumwsum(int32_t, double, NUM2DBL,); break;
case CA_UINT32: proc_cumwsum(uint32_t, double, NUM2DBL,); break;
case CA_INT64: proc_cumwsum(int64_t, double, NUM2DBL,); break;
case CA_UINT64: proc_cumwsum(uint64_t, double, NUM2DBL,); break;
case CA_FLOAT32: proc_cumwsum(float32_t, double, NUM2DBL,); break;
case CA_FLOAT64: proc_cumwsum(float64_t, double, NUM2DBL,); break;
case CA_FLOAT128: proc_cumwsum(float128_t, double, NUM2DBL,); break;
#ifdef HAVE_COMPLEX_H
case CA_CMPLX64: proc_cumwsum(cmplx64_t, cmplx128_t, NUM2CC,); break;
case CA_CMPLX128: proc_cumwsum(cmplx128_t, cmplx128_t, NUM2CC,); break;
case CA_CMPLX256: proc_cumwsum(cmplx256_t, cmplx128_t, NUM2CC,); break;
#endif
case CA_OBJECT: proc_cumwsum(VALUE, double, NUM2DBL, NUM2DBL); break;
default: rb_raise(rb_eRuntimeError, "invalid data type");
}
ca_detach(ca);
return ca_wrap_struct(co);
}
|
#data_class ⇒ Object
(Attribute) Returns data_class if self is fixed-length type and it has the data class.
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 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 |
# File 'ext/carray_attribute.c', line 613
VALUE
rb_ca_data_class (VALUE self)
{
volatile VALUE parent, data_class;
CArray *ca;
Data_Get_Struct(self, CArray, ca);
if ( ca_test_flag(ca, CA_FLAG_NOT_DATA_CLASS) ) {
return Qnil;
}
if ( ! ca_is_fixlen_type(ca) ) { /* not a fixlen array */
ca_set_flag(ca, CA_FLAG_NOT_DATA_CLASS);
return Qnil;
}
data_class = rb_ivar_get(self, id_data_class);
if ( ! NIL_P(data_class) ) {
return data_class;
}
else {
return Qnil;
if ( ca_is_entity(ca) ) { /* no further parent */
ca_set_flag(ca, CA_FLAG_NOT_DATA_CLASS);
return Qnil;
}
else {
parent = rb_ca_parent(self);
if ( NIL_P(parent) ) { /* no parent */
ca_set_flag(ca, CA_FLAG_NOT_DATA_CLASS);
return Qnil;
}
else {
CArray *cr;
Data_Get_Struct(parent, CArray, cr);
if ( cr->bytes != ca->bytes ) { /* byte size mismatch */
ca_set_flag(ca, CA_FLAG_NOT_DATA_CLASS);
return Qnil;
}
else {
data_class = rb_ca_data_class(parent); /* parent's data class */
if ( ! NIL_P(data_class) ) {
return data_class;
}
else {
ca_set_flag(ca, CA_FLAG_NOT_DATA_CLASS);
return Qnil;
}
}
}
}
}
}
|
#data_type ⇒ Object
(Attribute) Returns the data type of each element (e.g. CA_INT32, CA_FLOAT64, …).
37 38 39 40 41 42 43 |
# File 'ext/carray_attribute.c', line 37
VALUE
rb_ca_data_type (VALUE self)
{
CArray *ca;
Data_Get_Struct(self, CArray, ca);
return INT2NUM(ca->data_type);
}
|
#data_type_name ⇒ Object
(Attribute) Returns the string representaion of the data_type (e.g. “int32”, “fixlen”)
178 179 180 181 182 183 184 |
# File 'ext/carray_attribute.c', line 178
VALUE
rb_ca_data_type_name (VALUE self)
{
CArray *ca;
Data_Get_Struct(self, CArray, ca);
return rb_str_new2(ca_type_name[ca->data_type]);
}
|
#deg_180 ⇒ Object
76 77 78 79 80 |
# File 'ext/carray_mathfunc.c', line 76
static VALUE
rb_ca_deg_180 (VALUE self)
{
return ca_call_cfunc_1_1(CA_DOUBLE, CA_DOUBLE, mathfunc_deg_180, self);
}
|
#deg_180! ⇒ Object
82 83 84 85 86 87 88 89 |
# File 'ext/carray_mathfunc.c', line 82
static VALUE
rb_ca_deg_180_bang (VALUE self)
{
volatile VALUE out;
out = ca_call_cfunc_1_1(CA_DOUBLE, CA_DOUBLE, mathfunc_deg_180, self);
rb_funcall(self, rb_intern("[]="), 1, out);
return self;
}
|
#deg_360 ⇒ Object
34 35 36 37 38 |
# File 'ext/carray_mathfunc.c', line 34
static VALUE
rb_ca_deg_360 (VALUE self)
{
return ca_call_cfunc_1_1(CA_DOUBLE, CA_DOUBLE, mathfunc_deg_360, self);
}
|
#deg_360! ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'ext/carray_mathfunc.c', line 40
static VALUE
rb_ca_deg_360_bang (VALUE self)
{
volatile VALUE out;
out = ca_call_cfunc_1_1(CA_DOUBLE, CA_DOUBLE, mathfunc_deg_360, self);
rb_funcall(self, rb_intern("[]="), 1, out);
return self;
}
|
#delete_block(offset, bsize) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 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 |
# File 'lib/carray/compose.rb', line 75 def delete_block (offset, bsize) if offset.size != ndim or bsize.size != ndim raise "ndim mismatch" end newdim = dim grids = [] ndim.times do |i| if offset[i] < 0 offset[i] += dim[i] end if bsize[i] >= 0 if offset[i] < 0 or offset[i] >= dim[i] raise "invalid offset or size" end newdim[i] -= bsize[i] else if offset[i] + bsize[i] + 1 < 0 or offset[i] + bsize[i] > dim[i] raise "invalid offset or size" end newdim[i] += bsize[i] end grids[i] = CArray.int32(newdim[i]) if bsize[i] >= 0 if offset[i] > 0 grids[i][0...offset[i]].seq! end if offset[i] + bsize[i] < dim[i] grids[i][offset[i]..-1].seq!(offset[i]+bsize[i]) end else if offset[i]+bsize[i] > 0 grids[i][0..offset[i]+bsize[i]].seq! end if offset[i]+bsize[i]+1 < dim[i]-1 grids[i][offset[i]+bsize[i]+1..-1].seq!(offset[i]+1) end end end return self[*grids].to_ca end |
#dim ⇒ Object
(Attribute) Returns the Array object contains the dimensional shape of array (e.g. [2,3] for 2D 2x3 array, …).
98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'ext/carray_attribute.c', line 98
VALUE
rb_ca_dim (VALUE self)
{
volatile VALUE dim;
CArray *ca;
int i;
Data_Get_Struct(self, CArray, ca);
dim = rb_ary_new2(ca->ndim);
for (i=0; i<ca->ndim; i++) {
rb_ary_store(dim, i, SIZE2NUM(ca->dim[i]));
}
return dim;
}
|
#dim0 ⇒ Object
(Attribute) Short-hand for “dim”
119 120 121 122 123 124 125 |
# File 'ext/carray_attribute.c', line 119
VALUE
rb_ca_dim0 (VALUE self)
{
CArray *ca;
Data_Get_Struct(self, CArray, ca);
return SIZE2NUM(ca->dim[0]);
}
|
#dim1 ⇒ Object
(Attribute) Short-hand for “dim”
134 135 136 137 138 139 140 |
# File 'ext/carray_attribute.c', line 134
VALUE
rb_ca_dim1 (VALUE self)
{
CArray *ca;
Data_Get_Struct(self, CArray, ca);
return ( ca->ndim >= 2 ) ? SIZE2NUM(ca->dim[1]) : Qnil;
}
|
#dim2 ⇒ Object
(Attribute) Short-hand for ‘dim’
149 150 151 152 153 154 155 |
# File 'ext/carray_attribute.c', line 149
VALUE
rb_ca_dim2 (VALUE self)
{
CArray *ca;
Data_Get_Struct(self, CArray, ca);
return ( ca->ndim >= 3 ) ? SIZE2NUM(ca->dim[2]) : Qnil;
}
|
#dim3 ⇒ Object
(Attribute) Short-hand for “dim”
164 165 166 167 168 169 170 |
# File 'ext/carray_attribute.c', line 164
VALUE
rb_ca_dim3 (VALUE self)
{
CArray *ca;
Data_Get_Struct(self, CArray, ca);
return ( ca->ndim >= 4 ) ? SIZE2NUM(ca->dim[3]) : Qnil;
}
|
#display_by_magick(image_type = nil, options = "") ⇒ Object
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 |
# File 'lib/carray/io/imagemagick.rb', line 202 def display_by_magick (image_type = nil, = "") unless image_type image_type = magick_guess_image_type() end unless image_type raise "please specify image_type" end quantum_format = self.float? ? "-define quantum:format=floating-point" : "" depth = fixlen? ? "-depth 8" : "-depth #{8*bytes}" display_command = [ "display", depth, "-size " + [dim1, dim0].join("x"), quantum_format, , "#{image_type}:-", ].join(" ") begin IO.popen(display_command, "w") { |io| if bytes > 1 and CArray.endian == CA_LITTLE_ENDIAN swap_bytes.dump_binary(io) else self.dump_binary(io) end } rescue raise "ImageMagick's display command failed to display image" end end |
#dump_binary ⇒ Object
(IO) Dumps the value array to the given IO stream
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'ext/carray_conversion.c', line 111
static VALUE
rb_ca_dump_binary (int argc, VALUE *argv, VALUE self)
{
volatile VALUE io;
CArray *ca;
Data_Get_Struct(self, CArray, ca);
if ( ca_is_object_type(ca) ) {
rb_raise(rb_eCADataTypeError, "don't dump object array");
}
if ( argc == 0 ) {
io = rb_str_new(NULL, 0);
}
else if ( argc == 1 ) {
io = argv[0];
}
else {
rb_raise(rb_eArgError, "invalid # of arguments (%i for 1)", argc);
}
switch ( TYPE(io) ) {
case T_STRING:
if ( ca_length(ca) != RSTRING_LEN(io) ) {
rb_str_resize(io, ca_length(ca));
}
ca_copy_data(ca, StringValuePtr(io));
StringValuePtr(io)[ca_length(ca)] = '\0';
OBJ_TAINT(io);
break;
#if RUBY_VERSION_CODE >= 190
case T_FILE: {
volatile VALUE str;
rb_io_t *iop;
GetOpenFile(io, iop);
rb_io_check_writable(iop);
ca_attach(ca);
str = rb_str_new(ca->ptr, ca->bytes*ca->elements);
rb_io_write(io, str);
ca_detach(ca);
break;
}
#else
case T_FILE: {
OpenFile *iop;
size_t total;
GetOpenFile(io, iop);
rb_io_check_writable(iop);
ca_attach(ca);
total = fwrite(ca->ptr, ca->bytes, ca->elements, iop->f);
ca_detach(ca);
if ( total < ca->elements ) {
rb_raise(rb_eIOError, "I/O write error in CArray#dump_binary");
}
break;
}
#endif
default:
if ( rb_respond_to(io, rb_intern("write") ) ) {
VALUE buf = rb_str_new(NULL, ca_length(ca));
ca_copy_data(ca, StringValuePtr(buf));
OBJ_INFECT(buf, self);
rb_funcall(io, rb_intern("write"), 1, buf);
}
else {
rb_raise(rb_eRuntimeError, "IO like object should have 'write' method");
}
}
return io;
}
|
#duplicated_values ⇒ Object
Returns the array eliminated all the duplicated elements.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/carray/obsolete.rb', line 43 def duplicated_values warn "CArray#duplicated_values will be obsolete" if uniq.size == size return [] else hash = {} list = [] each_with_addr do |v, addr| if v == UNDEF next elsif hash[v] list << [v, addr, hash[v]] hash[v] += 1 else hash[v] = 0 end end return list end end |
#each({|elem| ... }) ⇒ Object
(Iterator) Iterates all the elements of the object.
72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'ext/carray_loop.c', line 72
static VALUE
rb_ca_each (VALUE self)
{
volatile VALUE ret = Qnil;
ca_size_t elements = NUM2SIZE(rb_ca_elements(self));
ca_size_t i;
#if RUBY_VERSION_CODE >= 190
RETURN_ENUMERATOR(self, 0, 0);
#endif
for (i=0; i<elements; i++) {
ret = rb_yield(rb_ca_fetch_addr(self, i));
}
return ret;
}
|
#each_addr({|addr| ... }) ⇒ Object
(Iterator) Iterates all address of the object.
113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'ext/carray_loop.c', line 113
static VALUE
rb_ca_each_addr (VALUE self)
{
volatile VALUE ret = Qnil;
ca_size_t elements = NUM2SIZE(rb_ca_elements(self));
ca_size_t i;
#if RUBY_VERSION_CODE >= 190
RETURN_ENUMERATOR(self, 0, 0);
#endif
for (i=0; i<elements; i++) {
ret = rb_yield(SIZE2NUM(i));
}
return ret;
}
|
#each_index({|idx| ... }) ⇒ Object
(Iterator) Iterates all index of the object.
CArray.int(3,2).each_index(){|i,j| print "(#{i} #{j}) " }
<em>produces:</em>
(0 0) (0 1) (1 0) (1 1) (2 0) (2 1) (3 0) (3 1)
162 163 164 165 166 167 168 169 170 171 172 |
# File 'ext/carray_loop.c', line 162
static VALUE
rb_ca_each_index (VALUE self)
{
volatile VALUE ridx;
int8_t ndim = NUM2INT(rb_ca_ndim(self));
ridx = rb_ary_new2(ndim);
#if RUBY_VERSION_CODE >= 190
RETURN_ENUMERATOR(self, 0, 0);
#endif
return rb_ca_each_index_internal(self, 0, ridx);
}
|
#each_with_addr({|elem, addr| ... }) ⇒ Object
(Iterator) Iterates all the elements of the object.
93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'ext/carray_loop.c', line 93
static VALUE
rb_ca_each_with_addr (VALUE self)
{
volatile VALUE ret = Qnil;
ca_size_t elements = NUM2SIZE(rb_ca_elements(self));
ca_size_t i;
#if RUBY_VERSION_CODE >= 190
RETURN_ENUMERATOR(self, 0, 0);
#endif
for (i=0; i<elements; i++) {
ret = rb_yield_values(2, rb_ca_fetch_addr(self, i), SIZE2NUM(i));
}
return ret;
}
|
#each_with_index({|elem, idx| ... }) ⇒ Object
- TBD
233 234 235 236 237 238 239 240 241 242 243 244 245 246 |
# File 'ext/carray_loop.c', line 233
static VALUE
rb_ca_each_with_index (VALUE self)
{
volatile VALUE ridx, ret;
ca_size_t idx[CA_RANK_MAX];
int8_t ndim = NUM2INT(rb_ca_ndim(self));
#if RUBY_VERSION_CODE >= 190
RETURN_ENUMERATOR(self, 0, 0);
#endif
rb_ca_modify(self);
ridx = rb_ary_new2(ndim);
ret = rb_ca_each_with_index_internal(self, 0, idx, ridx);
return ret;
}
|
#elem_copy(idx1, idx2) ⇒ Object
(Element) Copies the value of the element of idx1 to the element of idx2
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'ext/carray_element.c', line 131
VALUE
rb_ca_elem_copy (VALUE self, VALUE ridx1, VALUE ridx2)
{
CArray *ca;
ca_size_t idx1[CA_RANK_MAX], idx2[CA_RANK_MAX];
ca_size_t addr1 = 0, addr2 = 0;
int8_t i;
ca_size_t k;
int has_mask;
char _val[32];
char *val = _val;
boolean8_t m = 0;
rb_ca_modify(self);
Data_Get_Struct(self, CArray, ca);
ca_update_mask(ca);
has_mask = ( ca->mask ) ? 1 : 0;
if ( ca->bytes > 32 ) {
val = malloc_with_check(ca->bytes);
}
if ( TYPE(ridx1) == T_ARRAY ) {
for (i=0; i<ca->ndim; i++) {
k = NUM2SIZE(rb_ary_entry(ridx1, i));
CA_CHECK_INDEX(k, ca->dim[i]);
idx1[i] = k;
}
ca_fetch_index(ca, idx1, val);
if ( has_mask ) {
ca_fetch_index(ca->mask, idx1, &m);
}
}
else {
k = NUM2SIZE(ridx1);
CA_CHECK_INDEX(k, ca->elements);
addr1 = k;
ca_fetch_addr(ca, addr1, val);
if ( has_mask ) {
ca_fetch_addr(ca->mask, addr1, &m);
}
}
if ( TYPE(ridx2) == T_ARRAY ) {
for (i=0; i<ca->ndim; i++) {
k = NUM2SIZE(rb_ary_entry(ridx2, i));
CA_CHECK_INDEX(k, ca->dim[i]);
idx2[i] = k;
}
ca_store_index(ca, idx2, val);
if ( has_mask ) {
ca_store_index(ca->mask, idx2, &m);
}
}
else {
k = NUM2SIZE(ridx2);
CA_CHECK_INDEX(k, ca->elements);
addr2 = k;
ca_store_addr(ca, addr2, val);
if ( has_mask ) {
ca_store_addr(ca->mask, addr2, &m);
}
}
if ( ca->bytes > 32 ) {
free(val);
}
return self;
}
|
#elem_decr(idx) ⇒ Object
(Element) Decrements the value by 1 at the element of idx.
362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 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 431 432 433 434 435 436 437 438 439 440 |
# File 'ext/carray_element.c', line 362
VALUE
rb_ca_elem_decr (VALUE self, VALUE ridx1)
{
volatile VALUE out;
CArray *ca;
ca_size_t idx1[CA_RANK_MAX];
ca_size_t addr1 = 0;
int8_t i;
ca_size_t k;
int has_index1 = 0;
int has_mask;
char _val[8];
char *val = _val;
boolean8_t m = 0;
rb_ca_modify(self);
Data_Get_Struct(self, CArray, ca);
if ( ! ca_is_integer_type(ca) ) {
rb_raise(rb_eCADataTypeError,
"decremented array should be an integer array");
}
ca_update_mask(ca);
has_mask = ( ca->mask ) ? 1 : 0;
if ( TYPE(ridx1) == T_ARRAY ) {
for (i=0; i<ca->ndim; i++) {
k = NUM2SIZE(rb_ary_entry(ridx1, i));
CA_CHECK_INDEX(k, ca->dim[i]);
idx1[i] = k;
}
if ( has_mask ) {
ca_fetch_index(ca->mask, idx1, &m);
}
if ( m ) {
return Qnil;
}
else {
ca_fetch_index(ca, idx1, val);
}
has_index1 = 1;
}
else {
k = NUM2SIZE(ridx1);
CA_CHECK_INDEX(k, ca->elements);
addr1 = k;
if ( has_mask ) {
ca_fetch_addr(ca->mask, addr1, &m);
}
if ( m ) {
return Qnil;
}
else {
ca_fetch_addr(ca, addr1, val);
}
}
switch ( ca->data_type ) {
case CA_INT8: out = INT2NUM(--*((int8_t*) val)); break;
case CA_UINT8: out = UINT2NUM(--*((uint8_t*) val)); break;
case CA_INT16: out = INT2NUM(--*((int16_t*) val)); break;
case CA_UINT16: out = UINT2NUM(--*((uint16_t*) val)); break;
case CA_INT32: out = INT2NUM(--*((int32_t*) val)); break;
case CA_UINT32: out = UINT2NUM(--*((uint32_t*) val)); break;
case CA_INT64: out = INT2NUM(--*((int64_t*) val)); break;
case CA_UINT64: out = UINT2NUM(--*((uint64_t*) val)); break;
}
if ( has_index1 ) {
ca_store_index(ca, idx1, val);
}
else {
ca_store_addr(ca, addr1, val);
}
return out;
}
|
#elem_fetch(idx) ⇒ Object
(Element) Fetches the object value at the element of idx.
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 |
# File 'ext/carray_element.c', line 245
VALUE
rb_ca_elem_fetch (VALUE self, VALUE ridx)
{
CArray *ca;
ca_size_t idx[CA_RANK_MAX];
ca_size_t addr = 0;
int8_t i;
ca_size_t k;
Data_Get_Struct(self, CArray, ca);
if ( TYPE(ridx) == T_ARRAY ) {
for (i=0; i<ca->ndim; i++) {
k = NUM2SIZE(rb_ary_entry(ridx, i));
CA_CHECK_INDEX(k, ca->dim[i]);
idx[i] = k;
}
return rb_ca_fetch_index(self, idx);
}
else {
k = NUM2SIZE(ridx);
CA_CHECK_INDEX(k, ca->elements);
addr = k;
return rb_ca_fetch_addr(self, addr);
}
}
|
#elem_incr(idx) ⇒ Object
(Element) Increments the value by 1 at the element of idx.
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 |
# File 'ext/carray_element.c', line 277
VALUE
rb_ca_elem_incr (VALUE self, VALUE ridx1)
{
volatile VALUE out;
CArray *ca;
ca_size_t idx1[CA_RANK_MAX];
ca_size_t addr1 = 0;
int8_t i;
ca_size_t k;
int has_index1 = 0;
int has_mask;
char _val[8];
char *val = _val;
boolean8_t m = 0;
rb_ca_modify(self);
Data_Get_Struct(self, CArray, ca);
if ( ! ca_is_integer_type(ca) ) {
rb_raise(rb_eCADataTypeError,
"incremented array should be an integer array");
}
ca_update_mask(ca);
has_mask = ( ca->mask ) ? 1 : 0;
if ( TYPE(ridx1) == T_ARRAY ) {
for (i=0; i<ca->ndim; i++) {
k = NUM2SIZE(rb_ary_entry(ridx1, i));
CA_CHECK_INDEX(k, ca->dim[i]);
idx1[i] = k;
}
if ( has_mask ) {
ca_fetch_index(ca->mask, idx1, &m);
}
if ( m ) {
return Qnil;
}
else {
ca_fetch_index(ca, idx1, val);
}
has_index1 = 1;
}
else {
k = NUM2SIZE(ridx1);
CA_CHECK_INDEX(k, ca->elements);
addr1 = k;
if ( has_mask ) {
ca_fetch_addr(ca->mask, addr1, &m);
}
if ( m ) {
return Qnil;
}
else {
ca_fetch_addr(ca, addr1, val);
}
}
switch ( ca->data_type ) {
case CA_INT8: out = INT2NUM(++*((int8_t*) val)); break;
case CA_UINT8: out = UINT2NUM(++*((uint8_t*) val)); break;
case CA_INT16: out = INT2NUM(++*((int16_t*) val)); break;
case CA_UINT16: out = UINT2NUM(++*((uint16_t*) val)); break;
case CA_INT32: out = INT2NUM(++*((int32_t*) val)); break;
case CA_UINT32: out = UINT2NUM(++*((uint32_t*) val)); break;
case CA_INT64: out = LL2NUM(++*((int64_t*) val)); break;
case CA_UINT64: out = ULL2NUM(++*((uint64_t*) val)); break;
}
if ( has_index1 ) {
ca_store_index(ca, idx1, val);
}
else {
ca_store_addr(ca, addr1, val);
}
return out;
}
|
#elem_masked?(idx) ⇒ Boolean
(Masking, Element) Returns true if the element at given idx is masked.
447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 |
# File 'ext/carray_element.c', line 447
VALUE
rb_ca_elem_test_masked (VALUE self, VALUE ridx1)
{
CArray *ca;
ca_size_t idx1[CA_RANK_MAX];
ca_size_t addr1 = 0;
int8_t i;
ca_size_t k;
boolean8_t m = 0;
Data_Get_Struct(self, CArray, ca);
ca_update_mask(ca);
if ( TYPE(ridx1) == T_ARRAY ) {
for (i=0; i<ca->ndim; i++) {
k = NUM2SIZE(rb_ary_entry(ridx1, i));
CA_CHECK_INDEX(k, ca->dim[i]);
idx1[i] = k;
}
if ( ca->mask ) {
ca_fetch_index(ca->mask, idx1, &m);
}
}
else {
k = NUM2SIZE(ridx1);
CA_CHECK_INDEX(k, ca->elements);
addr1 = k;
if ( ca->mask ) {
ca_fetch_addr(ca->mask, addr1, &m);
}
}
return m ? Qtrue : Qfalse;
}
|
#elem_store(idx, obj) ⇒ Object
(Element) Stores the object value in the element of idx.
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 238 |
# File 'ext/carray_element.c', line 209
VALUE
rb_ca_elem_store (VALUE self, VALUE ridx, VALUE obj)
{
CArray *ca;
ca_size_t idx[CA_RANK_MAX];
ca_size_t addr = 0;
int8_t i;
ca_size_t k;
rb_ca_modify(self);
Data_Get_Struct(self, CArray, ca);
if ( TYPE(ridx) == T_ARRAY ) {
for (i=0; i<ca->ndim; i++) {
k = NUM2SIZE(rb_ary_entry(ridx, i));
CA_CHECK_INDEX(k, ca->dim[i]);
idx[i] = k;
}
rb_ca_store_index(self, idx, obj);
}
else {
k = NUM2SIZE(ridx);
CA_CHECK_INDEX(k, ca->elements);
addr = k;
rb_ca_store_addr(self, addr, obj);
}
return obj;
}
|
#elem_swap(idx1, idx2) ⇒ Object
(Element) Swaps the values at the elements which are specified by arguments.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 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 |
# File 'ext/carray_element.c', line 21
VALUE
rb_ca_elem_swap (VALUE self, VALUE ridx1, VALUE ridx2)
{
CArray *ca;
ca_size_t idx1[CA_RANK_MAX], idx2[CA_RANK_MAX];
ca_size_t addr1 = 0, addr2 = 0;
int8_t i;
ca_size_t k;
int has_mask, has_index1, has_index2;
char _val1[32], _val2[32];
char *val1 = _val1, *val2 = _val2;
boolean8_t m1 = 0, m2 = 0;
rb_ca_modify(self);
Data_Get_Struct(self, CArray, ca);
ca_update_mask(ca);
has_mask = ( ca->mask ) ? 1 : 0;
if ( ca->bytes > 32 ) {
val1 = malloc_with_check(ca->bytes);
val2 = malloc_with_check(ca->bytes);
}
if ( TYPE(ridx1) == T_ARRAY ) {
for (i=0; i<ca->ndim; i++) {
k = NUM2SIZE(rb_ary_entry(ridx1, i));
CA_CHECK_INDEX(k, ca->dim[i]);
idx1[i] = k;
}
has_index1 = 1;
ca_fetch_index(ca, idx1, val1);
if ( has_mask ) {
ca_fetch_index(ca->mask, idx1, &m1);
}
}
else {
k = NUM2SIZE(ridx1);
CA_CHECK_INDEX(k, ca->elements);
addr1 = k;
has_index1 = 0;
ca_fetch_addr(ca, addr1, val1);
if ( has_mask ) {
ca_fetch_addr(ca->mask, addr1, &m1);
}
}
if ( TYPE(ridx2) == T_ARRAY ) {
for (i=0; i<ca->ndim; i++) {
k = NUM2SIZE(rb_ary_entry(ridx2, i));
CA_CHECK_INDEX(k, ca->dim[i]);
idx2[i] = k;
}
has_index2 = 1;
ca_fetch_index(ca, idx2, val2);
if ( has_mask ) {
ca_fetch_index(ca->mask, idx2, &m2);
}
}
else {
k = NUM2SIZE(ridx2);
CA_CHECK_INDEX(k, ca->elements);
addr2 = k;
has_index2 = 0;
ca_fetch_addr(ca, addr2, val2);
if ( has_mask ) {
ca_fetch_addr(ca->mask, addr2, &m2);
}
}
if ( has_index1 ) {
ca_store_index(ca, idx1, val2);
if ( has_mask ) {
ca_store_index(ca->mask, idx1, &m2);
}
}
else {
ca_store_addr(ca, addr1, val2);
if ( has_mask ) {
ca_store_addr(ca->mask, addr1, &m2);
}
}
if ( has_index2 ) {
ca_store_index(ca, idx2, val1);
if ( has_mask ) {
ca_store_index(ca->mask, idx2, &m1);
}
}
else {
ca_store_addr(ca, addr2, val1);
if ( has_mask ) {
ca_store_addr(ca->mask, addr2, &m1);
}
}
if ( ca->bytes > 32 ) {
free(val1);
free(val2);
}
return self;
}
|
#elements ⇒ Object
(Attribute) Returns the number of elements
83 84 85 86 87 88 89 |
# File 'ext/carray_attribute.c', line 83
VALUE
rb_ca_elements (VALUE self)
{
CArray *ca;
Data_Get_Struct(self, CArray, ca);
return SIZE2NUM(ca->elements);
}
|
#empty? ⇒ Boolean
(Inquiry) Returns true if the object is empty.
279 280 281 282 283 284 285 |
# File 'ext/carray_attribute.c', line 279
VALUE
rb_ca_is_empty (VALUE self)
{
CArray *ca;
Data_Get_Struct(self, CArray, ca);
return ( ca->elements == 0 ) ? Qtrue : Qfalse;
}
|
#entity? ⇒ Boolean
(Inquiry) Returns true if self is an entity array (not a virtual array).
235 236 237 238 239 240 241 |
# File 'ext/carray_attribute.c', line 235
VALUE
rb_ca_is_entity (VALUE self)
{
CArray *ca;
Data_Get_Struct(self, CArray, ca);
return ( ca_is_virtual(ca) ) ? Qfalse : Qtrue;
}
|
#extend_as_table(column_names) ⇒ Object
obsolete methods
21 22 23 24 25 26 |
# File 'lib/carray/obsolete.rb', line 21 def extend_as_table (column_names) warn "CArray#extend_as_table will be obsolete" self.extend CArray::TableMethods self.column_names = column_names self end |
#fa ⇒ Object
:nodoc:
136 137 138 139 |
# File 'lib/carray/obsolete.rb', line 136 def fa # :nodoc: warn "CArray#fa will be obsolete, use CArray#t" return self.t end |
#fake ⇒ Object
yard:
class CArray
def fake (data_type, ={:bytes=>0})
end
end
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 |
# File 'ext/ca_obj_fake.c', line 336
VALUE
rb_ca_fake (int argc, VALUE *argv, VALUE self)
{
volatile VALUE obj, rtype, ropt, rbytes = Qnil;
CArray *ca;
int8_t data_type;
ca_size_t bytes;
Data_Get_Struct(self, CArray, ca);
rb_scan_args(argc, argv, "11", (VALUE *) &rtype, (VALUE *) &ropt);
rb_scan_options(ropt, "bytes", &rbytes);
rb_ca_guess_type_and_bytes(rtype, rbytes, &data_type, &bytes);
obj = rb_ca_fake_new(self, data_type, bytes);
rb_ca_data_type_import(obj, rtype);
return obj;
}
|
#false ⇒ Object
Returns the 8-bit integer CArray object filled with 0 which dimension size is same as self. The resulted array represents the logical array which has false for its all elements.
11 12 13 |
# File 'lib/carray/convert.rb', line 11 def false () return template(:boolean) end |
#farray ⇒ Object
yard:
class CArray
# create the virtual transposed array which dimension order is reversed.
def t
end
end
438 439 440 441 442 |
# File 'ext/ca_obj_farray.c', line 438
VALUE
rb_ca_farray (VALUE self)
{
return rb_ca_farray_new(self);
}
|
#field ⇒ Object
yard:
class CArray
# call-seq:
# CArray#field(offset, data_type[, :bytes=>bytes])
# CArray#field(offset, data_class)
# CArray#field(offset, template)
#
def field (offset, data_type)
end
end
558 559 560 561 562 563 564 565 566 567 568 569 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 597 598 599 600 601 602 603 604 605 606 607 |
# File 'ext/ca_obj_field.c', line 558
VALUE
rb_ca_field (int argc, VALUE *argv, VALUE self)
{
volatile VALUE obj, voffset, rtype, ropt, rbytes = Qnil;
CArray *ca;
int8_t data_type;
ca_size_t offset, bytes;
if ( argc == 1 ) {
return rb_ca_field_as_member(self, argv[0]);
}
Data_Get_Struct(self, CArray, ca);
/* CArray#field(offset, data_type[, :bytes=>bytes]) */
/* CArray#field(offset, data_class) */
/* CArray#field(offset, template) */
rb_scan_args(argc, argv, "21", (VALUE *) &voffset, (VALUE *) &rtype, (VALUE *) &ropt);
rb_scan_options(ropt, "bytes", &rbytes);
offset = NUM2SIZE(voffset);
if ( rb_obj_is_carray(rtype) ) {
CArray *ct;
ca_size_t dim[CA_RANK_MAX];
int8_t ndim;
int8_t i, j;
Data_Get_Struct(rtype, CArray, ct);
data_type = CA_FIXLEN;
bytes = ct->bytes * ct->elements;
obj = rb_ca_field_new(self, offset, data_type, bytes);
rb_ca_data_type_inherit(obj, rtype);
ndim = ca->ndim + ct->ndim;
for (i=0; i<ca->ndim; i++) {
dim[i] = ca->dim[i];
}
for (j=0; j<ct->ndim; j++, i++) {
dim[i] = ct->dim[j];
}
obj = rb_ca_refer_new(obj, ct->data_type, ndim, dim, ct->bytes, 0);
}
else {
rb_ca_guess_type_and_bytes(rtype, rbytes, &data_type, &bytes);
obj = rb_ca_field_new(self, offset, data_type, bytes);
rb_ca_data_type_import(obj, rtype);
}
return obj;
}
|
#fields ⇒ Object
(Reference) Returns an array of data class members (fields)
1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 |
# File 'ext/carray_core.c', line 1249
VALUE
rb_ca_fields (VALUE self)
{
VALUE data_class = rb_ca_data_class(self);
volatile VALUE member_names, list;
int i;
if ( NIL_P(data_class) ) {
rb_raise(rb_eRuntimeError, "carray doesn't have data class");
}
member_names = rb_const_get(data_class, rb_intern("MEMBERS"));
list = rb_ary_new2(RARRAY_LEN(member_names));
for (i=0; i<RARRAY_LEN(member_names); i++) {
VALUE name = rb_ary_entry(member_names, i);
rb_ary_store(list, i, rb_ca_field_as_member(self, name));
}
return list;
}
|
#fields_at(*names) ⇒ Object
Returns an array of data class members (fields) with names specified
1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 |
# File 'ext/carray_core.c', line 1272
VALUE
rb_ca_fields_at (int argc, VALUE *argv, VALUE self)
{
VALUE data_class = rb_ca_data_class(self);
volatile VALUE member_names, list;
int i;
if ( NIL_P(data_class) ) {
rb_raise(rb_eRuntimeError, "carray doesn't have data class");
}
member_names = rb_ary_new4(argc, argv);
list = rb_ary_new2(RARRAY_LEN(member_names));
for (i=0; i<RARRAY_LEN(member_names); i++) {
VALUE name = rb_ary_entry(member_names, i);
rb_ary_store(list, i, rb_ca_field_as_member(self, name));
}
return list;
}
|
#fill ⇒ Object
yard:
class CArray
def fill
end
def fill_copy
end
end
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 |
# File 'ext/carray_access.c', line 218
VALUE
rb_ca_fill (VALUE self, VALUE rval)
{
CArray *ca;
rb_ca_modify(self);
Data_Get_Struct(self, CArray, ca);
if ( ca_is_empty(ca) ) {
return rval;
}
if ( rval == CA_UNDEF ) {
boolean8_t one = 1;
ca_update_mask(ca);
if ( ! ca->mask ) {
ca_create_mask(ca);
}
ca_fill(ca->mask, &one);
}
else {
char *fval = malloc_with_check(ca->bytes);
boolean8_t zero = 0;
rb_ca_obj2ptr(self, rval, fval);
if ( ca_has_mask(ca) ) {
ca_fill(ca->mask, &zero);
}
ca_fill(ca, fval);
free(fval);
}
return self;
}
|
#fill_copy ⇒ Object
252 253 254 255 256 257 |
# File 'ext/carray_access.c', line 252
VALUE
rb_ca_fill_copy (VALUE self, VALUE rval)
{
volatile VALUE out = rb_ca_template(self);
return rb_ca_fill(out, rval);
}
|
#first ⇒ Object
87 88 89 |
# File 'lib/carray/basic.rb', line 87 def first self[0] end |
#fixlen(bytes: ) ⇒ Object
(Conversion) Short-Hand of “CArray#to_type(:fixlen, bytes:)”
357 358 359 360 361 362 363 364 365 366 |
# File 'ext/carray_cast.c', line 357
VALUE
rb_ca_to_fixlen (int argc, VALUE *argv, VALUE self)
{
volatile VALUE ropt = rb_pop_options(&argc, &argv);
VALUE list[2];
// rb_scan_args(argc, argv, "0");
list[0] = INT2NUM(CA_FIXLEN);
list[1] = ropt;
return rb_ca_to_type_internal(2, list, self);
}
|
#fixlen? ⇒ Boolean
(Inquiry) Returns true if self is fixed-length type array
400 401 402 403 404 405 406 |
# File 'ext/carray_attribute.c', line 400
VALUE
rb_ca_is_fixlen_type (VALUE self)
{
CArray *ca;
Data_Get_Struct(self, CArray, ca);
return ca_is_fixlen_type(ca) ? Qtrue : Qfalse;
}
|
#flatten ⇒ Object
48 49 50 |
# File 'lib/carray/transform.rb', line 48 def flatten return reshape(elements).to_ca end |
#flattened ⇒ Object
flatten
44 45 46 |
# File 'lib/carray/transform.rb', line 44 def flattened return reshape(elements) end |
#float128 ⇒ Object
(Conversion) Short-Hand of “CArray#to_type(:float128)”
471 472 473 474 |
# File 'ext/carray_cast.c', line 471
VALUE rb_ca_to_float128 (VALUE self)
{
rb_ca_to_type_method_body(CA_FLOAT128);
}
|
#float32 ⇒ Object Also known as: float
(Conversion) Short-Hand of “CArray#to_type(:float32)”
453 454 455 456 |
# File 'ext/carray_cast.c', line 453
VALUE rb_ca_to_float32 (VALUE self)
{
rb_ca_to_type_method_body(CA_FLOAT32);
}
|
#float64 ⇒ Object Also known as: double
(Conversion) Short-Hand of “CArray#to_type(:float64)”
462 463 464 465 |
# File 'ext/carray_cast.c', line 462
VALUE rb_ca_to_float64 (VALUE self)
{
rb_ca_to_type_method_body(CA_FLOAT64);
}
|
#float? ⇒ Boolean
(Inquiry) Returns true if self is float type array
521 522 523 524 525 526 527 |
# File 'ext/carray_attribute.c', line 521
VALUE
rb_ca_is_float_type (VALUE self)
{
CArray *ca;
Data_Get_Struct(self, CArray, ca);
return ca_is_float_type(ca) ? Qtrue : Qfalse;
}
|
#freeze ⇒ Object
Freeze the object.
579 580 581 582 583 584 585 586 |
# File 'ext/carray_test.c', line 579
VALUE
rb_ca_freeze (VALUE self)
{
CArray *ca;
Data_Get_Struct(self, CArray, ca);
ca_set_flag(ca, CA_FLAG_READ_ONLY);
return rb_obj_freeze(self);
}
|
#from_bit_string(bstr, nb) ⇒ Object
96 97 98 99 100 101 102 |
# File 'lib/carray/convert.rb', line 96 def from_bit_string (bstr, nb) hex = CArray.uint8(bstr.length).load_binary(bstr) hex.bits[] = hex.bits[nil,[-1..0]] bits = hex.bits.flatten self.bits[false,[(nb-1)..0]][nil].paste([0], bits) return self end |
#gradate ⇒ Object
2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 |
# File 'ext/carray_stat.c', line 2005
static VALUE
rb_ca_grade (int argc, VALUE *argv, VALUE self)
{
volatile VALUE out, vnum, vmin, vmax;
CArray *ca, *sa;
ca_size_t icls;
rb_scan_args(argc, argv, "12", (VALUE *) &vnum, (VALUE *) &vmin, (VALUE *) &vmax);
if ( NIL_P(vmin) ) {
vmin = rb_funcall(self, rb_intern("min"), 0);
}
if ( NIL_P(vmax) ) {
vmax = rb_funcall(self, rb_intern("max"), 0);
}
Data_Get_Struct(self, CArray, ca);
icls = NUM2LONG(vnum);
if ( icls < 1 ) {
rb_raise(rb_eArgError, "bin number must be larger than 1");
}
out = rb_carray_new_safe(CA_SIZE, ca->ndim, ca->dim, 0, NULL);
Data_Get_Struct(out, CArray, sa);
ca_attach(ca);
if ( ca_has_mask(ca) ) {
ca_create_mask(sa);
ca_setup_mask(sa, ca->mask);
}
switch ( ca->data_type ) {
case CA_BOOLEAN:
case CA_INT8: proc_grade(int8_t, ); break;
case CA_UINT8: proc_grade(uint8_t, ); break;
case CA_INT16: proc_grade(int16_t, ); break;
case CA_UINT16: proc_grade(uint16_t, ); break;
case CA_INT32: proc_grade(int32_t, ); break;
case CA_UINT32: proc_grade(uint32_t, ); break;
case CA_INT64: proc_grade(int64_t, ); break;
case CA_UINT64: proc_grade(uint64_t, ); break;
case CA_FLOAT32: proc_grade(float32_t, ); break;
case CA_FLOAT64: proc_grade(float64_t, ); break;
case CA_FLOAT128: proc_grade(float128_t, ); break;
case CA_OBJECT: proc_grade(VALUE,NUM2DBL); break;
default: rb_raise(rb_eCADataTypeError, "invalid data type");
}
ca_detach(ca);
return out;
}
|
#grade ⇒ Object
rb_define_method(rb_cCArray, “histogram”, rb_ca_histogram, -1);
2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 |
# File 'ext/carray_stat.c', line 2005
static VALUE
rb_ca_grade (int argc, VALUE *argv, VALUE self)
{
volatile VALUE out, vnum, vmin, vmax;
CArray *ca, *sa;
ca_size_t icls;
rb_scan_args(argc, argv, "12", (VALUE *) &vnum, (VALUE *) &vmin, (VALUE *) &vmax);
if ( NIL_P(vmin) ) {
vmin = rb_funcall(self, rb_intern("min"), 0);
}
if ( NIL_P(vmax) ) {
vmax = rb_funcall(self, rb_intern("max"), 0);
}
Data_Get_Struct(self, CArray, ca);
icls = NUM2LONG(vnum);
if ( icls < 1 ) {
rb_raise(rb_eArgError, "bin number must be larger than 1");
}
out = rb_carray_new_safe(CA_SIZE, ca->ndim, ca->dim, 0, NULL);
Data_Get_Struct(out, CArray, sa);
ca_attach(ca);
if ( ca_has_mask(ca) ) {
ca_create_mask(sa);
ca_setup_mask(sa, ca->mask);
}
switch ( ca->data_type ) {
case CA_BOOLEAN:
case CA_INT8: proc_grade(int8_t, ); break;
case CA_UINT8: proc_grade(uint8_t, ); break;
case CA_INT16: proc_grade(int16_t, ); break;
case CA_UINT16: proc_grade(uint16_t, ); break;
case CA_INT32: proc_grade(int32_t, ); break;
case CA_UINT32: proc_grade(uint32_t, ); break;
case CA_INT64: proc_grade(int64_t, ); break;
case CA_UINT64: proc_grade(uint64_t, ); break;
case CA_FLOAT32: proc_grade(float32_t, ); break;
case CA_FLOAT64: proc_grade(float64_t, ); break;
case CA_FLOAT128: proc_grade(float128_t, ); break;
case CA_OBJECT: proc_grade(VALUE,NUM2DBL); break;
default: rb_raise(rb_eCADataTypeError, "invalid data type");
}
ca_detach(ca);
return out;
}
|
#grid ⇒ Object
yard:
class CArray
def grid
end
end
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 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 |
# File 'ext/ca_obj_grid.c', line 611
VALUE
rb_ca_grid (int argc, VALUE *argv, VALUE self)
{
volatile VALUE obj, ridx, rval;
volatile VALUE list = rb_ary_new();
CArray *ca;
CArray *ci[CA_RANK_MAX];
ca_size_t dim[CA_RANK_MAX];
CArray *grid[CA_RANK_MAX];
ca_size_t i;
Data_Get_Struct(self, CArray, ca);
ridx = rb_ary_new4(argc, argv);
if ( RARRAY_LEN(ridx) > ca->ndim ) {
rb_raise(rb_eArgError, "# of arguments doesn't equal to the ndim");
}
else if ( RARRAY_LEN(ridx) < ca->ndim ) {
volatile VALUE ref;
CArray *cv;
ca_size_t rdim[CA_RANK_MAX];
ca_size_t rndim = RARRAY_LEN(ridx);
ca_size_t j = 0, k;
for (i=0; i<rndim; i++) {
rval = rb_ary_entry(ridx, i);
if ( rb_obj_is_carray(rval) ) {
Data_Get_Struct(rval, CArray, cv);
rdim[i] = 1;
for (k=0; k<cv->ndim; k++) {
rdim[i] *= ca->dim[j];
j += 1;
}
}
else {
rdim[i] = ca->dim[j];
j += 1;
}
}
if ( j != ca->ndim ) {
rb_raise(rb_eArgError, "invalid total ndim of args");
}
ref = rb_ca_refer_new(self, ca->data_type, rndim, rdim, ca->bytes, 0);
return rb_ca_grid(argc, argv, ref);
}
for (i=0; i<RARRAY_LEN(ridx); i++) {
rval = rb_ary_entry(ridx, i);
if ( NIL_P(rval) ) {
ci[i] = NULL;
dim[i] = ca->dim[i];
grid[i] = NULL;
}
else {
if ( rb_obj_is_carray(rval) ) {
if ( rb_ca_is_boolean_type(rval) ) {
rval = rb_ca_where(rval);
}
}
else if ( rb_obj_is_kind_of(rval, rb_cRange) ) {
rval = rb_funcall(rb_mKernel, rb_intern("CA_SIZE"), 1, rval);
}
else if ( TYPE(rval) == T_ARRAY ) {
rb_raise(rb_eRuntimeError, "not implemented for this index");
}
ci[i] = ca_wrap_readonly(rval, CA_SIZE);
rb_ary_push(list, rval);
ca_attach(ci[i]);
if ( ca_is_any_masked(ci[i]) ) {
dim[i] = ci[i]->elements - ca_count_masked(ci[i]);
}
else {
dim[i] = ci[i]->elements;
}
grid[i] = ci[i];
}
}
obj = rb_ca_grid_new(self, dim, grid);
for (i=0; i<RARRAY_LEN(ridx); i++) {
if ( ci[i] ) {
ca_detach(ci[i]);
}
}
return obj;
}
|
#has_attribute? ⇒ Boolean
67 68 69 70 71 72 73 |
# File 'lib/carray/basic.rb', line 67 def has_attribute? if ( not @attribute ) or @attribute.empty? return false else return true end end |
#has_data_class? ⇒ Boolean
(Inquiry) Returns true if self is fixed-length type and has the data class.
669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 |
# File 'ext/carray_attribute.c', line 669
VALUE
rb_ca_has_data_class (VALUE self)
{
CArray *ca;
Data_Get_Struct(self, CArray, ca);
if ( ca_test_flag(ca, CA_FLAG_NOT_DATA_CLASS) ) {
return Qfalse;
}
else {
if ( ca_is_fixlen_type(ca) ) {
if ( RTEST(rb_ca_data_class(self)) ) {
return Qtrue;
}
}
ca_set_flag(ca, CA_FLAG_NOT_DATA_CLASS);
return Qfalse;
}
}
|
#has_mask? ⇒ Boolean
(Masking, Inquiry) Returns true if self has the mask array.
572 573 574 575 576 577 578 |
# File 'ext/carray_mask.c', line 572
VALUE
rb_ca_has_mask (VALUE self)
{
CArray *ca;
Data_Get_Struct(self, CArray, ca);
return ( ca_has_mask(ca) ) ? Qtrue : Qfalse;
}
|
#hash ⇒ Object
(Inquiry) Returns the hash value of the object.
547 548 549 550 551 552 553 554 555 556 |
# File 'ext/carray_test.c', line 547
VALUE
rb_ca_hash (VALUE self)
{
CArray *ca;
int32_t hash;
Data_Get_Struct(self, CArray, ca);
hash = ca_hash(ca);
return ULONG2NUM(hash);
}
|
#imag ⇒ Object
Return the imaginary part of self. If self is a complex array, the resulted array is CAMember object refers the appropriate part of self. In this case, you change the resulted array, the original array is also changed.
Otherwise, the resulted array is a dummy CArray object filled with 0. In this case, the change in the resulted array does not affect the original array. For this purpose, you should explicitly convert the array to complex array.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/carray/math.rb', line 55 def imag if not @__imag__ if complex? @__imag__ = case data_type when CA_CMPLX64 field(4, CA_FLOAT32) when CA_CMPLX128 field(8, CA_FLOAT64) when CA_CMPLX128 field(16, CA_FLOAT128) end else @__imag__ = self.template { 0 } end end return @__imag__ end |
#imag=(val) ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/carray/math.rb', line 73 def imag= (val) if complex? imag[] = val else raise "not a complex array" end end |
#incr_addr(addr) ⇒ Object
(Element) Increment the value at the element of addr.
490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 |
# File 'ext/carray_element.c', line 490
static VALUE
rb_ca_incr_addr (volatile VALUE self, volatile VALUE raddr)
{
CArray *ca, *ci;
int64_t *q, *p;
ca_size_t k, elements;
ca_size_t i;
boolean8_t *m;
rb_ca_modify(self);
self = rb_ca_wrap_writable(self, INT2NUM(CA_INT64));
raddr = rb_ca_wrap_readonly(raddr, INT2NUM(CA_INT64));
Data_Get_Struct(self, CArray, ca);
Data_Get_Struct(raddr, CArray, ci);
ca_attach_n(2, ca, ci);
q = (int64_t *) ca->ptr;
p = (int64_t *) ci->ptr;
m = ( ci->mask ) ? (boolean8_t *) ci->mask->ptr : NULL;
elements = ca->elements;
if ( m ) {
#ifdef _OPENMP
#pragma omp parallel for
#endif
for (i=0; i<ci->elements; i++) {
if ( ! *(m+i) ) {
k = *(p+i);
CA_CHECK_INDEX(k, elements);
*(q + k) += 1;
}
}
}
else {
#ifdef _OPENMP
#pragma omp parallel for
#endif
for (i=0; i<ci->elements; i++) {
k = *(p+i);
CA_CHECK_INDEX(k, elements);
*(q + k) += 1;
}
}
ca_sync(ca);
ca_detach_n(2, ca, ci);
return Qnil;
}
|
#index(n = 0) ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/carray/basic.rb', line 119 def index (n = 0) unless n.is_a?(Integer) raise ArgumentError, "argument should be an integer" end if n.between?(0, ndim-1) return CArray.int32(dim[n]).seq! else raise ArgumentError, "invalid dimension specifier #{n} (0..#{self.ndim-1})" end end |
#index2addr ⇒ Object
yard:
class CArray
def index2addr (*index)
end
end
1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 |
# File 'ext/carray_access.c', line 1804
VALUE
rb_ca_index2addr (int argc, VALUE *argv, VALUE self)
{
volatile VALUE obj;
CArray *ca, *co, *cidx[CA_RANK_MAX];
ca_size_t *q, *p[CA_RANK_MAX], s[CA_RANK_MAX];
ca_size_t *dim;
ca_size_t addr, elements = 0;
int8_t i;
ca_size_t k, n;
boolean8_t *m;
int all_number = 1;
Data_Get_Struct(self, CArray, ca);
if ( argc != ca->ndim ) {
rb_raise(rb_eRuntimeError, "invalid ndim of index");
}
for (i=0; i<ca->ndim; i++) {
if ( ! rb_obj_is_kind_of(argv[i], rb_cInteger) ) {
all_number = 0;
break;
}
}
if ( all_number ) {
dim = ca->dim;
addr = 0;
for (i=0; i<ca->ndim; i++) {
k = NUM2SIZE(argv[i]);
CA_CHECK_INDEX(k, dim[i]);
addr = dim[i] * addr + k;
}
return SIZE2NUM(addr);
}
elements = 1;
for (i=0; i<ca->ndim; i++) {
cidx[i] = ca_wrap_readonly(argv[i], CA_SIZE);
if ( ! ca_is_scalar(cidx[i]) ) {
if ( elements == 1 ) {
elements = cidx[i]->elements;
}
else if ( elements != cidx[i]->elements ) {
rb_raise(rb_eRuntimeError, "mismatch in # of elements");
}
}
}
for (i=0; i<ca->ndim; i++) {
ca_attach(cidx[i]);
ca_set_iterator(1, cidx[i], &p[i], &s[i]);
}
obj = rb_carray_new(CA_SIZE, 1, &elements, 0, NULL);
Data_Get_Struct(obj, CArray, co);
q = (ca_size_t *) co->ptr;
ca_copy_mask_overwrite_n(co, elements, ca->ndim, cidx);
m = ( co->mask ) ? (boolean8_t *) co->mask->ptr : NULL;
dim = ca->dim;
if ( m ) {
n = elements;
while ( n-- ) {
if ( !*m ) {
addr = 0;
for (i=0; i<ca->ndim; i++) {
k = *(p[i]);
p[i]+=s[i];
CA_CHECK_INDEX(k, dim[i]);
addr = dim[i] * addr + k;
}
*q = addr;
}
else {
for (i=0; i<ca->ndim; i++) {
p[i]+=s[i];
}
}
m++; q++;
}
}
else {
n = elements;
while ( n-- ) {
addr = 0;
for (i=0; i<ca->ndim; i++) {
k = *(p[i]);
p[i]+=s[i];
CA_CHECK_INDEX(k, dim[i]);
addr = dim[i] * addr + k;
}
*q = addr;
q++;
}
}
for (i=0; i<ca->ndim; i++) {
ca_detach(cidx[i]);
}
return obj;
}
|
#indices ⇒ Object
135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/carray/basic.rb', line 135 def indices list = Array.new(ndim) {|i| rpt = self.dim rpt[i] = :% index(i)[*rpt] } if block_given? return yield(*list) else return list end end |
#inherit_mask(*others: ) ⇒ Object
(Masking, Destructive) Sets the mask array of self by the logical sum of the mask states of self and arrays given in arguments.
976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 |
# File 'ext/carray_mask.c', line 976
static VALUE
rb_ca_inherit_mask_method (int argc, VALUE *argv, VALUE self)
{
CArray **slist;
CArray *ca, *cs;
int i;
rb_ca_modify(self);
Data_Get_Struct(self, CArray, ca);
slist = malloc_with_check(sizeof(CArray *)*argc);
for (i=0; i<argc; i++) {
if ( rb_obj_is_carray(argv[i]) ) {
Data_Get_Struct(argv[i], CArray, cs);
slist[i] = cs;
}
else {
slist[i] = NULL;
}
}
ca_copy_mask_overlay_n(ca, ca->elements, argc, slist);
free(slist);
return self;
}
|
#inherit_mask_replace(*others) ⇒ Object
Sets the mask array of self by the logical sum of the mask states of arrays given in arguments. This method does not inherit the mask states of itself (different point from ‘CArray#inherit_mask`)
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 |
# File 'ext/carray_mask.c', line 1055
static VALUE
rb_ca_inherit_mask_replace_method (int argc, VALUE *argv, VALUE self)
{
CArray **slist;
CArray *ca, *cs;
int i;
rb_ca_modify(self);
Data_Get_Struct(self, CArray, ca);
slist = malloc_with_check(sizeof(CArray *)*argc);
for (i=0; i<argc; i++) {
if ( rb_obj_is_carray(argv[i]) ) {
Data_Get_Struct(argv[i], CArray, cs);
slist[i] = cs;
}
else {
slist[i] = NULL;
}
}
ca_copy_mask_overwrite_n(ca, ca->elements, argc, slist);
free(slist);
return self;
}
|
#initialize_copy(other) ⇒ Object
949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 |
# File 'ext/ca_obj_array.c', line 949
static VALUE
rb_ca_initialize_copy (VALUE self, VALUE other)
{
CArray *ca, *cs;
rb_call_super(1, &other);
Data_Get_Struct(self, CArray, ca);
Data_Get_Struct(other, CArray, cs);
ca_update_mask(cs);
carray_setup(ca, cs->data_type, cs->ndim, cs->dim, cs->bytes, cs->mask);
memcpy(ca->ptr, cs->ptr, ca_length(cs));
return self;
}
|
#insert_block(offset, bsize, &block) ⇒ Object
insert
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 70 71 72 73 |
# File 'lib/carray/compose.rb', line 45 def insert_block (offset, bsize, &block) if offset.size != ndim or bsize.size != ndim raise "ndim mismatch" end newdim = dim grids = dim.map{|d| CArray.int32(d) } ndim.times do |i| if offset[i] < 0 offset[i] += dim[i] end if offset[i] < 0 or offset[i] >= dim[i] or bsize[i] < 0 raise "invalid offset or size" end if bsize[i] > 0 newdim[i] += bsize[i] end grids[i][0...offset[i]].seq! grids[i][offset[i]..-1].seq!(offset[i]+bsize[i]) end out = CArray.new(data_type, newdim) if block_given? sel = out.true sel[*grids] = 0 out[sel] = block.call end out[*grids] = self return out end |
#inspect ⇒ Object
217 218 219 |
# File 'lib/carray/inspect.rb', line 217 def inspect return CArray::Inspector.new(self).inspect_string end |
#int16 ⇒ Object Also known as: short
(Conversion) Short-Hand of “CArray#to_type(:int16)”
399 400 401 402 |
# File 'ext/carray_cast.c', line 399
VALUE rb_ca_to_int16 (VALUE self)
{
rb_ca_to_type_method_body(CA_INT16);
}
|
#int32 ⇒ Object Also known as: int
(Conversion) Short-Hand of “CArray#to_type(:int32)”
417 418 419 420 |
# File 'ext/carray_cast.c', line 417
VALUE rb_ca_to_int32 (VALUE self)
{
rb_ca_to_type_method_body(CA_INT32);
}
|
#int64 ⇒ Object
(Conversion) Short-Hand of “CArray#to_type(:int64)”
435 436 437 438 |
# File 'ext/carray_cast.c', line 435
VALUE rb_ca_to_int64 (VALUE self)
{
rb_ca_to_type_method_body(CA_INT64);
}
|
#int8 ⇒ Object
(Conversion) Short-Hand of “CArray#to_type(:int8)”
381 382 383 384 |
# File 'ext/carray_cast.c', line 381
VALUE rb_ca_to_int8 (VALUE self)
{
rb_ca_to_type_method_body(CA_INT8);
}
|
#integer? ⇒ Boolean
(Inquiry) Returns true if self is integer type array
468 469 470 471 472 473 474 |
# File 'ext/carray_attribute.c', line 468
VALUE
rb_ca_is_integer_type (VALUE self)
{
CArray *ca;
Data_Get_Struct(self, CArray, ca);
return ca_is_integer_type(ca) ? Qtrue : Qfalse;
}
|
#invert_mask ⇒ Object
(Masking, Destructive) Inverts mask state.
960 961 962 963 964 965 966 967 |
# File 'ext/carray_mask.c', line 960
VALUE
rb_ca_invert_mask (VALUE self)
{
CArray *ca;
Data_Get_Struct(self, CArray, ca);
ca_invert_mask(ca);
return self;
}
|
#is_close(other, atol) ⇒ Object
100 101 102 |
# File 'lib/carray/math.rb', line 100 def is_close (other, atol) return ((self - other).abs <= atol) end |
#is_divisible(n) ⇒ Object
104 105 106 107 108 109 |
# File 'lib/carray/math.rb', line 104 def is_divisible (n) unless integer? raise "data type of reciever of CArray#divisible? should be integer." end return (self % n).eq(0) end |
#is_equiv(other, rtol) ⇒ Object
94 95 96 97 98 |
# File 'lib/carray/math.rb', line 94 def is_equiv (other, rtol) exact_eq = self.eq(other) relative_eq = ((self - other).abs/CAMath.max(self.abs, other.abs) <= rtol) return (exact_eq).or(relative_eq) end |
#is_masked ⇒ Object
(Masking, Element-Wise Inquiry) Returns new boolean type array of same shape with self. The returned array has 1 for the masked elements and 0 for not-masked elements.
749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 |
# File 'ext/carray_mask.c', line 749
VALUE
rb_ca_is_masked (VALUE self)
{
volatile VALUE mask;
CArray *ca, *cm, *co;
boolean8_t zero = 0;
boolean8_t *m, *p;
ca_size_t i;
Data_Get_Struct(self, CArray, ca);
co = carray_new(CA_BOOLEAN, ca->ndim, ca->dim, ca->bytes, NULL);
ca_update_mask(ca);
if ( ! ca->mask ) {
ca_fill(co, &zero);
}
else {
mask = rb_ca_mask_array(self);
Data_Get_Struct(mask, CArray, cm);
ca_attach(cm);
m = (boolean8_t *) cm->ptr;
p = (boolean8_t *) co->ptr;
for (i=0; i<ca->elements; i++) {
*p = ( *m ) ? 1 : 0;
m++; p++;
}
ca_detach(cm);
}
return ca_wrap_struct(co);
}
|
#is_not_divisible(n) ⇒ Object
111 112 113 114 115 116 |
# File 'lib/carray/math.rb', line 111 def is_not_divisible (n) unless integer? raise "data type of reciever of CArray#divisible? should be integer." end return (self % n).ne(0) end |
#is_not_masked ⇒ Object
(Masking, Element-Wise Inquiry) Returns new boolean type array of same shape with self. The returned array has 0 for the masked elements and 1 for not-masked elements.
790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 |
# File 'ext/carray_mask.c', line 790
VALUE
rb_ca_is_not_masked (VALUE self)
{
volatile VALUE mask;
CArray *ca, *cm, *co;
boolean8_t one = 1;
boolean8_t *m, *p;
ca_size_t i;
Data_Get_Struct(self, CArray, ca);
co = carray_new(CA_BOOLEAN, ca->ndim, ca->dim, ca->bytes, NULL);
ca_update_mask(ca);
if ( ! ca->mask ) {
ca_fill(co, &one);
}
else {
mask = rb_ca_mask_array(self);
Data_Get_Struct(mask, CArray, cm);
ca_attach(cm);
m = (boolean8_t *) cm->ptr;
p = (boolean8_t *) co->ptr;
for (i=0; i<ca->elements; i++) {
*p = ( *m ) ? 0 : 1;
m++; p++;
}
ca_detach(cm);
}
return ca_wrap_struct(co);
}
|
#is_real ⇒ Object
128 129 130 131 132 133 134 135 136 |
# File 'lib/carray/math.rb', line 128 def is_real if complex? imag.eq(0) elsif numeric? self.true else nil end end |
#join(*argv) ⇒ Object
Array#join like method
> a = CArray.object(3,3).seq(“a”,:succ)
> <CArray.object(3,3): elem=9 mem=72b
[ [ “a”, “b”, “c” ],
[ "d", "e", "f" ],
[ "g", "h", "i" ] ]>
> a.join(“n”,“,”)
> “a,b,cnd,e,fng,h,i”
73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/carray/convert.rb', line 73 def join (*argv) case argv.size when 0 return to_a.join() when 1 sep = argv.shift return to_a.join(sep) else sep = argv.shift return self[:i, false].map { |s| s[0, false].join(*argv) }.join(sep) end end |
#last ⇒ Object
91 92 93 |
# File 'lib/carray/basic.rb', line 91 def last self[-1] end |
#elements ⇒ Object
(Attribute) Returns the number of elements
83 84 85 86 87 88 89 |
# File 'ext/carray_attribute.c', line 83
VALUE
rb_ca_elements (VALUE self)
{
CArray *ca;
Data_Get_Struct(self, CArray, ca);
return SIZE2NUM(ca->elements);
}
|
#load_binary(io) ⇒ Object
(IO) Loads the value array from the given IO stream
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 238 239 240 |
# File 'ext/carray_conversion.c', line 202
static VALUE
rb_ca_load_binary (VALUE self, VALUE io)
{
CArray *ca;
Data_Get_Struct(self, CArray, ca);
if ( ca_is_object_type(ca) ) {
rb_raise(rb_eCADataTypeError, "don't load object array");
}
ca_allocate(ca);
switch ( TYPE(io) ) {
case T_STRING:
if ( ca_length(ca) > RSTRING_LEN(io) ) {
rb_raise(rb_eRuntimeError,
"data size mismatch (%lld for %lld)",
(ca_size_t) RSTRING_LEN(io), (ca_size_t) ca_length(ca));
}
memcpy(ca->ptr, StringValuePtr(io), ca_length(ca));
OBJ_INFECT(self, io);
break;
default:
if ( rb_respond_to(io, rb_intern("read") ) ) {
VALUE buf = rb_funcall(io, rb_intern("read"), 1, SIZE2NUM(ca_length(ca)));
memcpy(ca->ptr, StringValuePtr(buf), ca_length(ca));
OBJ_INFECT(self, io);
}
else {
rb_raise(rb_eRuntimeError, "IO like object should have 'read' method");
}
}
ca_sync(ca);
ca_detach(ca);
return self;
}
|
#map(&block) ⇒ Object
Returns map
25 26 27 |
# File 'lib/carray/convert.rb', line 25 def map (&block) return self.convert(CA_OBJECT, &block).to_a end |
#map!({|elem| ... }) ⇒ Object
(Iterator, Destructive) Iterates all elements of the object and stores the return from the block to the element.
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'ext/carray_loop.c', line 179
static VALUE
rb_ca_map_bang (VALUE self)
{
volatile VALUE obj;
CArray *ca;
ca_size_t elements = NUM2SIZE(rb_ca_elements(self));
ca_size_t i;
#if RUBY_VERSION_CODE >= 190
RETURN_ENUMERATOR(self, 0, 0);
#endif
rb_ca_modify(self);
Data_Get_Struct(self, CArray, ca);
ca_attach(ca);
for (i=0; i<elements; i++) {
obj = rb_yield(rb_ca_fetch_addr(self, i));
rb_ca_store_addr(self, i, obj);
}
ca_sync(ca);
ca_detach(ca);
return self;
}
|
#map_addr!({|addr| ... }) ⇒ Object
- TBD
388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 |
# File 'ext/carray_loop.c', line 388
static VALUE
rb_ca_map_addr_bang (VALUE self)
{
volatile VALUE obj;
CArray *ca;
ca_size_t elements = NUM2SIZE(rb_ca_elements(self));
ca_size_t i;
#if RUBY_VERSION_CODE >= 190
RETURN_ENUMERATOR(self, 0, 0);
#endif
rb_ca_modify(self);
Data_Get_Struct(self, CArray, ca);
ca_attach(ca);
for (i=0; i<elements; i++) {
obj = rb_yield(SIZE2NUM(i));
rb_ca_store_addr(self, i, obj);
}
ca_sync(ca);
ca_detach(ca);
return self;
}
|
#map_index!({|idx| ... }) ⇒ Object
- TBD
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 |
# File 'ext/carray_loop.c', line 333
static VALUE
rb_ca_map_index_bang (VALUE self)
{
volatile VALUE ridx;
CArray *ca;
ca_size_t idx[CA_RANK_MAX];
int8_t ndim = NUM2INT(rb_ca_ndim(self));
#if RUBY_VERSION_CODE >= 190
RETURN_ENUMERATOR(self, 0, 0);
#endif
rb_ca_modify(self);
Data_Get_Struct(self, CArray, ca);
ca_attach(ca);
ridx = rb_ary_new2(ndim);
rb_ca_map_index_bang_internal(self, 0, idx, ridx);
ca_sync(ca);
ca_detach(ca);
return self;
}
|
#map_with_addr!({|elem, addr| ... }) ⇒ Object
- TBD
359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 |
# File 'ext/carray_loop.c', line 359
static VALUE
rb_ca_map_with_addr_bang (VALUE self)
{
volatile VALUE obj;
CArray *ca;
ca_size_t elements = NUM2SIZE(rb_ca_elements(self));
ca_size_t i;
#if RUBY_VERSION_CODE >= 190
RETURN_ENUMERATOR(self, 0, 0);
#endif
rb_ca_modify(self);
Data_Get_Struct(self, CArray, ca);
ca_attach(ca);
for (i=0; i<elements; i++) {
obj = rb_yield_values(2, rb_ca_fetch_addr(self, i), SIZE2NUM(i));
rb_ca_store_addr(self, i, obj);
}
ca_sync(ca);
ca_detach(ca);
return self;
}
|
#map_with_index({|elem, idx| ... }) ⇒ Object
- TBD
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 |
# File 'ext/carray_loop.c', line 281
static VALUE
rb_ca_map_with_index_bang (VALUE self)
{
volatile VALUE ridx;
CArray *ca;
ca_size_t idx[CA_RANK_MAX];
int8_t ndim = NUM2INT(rb_ca_ndim(self));
#if RUBY_VERSION_CODE >= 190
RETURN_ENUMERATOR(self, 0, 0);
#endif
rb_ca_modify(self);
Data_Get_Struct(self, CArray, ca);
ca_attach(ca);
ridx = rb_ary_new2(ndim);
rb_ca_map_with_index_bang_internal(self, 0, idx, ridx);
ca_sync(ca);
ca_detach(ca);
return self;
}
|
#marshal_dump ⇒ Object
for Marshal
220 221 222 223 224 225 226 |
# File 'lib/carray/serialize.rb', line 220 def marshal_dump () if self.class != CArray and self.class != CScalar return CArray.dump(self.to_ca) # raise TypeError, "can't dump a virtual or wrapped array." end return CArray.dump(self) end |
#marshal_load(data) ⇒ Object
228 229 230 231 232 |
# File 'lib/carray/serialize.rb', line 228 def marshal_load (data) io = StringIO.new(data) ca = CArray.load(io) initialize_copy(ca) end |
#mask ⇒ Object
(Masking, Inquiry) Returns new array which refers the mask state of self. The mask array can’t be set mask.
672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 |
# File 'ext/carray_mask.c', line 672
VALUE
rb_ca_mask_array (VALUE self)
{
VALUE obj;
CArray *ca;
Data_Get_Struct(self, CArray, ca);
ca_update_mask(ca);
if ( ca->mask ) {
obj = Data_Wrap_Struct(ca_class[ca->mask->obj_type],
ca_mark, ca_free_nop, ca->mask);
rb_ivar_set(obj, rb_intern("masked_array"), self);
if ( OBJ_FROZEN(self) ) {
rb_ca_freeze(obj);
}
return obj;
}
else {
return INT2NUM(0);
}
}
|
#mask=(new_mask) ⇒ Object
(Mask, Modification) Asigns new_mask to the mask array of self. If self doesn’t have a mask array, it will be created before asignment.
702 703 704 705 706 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 |
# File 'ext/carray_mask.c', line 702
VALUE
rb_ca_set_mask (VALUE self, VALUE rval)
{
volatile VALUE rmask = rval;
CArray *ca, *cv;
rb_ca_modify(self);
Data_Get_Struct(self, CArray, ca);
if ( ca_is_value_array(ca) ) {
rb_raise(rb_eRuntimeError,
"can not create mask for the value array");
}
if ( ca_is_mask_array(ca) ) {
rb_raise(rb_eRuntimeError,
"can not create mask for the mask array");
}
ca_update_mask(ca);
if ( ! ca->mask ) {
ca_create_mask(ca);
}
if ( rb_obj_is_carray(rmask) ) {
Data_Get_Struct(rmask, CArray, cv);
if ( ! ca_is_boolean_type(cv) ) {
cv = ca_wrap_readonly(rval, CA_BOOLEAN);
}
ca_setup_mask(ca, cv);
ca_copy_mask_overlay(ca, ca->elements, 1, cv);
return rval;
}
else {
return rb_ca_store_all(rb_ca_mask_array(self), rmask);
}
}
|
#mask_array? ⇒ Boolean
(Inquiry) Returns true if self is mask array (don’t confuse with “masked array”)
345 346 347 348 349 350 351 |
# File 'ext/carray_attribute.c', line 345
VALUE
rb_ca_is_mask_array (VALUE self)
{
CArray *ca;
Data_Get_Struct(self, CArray, ca);
return ( ca_is_mask_array(ca) ) ? Qtrue : Qfalse;
}
|
#maskout(*argv) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/carray/mask.rb', line 74 def maskout (*argv) obj = self.to_ca case argv.size when 1 val = argv.first case val when CArray, Symbol obj[val] = UNDEF else obj[:eq, val] = UNDEF end else obj[*argv] = UNDEF end return obj end |
#maskout!(*argv) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/carray/mask.rb', line 58 def maskout! (*argv) case argv.size when 1 val = argv.first case val when CArray, Symbol self[val] = UNDEF else self[:eq, val] = UNDEF end else self[*argv] = UNDEF end return self end |
#matchup(ref) ⇒ Object
matchup
97 98 99 100 101 102 |
# File 'lib/carray/basic.rb', line 97 def matchup (ref) ri = ref.sort_addr rs = ref[ri].to_ca si = rs.bsearch(self) return ri.project(si) end |
#matchup_nearest(ref, direction: "round") ⇒ Object
104 105 106 107 108 109 110 |
# File 'lib/carray/basic.rb', line 104 def matchup_nearest (ref, direction: "round") ri = ref.sort_addr rs = ref[ri].to_ca si = rs.section(self).send(direction.intern).int64 si.trim!(0,si.size) return ri[si].to_ca end |
#max_by(&block) ⇒ Object
73 74 75 76 77 78 79 80 |
# File 'lib/carray/ordering.rb', line 73 def max_by (&block) if empty? return UNDEF else addr = convert(:object, &block).max_addr return self[addr] end end |
#max_with(*others) ⇒ Object
82 83 84 85 86 87 88 89 |
# File 'lib/carray/ordering.rb', line 82 def max_with (*others) if empty? return ([self] + others).map { |x| UNDEF } else addr = max_addr return ([self] + others).map { |x| x[addr] } end end |
#median(*argv) ⇒ Object
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 |
# File 'lib/carray/math.rb', line 239 def median (*argv) opt = argv.last.is_a?(Hash) ? argv.pop : {} min_count = opt[:mask_limit] if min_count and min_count < 0 min_count += elements end fill_value = opt[:fill_value] if argv.empty? if has_mask? if min_count and count_masked() > min_count return fill_value || UNDEF end c = self[:is_not_masked].sort n = self.count_not_masked else c = self.sort n = c.elements end if n == 0 return fill_value || UNDEF else return (c[(n-1)/2] + c[n/2])/2.0 end else raise "CArray#median is not implemented for multiple ndims" end end |
#members ⇒ Object
(Inquiry) Returns data class member names
1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 |
# File 'ext/carray_core.c', line 1186
VALUE
rb_ca_members (VALUE self)
{
VALUE data_class = rb_ca_data_class(self);
if ( NIL_P(data_class) ) {
rb_raise(rb_eRuntimeError, "carray doesn't have data class");
}
else {
return rb_obj_clone(rb_const_get(data_class, rb_intern("MEMBERS")));
}
}
|
#min_by(&block) ⇒ Object
91 92 93 94 95 96 97 98 |
# File 'lib/carray/ordering.rb', line 91 def min_by (&block) if empty? return UNDEF else addr = convert(:object, &block).min_addr return self[addr] end end |
#min_with(*others) ⇒ Object
100 101 102 103 104 105 106 107 |
# File 'lib/carray/ordering.rb', line 100 def min_with (*others) if empty? return ([self] + others).map { |x| UNDEF } else addr = min_addr return ([self] + others).map { |x| x[addr] } end end |
#mul_add(weight, min_count = nil, fill_value = nil) ⇒ Object
- TBD
540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 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 597 598 599 600 601 602 603 604 605 606 607 |
# File 'ext/carray_operator.c', line 540
static VALUE
rb_ca_mul_add (int argc, VALUE *argv, volatile VALUE self)
{
volatile VALUE out;
volatile VALUE weight = Qnil;
volatile VALUE rmin_count = Qnil;
volatile VALUE rfval = Qnil;
CArray *ca, *cw;
boolean8_t *mi = NULL;
ca_size_t min_count;
/* FIXME: to parse :mask_limit, :fill_value */
rb_scan_args(argc, argv, "12", (VALUE *) &weight, (VALUE *) &rmin_count, (VALUE *) &rfval);
/* do implicit casting and resolving unbound repeat array */
rb_ca_cast_self_or_other(&self, &weight);
Data_Get_Struct(self, CArray, ca);
Data_Get_Struct(weight, CArray, cw);
/* checking elements and data_type */
ca_check_same_elements(ca, cw);
ca_check_same_data_type(ca, cw);
if ( ca->elements == 0 ) {
return ( NIL_P(rfval) ) ? CA_UNDEF : rfval;
}
if ( ca_has_mask(ca) || ca_has_mask(cw) ) {
mi = ca_allocate_mask_iterator(2, ca, cw);
}
min_count = ( NIL_P(rmin_count) || ( ! mi ) ) ?
ca->elements - 1 : NUM2SIZE(rmin_count);
if ( min_count < 0 ) {
min_count += ca->elements;
}
ca_attach_n(2, ca, cw);
switch ( ca->data_type ) {
case CA_INT8: proc_mul_add(int8_t, ,LONG2NUM); break;
case CA_UINT8: proc_mul_add(uint8_t,,ULONG2NUM); break;
case CA_INT16: proc_mul_add(int16_t,,LONG2NUM); break;
case CA_UINT16: proc_mul_add(uint16_t,,ULONG2NUM); break;
case CA_INT32: proc_mul_add(int32_t,,LONG2NUM); break;
case CA_UINT32: proc_mul_add(uint32_t,,ULONG2NUM); break;
case CA_INT64: proc_mul_add(int64_t,,LL2NUM); break;
case CA_UINT64: proc_mul_add(uint64_t,,ULL2NUM); break;
case CA_FLOAT32: proc_mul_add(float32_t,,rb_float_new); break;
case CA_FLOAT64: proc_mul_add(float64_t,,rb_float_new); break;
case CA_FLOAT128: proc_mul_add(float128_t,,rb_float_new); break;
#ifdef HAVE_COMPLEX_H
case CA_CMPLX64: proc_mul_add(cmplx64_t,,rb_ccomplex_new); break;
case CA_CMPLX128: proc_mul_add(cmplx128_t,,rb_ccomplex_new); break;
case CA_CMPLX256: proc_mul_add(cmplx256_t,,rb_ccomplex_new); break;
#endif
/* case CA_OBJECT: proc_mul_add(VALUE,NUM2DBL,rb_float_new); break; */
default: rb_raise(rb_eCADataTypeError, "invalid data type");
}
ca_detach_n(2, ca, cw);
free(mi);
return out;
}
|
#ndim ⇒ Object
(Attribute) Returns the rank (e.g. 1 for 1D array, 3 for 3D array, …).
51 52 53 54 55 56 57 |
# File 'ext/carray_attribute.c', line 51
VALUE
rb_ca_ndim (VALUE self)
{
CArray *ca;
Data_Get_Struct(self, CArray, ca);
return INT2NUM(ca->ndim);
}
|
#nlargest(n) ⇒ Object
113 114 115 116 117 118 119 120 121 122 |
# File 'lib/carray/ordering.rb', line 113 def nlargest (n) obj = self.to_ca list = [] n.times do |i| k = obj.max_addr list << obj[k] obj[k] = UNDEF end list.to_ca.to_type(data_type) end |
#nlargest_addr(n) ⇒ Object
124 125 126 127 128 129 130 131 132 133 |
# File 'lib/carray/ordering.rb', line 124 def nlargest_addr (n) obj = self.to_ca list = [] n.times do |i| k = obj.max_addr list << k obj[k] = UNDEF end CA_INT64(list) end |
#none_close? ⇒ Boolean
1859 1860 1861 1862 1863 |
# File 'ext/carray_stat.c', line 1859
static VALUE
rb_ca_none_close_p (int argc, VALUE *argv, VALUE self)
{
return rb_ca_any_close_p(argc, argv, self) ? Qfalse : Qtrue;
}
|
#none_equal? ⇒ Boolean
1847 1848 1849 1850 1851 |
# File 'ext/carray_stat.c', line 1847
static VALUE
rb_ca_none_equal_p (int argc, VALUE *argv, VALUE self)
{
return rb_ca_any_equal_p(argc, argv, self) ? Qfalse : Qtrue;
}
|
#none_equiv? ⇒ Boolean
1853 1854 1855 1856 1857 |
# File 'ext/carray_stat.c', line 1853
static VALUE
rb_ca_none_equiv_p (int argc, VALUE *argv, VALUE self)
{
return rb_ca_any_equiv_p(argc, argv, self) ? Qfalse : Qtrue;
}
|
#normalize_index ⇒ Object
yard:
class CArray
def normalize_index (idx)
end
end
1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 |
# File 'ext/carray_access.c', line 1696
static VALUE
rb_ca_normalize_index (VALUE self, VALUE ridx)
{
volatile VALUE rindex;
CArray *ca;
CAIndexInfo info;
int i;
Data_Get_Struct(self, CArray, ca);
Check_Type(ridx, T_ARRAY);
info.range_check = 1;
rb_ca_scan_index(ca->ndim, ca->dim, ca->elements,
RARRAY_LEN(ridx), RARRAY_PTR(ridx), &info);
switch ( info.type ) {
case CA_REG_ALL:
case CA_REG_SELECT:
case CA_REG_ADDRESS:
rindex = rb_ary_new2(info.ndim);
rb_ary_store(rindex, 0, SIZE2NUM(info.index[0].scalar));
return rindex;
case CA_REG_POINT:
rindex = rb_ary_new2(info.ndim);
for (i=0; i<ca->ndim; i++) {
rb_ary_store(rindex, i, SIZE2NUM(info.index[i].scalar));
}
return rindex;
case CA_REG_BLOCK:
case CA_REG_ITERATOR:
rindex = rb_ary_new2(info.ndim);
for (i=0; i<ca->ndim; i++) {
switch ( info.index_type[i] ) {
case CA_IDX_SCALAR:
rb_ary_store(rindex, i, SIZE2NUM(info.index[i].scalar));
break;
case CA_IDX_ALL:
rb_ary_store(rindex, i, Qnil);
break;
case CA_IDX_BLOCK:
rb_ary_store(rindex, i,
rb_ary_new3(3,
SIZE2NUM(info.index[i].block.start),
SIZE2NUM(info.index[i].block.count),
SIZE2NUM(info.index[i].block.step)));
break;
case CA_IDX_SYMBOL:
rb_ary_store(rindex, i, ID2SYM(info.index[i].symbol.id));
break;
default:
rb_raise(rb_eRuntimeError, "unknown index spec");
}
}
return rindex;
case CA_REG_ADDRESS_COMPLEX:
case CA_REG_FLATTEN:
self = rb_ca_refer_new_flatten(self);
return rb_ca_normalize_index(self, ridx);
default:
rb_raise(rb_eArgError, "unknown index specification");
}
rb_raise(rb_eArgError, "fail to normalize index");
}
|
#nsmallest(n) ⇒ Object
135 136 137 138 139 140 141 142 143 144 |
# File 'lib/carray/ordering.rb', line 135 def nsmallest (n) obj = self.to_ca list = [] n.times do |i| k = obj.min_addr list << obj[k] obj[k] = UNDEF end list.to_ca.to_type(data_type) end |
#nsmallest_addr(n) ⇒ Object
146 147 148 149 150 151 152 153 154 155 |
# File 'lib/carray/ordering.rb', line 146 def nsmallest_addr (n) obj = self.to_ca list = [] n.times do |i| k = obj.min_addr list << k obj[k] = UNDEF end CA_INT64(list) end |
#numeric? ⇒ Boolean
(Inquiry) Returns true if self is numeric type array
445 446 447 448 449 450 451 |
# File 'ext/carray_attribute.c', line 445
VALUE
rb_ca_is_numeric_type (VALUE self)
{
CArray *ca;
Data_Get_Struct(self, CArray, ca);
return ca_is_numeric_type(ca) ? Qtrue : Qfalse;
}
|
#obj_type ⇒ Object
(Attribute) Returns the object type (e.g. CA_OBJ_ARRAY, CA_OBJ_BLOCK, …). Since the object type can be known from the class of the object, this attribute method is rarely used.
23 24 25 26 27 28 29 |
# File 'ext/carray_attribute.c', line 23
VALUE
rb_ca_obj_type (VALUE self)
{
CArray *ca;
Data_Get_Struct(self, CArray, ca);
return INT2NUM(ca->obj_type);
}
|
#object ⇒ Object
(Conversion) Short-Hand of “CArray#to_type(:object)”
507 508 509 510 |
# File 'ext/carray_cast.c', line 507
VALUE rb_ca_to_VALUE (VALUE self)
{
rb_ca_to_type_method_body(CA_OBJECT);
}
|
#object? ⇒ Boolean
(Inquiry) Returns true if self is object type array
566 567 568 569 570 571 572 |
# File 'ext/carray_attribute.c', line 566
VALUE
rb_ca_is_object_type (VALUE self)
{
CArray *ca;
Data_Get_Struct(self, CArray, ca);
return ca_is_object_type(ca) ? Qtrue : Qfalse;
}
|
#order(dir = 1) ⇒ Object
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/carray/ordering.rb', line 157 def order (dir = 1) if dir >= 0 ### ascending order if has_mask? obj = template(:int32) { UNDEF } sel = is_not_masked obj[sel][self[sel].sort_addr].seq! return obj else obj = template(:int32) obj[sort_addr].seq! return obj end else ### descending order if has_mask? obj = template(:int32) { UNDEF} sel = is_not_masked obj[sel][self[sel].sort_addr.reversed].seq! return obj else obj = template(:int32) obj[sort_addr.reversed].seq! return obj end end end |
#parent ⇒ Object
(Attribute) Returns the parent carray if self has parent, or returns nil if self has no parent.
585 586 587 588 589 |
# File 'ext/carray_attribute.c', line 585
VALUE
rb_ca_parent (VALUE self)
{
return rb_ivar_get(self, id_parent);
}
|
#paste(idx, ary) ⇒ Object
(Copy) Pastes ary to self at the index idx. idx should be Array object with the length same as self.ndim. ary should have same shape with self.
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 |
# File 'ext/carray_copy.c', line 285
static VALUE
rb_ca_paste (VALUE self, VALUE roffset, VALUE rsrc)
{
CArray *ca, *cs;
ca_size_t offset[CA_RANK_MAX];
int i;
rb_ca_modify(self);
Data_Get_Struct(self, CArray, ca);
Check_Type(roffset, T_ARRAY);
if ( RARRAY_LEN(roffset) != ca->ndim ) {
rb_raise(rb_eArgError,
"# of arguments should equal to the ndim");
}
for (i=0; i<ca->ndim; i++) {
offset[i] = NUM2SIZE(rb_ary_entry(roffset,i));
}
cs = ca_wrap_readonly(rsrc, ca->data_type);
ca_paste(ca, offset, cs);
return self;
}
|
#percentile(*argv) ⇒ Object
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 |
# File 'lib/carray/math.rb', line 268 def percentile (*argv) opt = argv.last.is_a?(Hash) ? argv.pop : {} pers = argv min_count = opt[:mask_limit] if min_count and min_count < 0 min_count += elements end fill_value = opt[:fill_value] if has_mask? if min_count and count_masked() > min_count return argv.map { fill_value || UNDEF } end ca = self[:is_not_masked].sort n = self.count_not_masked else ca = self.sort n = ca.elements end out = [] begin pers.each do |per| if per == 100 out << ca[n-1] elsif per >= 0 and per < 100 if n > 1 f = (n-1)*per/100.0 k = f.floor r = f - k out << (1-r)*ca[k] + r*ca[k+1] else out << ca[0] end else out << CA_NAN end end end return out end |
#project(idx, lval = nil, uval = nil) ⇒ Object
[TBD]. Creates new array the element of the object as address.
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'ext/carray_order.c', line 146
VALUE
rb_ca_project (int argc, VALUE *argv, VALUE self)
{
volatile VALUE obj, ridx, vlfval, vufval;
CArray *ca, *ci, *co;
char *lfval, *ufval;
rb_scan_args(argc, argv, "12", (VALUE *)&ridx, (VALUE *) &vlfval, (VALUE *) &vufval);
Data_Get_Struct(self, CArray, ca);
rb_check_carray_object(ridx);
ci = ca_wrap_readonly(ridx, CA_SIZE);
lfval = malloc_with_check(ca->bytes);
ufval = malloc_with_check(ca->bytes);
if ( ! NIL_P(vlfval) ) {
rb_ca_obj2ptr(self, vlfval, lfval);
rb_ca_obj2ptr(self, vlfval, ufval);
}
if ( ! NIL_P(vufval) ) {
rb_ca_obj2ptr(self, vufval, ufval);
}
co = ca_project(ca, ci,
( ! NIL_P(vlfval) ) ? lfval : NULL,
( ( ! NIL_P(vufval) ) || ( ! NIL_P(vlfval) ) ) ? ufval : NULL);
free(lfval);
free(ufval);
obj = ca_wrap_struct(co);
rb_ca_data_type_inherit(obj, self);
if ( ! ca_is_any_masked(co) ) {
obj = rb_ca_unmask_copy(obj);
}
return obj;
}
|
#pull(*args) ⇒ Object
36 37 38 39 40 |
# File 'lib/carray/obsolete.rb', line 36 def pull (*args) warn "CArray#pull will be obsolete" idx = args.map{|s| s.nil? ? :% : s} return self[*idx].to_ca end |
#pulled(*args) ⇒ Object
pulled
30 31 32 33 34 |
# File 'lib/carray/obsolete.rb', line 30 def pulled (*args) warn "CArray#pulled will be obsolete" idx = args.map{|s| s.nil? ? :% : s} return self[*idx] end |
#quantile ⇒ Object
308 309 310 |
# File 'lib/carray/math.rb', line 308 def quantile return percentile(0, 25, 50, 75, 100) end |
#quantize ⇒ Object
2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 |
# File 'ext/carray_stat.c', line 2005
static VALUE
rb_ca_grade (int argc, VALUE *argv, VALUE self)
{
volatile VALUE out, vnum, vmin, vmax;
CArray *ca, *sa;
ca_size_t icls;
rb_scan_args(argc, argv, "12", (VALUE *) &vnum, (VALUE *) &vmin, (VALUE *) &vmax);
if ( NIL_P(vmin) ) {
vmin = rb_funcall(self, rb_intern("min"), 0);
}
if ( NIL_P(vmax) ) {
vmax = rb_funcall(self, rb_intern("max"), 0);
}
Data_Get_Struct(self, CArray, ca);
icls = NUM2LONG(vnum);
if ( icls < 1 ) {
rb_raise(rb_eArgError, "bin number must be larger than 1");
}
out = rb_carray_new_safe(CA_SIZE, ca->ndim, ca->dim, 0, NULL);
Data_Get_Struct(out, CArray, sa);
ca_attach(ca);
if ( ca_has_mask(ca) ) {
ca_create_mask(sa);
ca_setup_mask(sa, ca->mask);
}
switch ( ca->data_type ) {
case CA_BOOLEAN:
case CA_INT8: proc_grade(int8_t, ); break;
case CA_UINT8: proc_grade(uint8_t, ); break;
case CA_INT16: proc_grade(int16_t, ); break;
case CA_UINT16: proc_grade(uint16_t, ); break;
case CA_INT32: proc_grade(int32_t, ); break;
case CA_UINT32: proc_grade(uint32_t, ); break;
case CA_INT64: proc_grade(int64_t, ); break;
case CA_UINT64: proc_grade(uint64_t, ); break;
case CA_FLOAT32: proc_grade(float32_t, ); break;
case CA_FLOAT64: proc_grade(float64_t, ); break;
case CA_FLOAT128: proc_grade(float128_t, ); break;
case CA_OBJECT: proc_grade(VALUE,NUM2DBL); break;
default: rb_raise(rb_eCADataTypeError, "invalid data type");
}
ca_detach(ca);
return out;
}
|
#quo(other) ⇒ Object
148 149 150 151 152 153 154 155 156 157 |
# File 'lib/carray/math.rb', line 148 def quo (other) case when integer? return object.quo_i(other) when object? return quo_i(other) else return self/other end end |
#rad_2pi ⇒ Object
114 115 116 117 118 |
# File 'ext/carray_mathfunc.c', line 114
static VALUE
rb_ca_rad_2pi (VALUE self)
{
return ca_call_cfunc_1_1(CA_DOUBLE, CA_DOUBLE, mathfunc_rad_2pi, self);
}
|
#rad_2pi! ⇒ Object
120 121 122 123 124 125 126 127 |
# File 'ext/carray_mathfunc.c', line 120
static VALUE
rb_ca_rad_2pi_bang (VALUE self)
{
volatile VALUE out;
out = ca_call_cfunc_1_1(CA_DOUBLE, CA_DOUBLE, mathfunc_rad_2pi, self);
rb_funcall(self, rb_intern("[]="), 1, out);
return self;
}
|
#rad_pi ⇒ Object
156 157 158 159 160 |
# File 'ext/carray_mathfunc.c', line 156
static VALUE
rb_ca_rad_pi (VALUE self)
{
return ca_call_cfunc_1_1(CA_DOUBLE, CA_DOUBLE, mathfunc_rad_pi, self);
}
|
#rad_pi! ⇒ Object
162 163 164 165 166 167 168 169 |
# File 'ext/carray_mathfunc.c', line 162
static VALUE
rb_ca_rad_pi_bang (VALUE self)
{
volatile VALUE out;
out = ca_call_cfunc_1_1(CA_DOUBLE, CA_DOUBLE, mathfunc_rad_pi, self);
rb_funcall(self, rb_intern("[]="), 1, out);
return self;
}
|
#random(*argv) ⇒ Object
statistics
200 201 202 |
# File 'lib/carray/math.rb', line 200 def random (*argv) return template.random!(*argv) end |
#randomn ⇒ Object
223 224 225 |
# File 'lib/carray/math.rb', line 223 def randomn return template.randomn! end |
#randomn! ⇒ Object
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
# File 'lib/carray/math.rb', line 204 def randomn! if elements == 1 self[0] = CArray.new(data_type,[2]).randomn![0] return self end x1 = CArray.new(data_type, [elements/2]) x2 = CArray.new(data_type, [elements/2]) fac = x1.random!.log!.mul!(-2.0).sqrt! ### fac = sqrt(-2*log(rnd())) x2.random!.mul!(2.0*Math::PI) ### x2 = 2*PI*rnd() x3 = x2.to_ca self2 = reshape(2,elements/2) self2[0,nil] = x2.cos!.mul!(fac) ### self[even] = fac*cos(x2) self2[1,nil] = x3.sin!.mul!(fac) ### self[odd] = fac*sin(x2) if elements % 2 == 1 self[[-1]].randomn! end return self end |
#range ⇒ Object
109 110 111 |
# File 'lib/carray/ordering.rb', line 109 def range return (self.min)..(self.max) end |
#ndim ⇒ Object
(Attribute) Returns the rank (e.g. 1 for 1D array, 3 for 3D array, …).
51 52 53 54 55 56 57 |
# File 'ext/carray_attribute.c', line 51
VALUE
rb_ca_ndim (VALUE self)
{
CArray *ca;
Data_Get_Struct(self, CArray, ca);
return INT2NUM(ca->ndim);
}
|
#read_only? ⇒ Boolean
(Inquiry) Returns true if the object is read-only
312 313 314 315 316 317 318 |
# File 'ext/carray_attribute.c', line 312
VALUE
rb_ca_is_read_only (VALUE self)
{
CArray *ca;
Data_Get_Struct(self, CArray, ca);
return ( ca_is_readonly(ca) ) ? Qtrue : Qfalse;
}
|
#real ⇒ Object
Return the real part of self. If self is a complex array, the resulted array is CAMember object refers the appropriate part of self. Otherwise, the resulted array is CARefer object refers self. If you change the resulted array, the original array is also changed.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/carray/math.rb', line 23 def real if not @__real__ if complex? @__real__ = case data_type when CA_CMPLX64 field(0, CA_FLOAT32) when CA_CMPLX128 field(0, CA_FLOAT64) when CA_CMPLX128 field(0, CA_FLOAT128) end else @__real__ = self[] end end @__real__ end |
#real=(val) ⇒ Object
41 42 43 |
# File 'lib/carray/math.rb', line 41 def real= (val) real[] = val end |
#real? ⇒ Boolean
118 119 120 121 122 123 124 125 126 |
# File 'lib/carray/math.rb', line 118 def real? if complex? imag.all_equal?(0) elsif numeric? true else nil end end |
#recurrence(*argv, &block) ⇒ Object
73 74 75 |
# File 'lib/carray/math/recurrence.rb', line 73 def recurrence (*argv, &block) return self.template.recurrence!(*argv, &block) end |
#recurrence!(init = {}, &block) ⇒ Object
67 68 69 70 71 |
# File 'lib/carray/math/recurrence.rb', line 67 def recurrence! (init = {}, &block) lazy = CARecurrence.new(self, init, &block) CArray.attach(lazy) {} return self end |
#refer ⇒ Object
yard:
class CArray
# call-seq:
# CArray.refer()
# CArray.refer(data_type, dim[, :bytes=>bytes, :offset=>offset])
# CArray.refer(data_class, dim)
#
# Returns CARefer object which refers self.
# In second form, `data_type` can be different data_type of self,
# as long as the total byte length of new array is smaller than
# that of self.
def refer (*argv)
end
end
508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 |
# File 'ext/ca_obj_refer.c', line 508
static VALUE
rb_ca_refer (int argc, VALUE *argv, VALUE self)
{
volatile VALUE obj = Qnil;
CArray *ca;
CARefer *cr;
int8_t data_type;
int8_t ndim;
ca_size_t dim[CA_RANK_MAX];
ca_size_t bytes, offset = 0;
int8_t i;
Data_Get_Struct(self, CArray, ca);
if ( argc == 0 ) { /* CArray#refer() */
data_type = ca->data_type;
bytes = ca->bytes;
ndim = ca->ndim;
for (i=0; i<ndim; i++) {
dim[i] = ca->dim[i];
}
cr = ca_refer_new((CArray*)ca, data_type, ndim, dim, bytes, offset);
obj = ca_wrap_struct(cr);
rb_ca_set_parent(obj, self);
rb_ca_data_type_inherit(obj, self);
}
else {
volatile VALUE rtype, rdim, ropt, rbytes = Qnil, roffset = Qnil;
ca_size_t elements;
ropt = rb_pop_options(&argc, &argv);
rb_scan_args(argc, argv, "11", (VALUE *) &rtype, (VALUE *) &rdim);
rb_scan_options(ropt, "bytes,offset", &rbytes, &roffset);
if ( NIL_P(rbytes) ) {
rbytes = rb_ca_bytes(self);
}
rb_ca_guess_type_and_bytes(rtype, rbytes, &data_type, &bytes);
if ( NIL_P(rdim) ) {
if ( ca->bytes != bytes ) {
rb_raise(rb_eRuntimeError,
"specify dimension shape for different byte size");
}
else {
rdim = rb_ca_dim(self);
}
}
Check_Type(rdim, T_ARRAY);
ndim = RARRAY_LEN(rdim);
elements = 1;
for (i=0; i<ndim; i++) {
dim[i] = NUM2SIZE(rb_ary_entry(rdim, i));
elements *= dim[i];
}
if ( ! NIL_P(roffset) ) {
offset = NUM2SIZE(roffset);
}
cr = ca_refer_new((CArray*)ca, data_type, ndim, dim, bytes, offset);
obj = ca_wrap_struct(cr);
rb_ca_set_parent(obj, self);
rb_ca_data_type_import(obj, rtype);
}
return obj;
}
|
#replace_value(from, to) ⇒ Object
124 125 126 127 128 |
# File 'lib/carray/obsolete.rb', line 124 def replace_value (from, to) warn "CArray#replace_value will be obsolete" self[:eq, from] = to return self end |
#reshape(*newdim) ⇒ Object
reshape
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/carray/transform.rb', line 17 def reshape (*newdim) ifalse = nil i = 0 0.upto(newdim.size-1) do |i| if newdim[i].nil? newdim[i] = dim[i] elsif newdim[i] == false ifalse = i break end end k = 0 (newdim.size-1).downto(i+1) do |j| if newdim[j].nil? newdim[j] = dim[ndim-1-k] end k += 1 end if ifalse newdim[ifalse] = elements/newdim.select{|x| x!=false}.inject(1){|s,x| s*x} end return refer(data_type, newdim, :bytes=>bytes) end |
#resize(*newdim, &block) ⇒ Object
Returns the array resized to the dimension given as newdim. The new area is filled by the value returned by the block.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/carray/compose.rb', line 17 def resize (*newdim, &block) if newdim.size != ndim raise "ndim mismatch" end offset = Array.new(ndim){0} ndim.times do |i| d = newdim[i] case d when nil newdim[i] = dim[i] when Integer if d < 0 newdim[i] *= -1 offset[i] = newdim[i] - dim[i] end else raise "invalid dimension size" end end out = CArray.new(data_type, newdim, &block) if out.has_mask? out.mask.paste(offset, self.false) end out.paste(offset, self) return out end |
#reverse ⇒ Object
Returns a new CArray object containing ca’s elements in reverse order.
281 282 283 284 285 286 287 |
# File 'ext/carray_order.c', line 281
static VALUE
rb_ca_reversed_copy (VALUE self)
{
volatile VALUE out = rb_ca_copy(self);
rb_ca_data_type_inherit(out, self);
return rb_ca_reverse_bang(out);
}
|
#reverse! ⇒ Object
Reverses the elements of ca in place.
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 |
# File 'ext/carray_order.c', line 231
static VALUE
rb_ca_reverse_bang (VALUE self)
{
CArray *ca;
rb_ca_modify(self);
Data_Get_Struct(self, CArray, ca);
ca_attach(ca);
switch ( ca->data_type ) {
case CA_FIXLEN: proc_reverse_bang_data(); break;
case CA_BOOLEAN:
case CA_INT8:
case CA_UINT8: proc_reverse_bang(int8_t); break;
case CA_INT16:
case CA_UINT16: proc_reverse_bang(int16_t); break;
case CA_INT32:
case CA_UINT32:
case CA_FLOAT32: proc_reverse_bang(int32_t); break;
case CA_INT64:
case CA_UINT64:
case CA_FLOAT64: proc_reverse_bang(float64_t); break;
case CA_FLOAT128: proc_reverse_bang(float128_t); break;
#ifdef HAVE_COMPLEX_H
case CA_CMPLX64: proc_reverse_bang(float64_t); break;
case CA_CMPLX128: proc_reverse_bang(cmplx128_t); break;
case CA_CMPLX256: proc_reverse_bang(cmplx256_t); break;
#endif
case CA_OBJECT: proc_reverse_bang(VALUE); break;
default:
rb_raise(rb_eCADataTypeError, "[BUG] array has an unknown data type");
}
if ( ca_has_mask(ca) ) {
proc_reverse_bang_mask();
}
ca_sync(ca);
ca_detach(ca);
return self;
}
|
#reversed ⇒ Object
reversed
16 17 18 |
# File 'lib/carray/ordering.rb', line 16 def reversed return self[*([-1..0]*ndim)] end |
#roll(*argv) ⇒ Object
41 42 43 |
# File 'lib/carray/ordering.rb', line 41 def roll (*argv) return self.rolled(*argv).to_ca end |
#roll!(*argv) ⇒ Object
36 37 38 39 |
# File 'lib/carray/ordering.rb', line 36 def roll! (*argv) self[] = self.rolled(*argv) return self end |
#rolled(*argv) ⇒ Object
31 32 33 34 |
# File 'lib/carray/ordering.rb', line 31 def rolled (*argv) argv.push({:roll => Array.new(ndim){1} }) return shifted(*argv) end |
#root_array ⇒ Object
(Attribute) Returns the object at the root of chain of reference.
740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 |
# File 'ext/carray_attribute.c', line 740
static VALUE
rb_ca_root_array (VALUE self)
{
volatile VALUE refary;
CArray *ca;
Data_Get_Struct(self, CArray, ca);
if ( ca_is_entity(ca) ) {
return self;
}
else {
refary = rb_ca_parent(self);
if ( NIL_P(refary) ) {
return self;
}
else {
return rb_ca_root_array(refary);
}
}
}
|
#rotate(*argv) ⇒ Object
:nodoc:
163 164 165 166 |
# File 'lib/carray/obsolete.rb', line 163 def rotate (*argv) # :nodoc: warn "CArray#rotate will be obsolete, use CArray#roll" return self.rolled(*argv).to_ca end |
#rotate!(*argv) ⇒ Object
:nodoc:
157 158 159 160 161 |
# File 'lib/carray/obsolete.rb', line 157 def rotate! (*argv) # :nodoc: warn "CArray#rotate! will be obsolete, use CArray#roll!" self[] = self.rolled(*argv) return self end |
#rotated(*argv) ⇒ Object
:nodoc:
151 152 153 154 155 |
# File 'lib/carray/obsolete.rb', line 151 def rotated (*argv) # :nodoc: warn "CArray#rotated will be obsolete, use CArray#rolled" argv.push({:roll => Array.new(ndim){1} }) return shifted(*argv) end |
#has_same_shape? ⇒ Boolean
(Inquiry) Returns true if the object has the same shape with the given array.
284 285 286 287 288 289 290 291 |
# File 'ext/carray_test.c', line 284
static VALUE
rb_ca_has_same_shape (VALUE self, VALUE other)
{
CArray *ca, *cb;
Data_Get_Struct(self, CArray, ca);
cb = ca_wrap_readonly(other, ca->data_type);
return ca_has_same_shape(ca, cb) ? Qtrue : Qfalse;
}
|
#save_binary(filename, opt = {}) ⇒ Object
:nodoc:
89 90 91 92 93 94 |
# File 'lib/carray/obsolete.rb', line 89 def save_binary (filename, opt={}) # :nodoc: warn "CArray#save_binary will be obsolete, use CArray.save" open(filename, "w") { |io| return Serializer.new(io).save(self, opt) } end |
#save_binary_io(io, opt = {}) ⇒ Object
:nodoc:
103 104 105 106 |
# File 'lib/carray/obsolete.rb', line 103 def save_binary_io (io, opt={}) # :nodoc: warn "CArray#save_binary_io will be obsolete, use CArray.save" return Serializer.new(io).save(self, opt) end |
#save_by_magick(filename, image_type = nil, options = "") ⇒ Object
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/carray/io/imagemagick.rb', line 153 def save_by_magick (filename, image_type = nil, = "") unless image_type image_type = magick_guess_image_type() end unless image_type raise "please specify image_type" end quantum_format = self.float? ? "-define quantum:format=floating-point" : "" case self.data_type when CA_INT8, CA_UINT8 depth = "-depth 8" when CA_INT16, CA_UINT16 depth = "-depth 16" when CA_FLOAT32 depth = "-depth 32" when CA_FLOAT64 depth = "-depth 64" when CA_FIXLEN depth = "-depth #{8*bytes}" else depth = "-depth 8" end convert_command = [ "convert", depth, "-size " + [dim1, dim0].join("x"), quantum_format, , "#{image_type}:-", filename ].join(" ") begin IO.popen(convert_command, "w") { |io| if data_type != CA_FIXLEN and data_type != CA_OBJECT if bytes > 1 and CArray.endian == CA_LITTLE_ENDIAN self.dump_binary(io) # swap_bytes.dump_binary(io) else self.dump_binary(io) end else self.dump_binary(io) end } rescue raise "ImageMagick's convert command failed to write image file '#{filename}'" end end |
#scalar? ⇒ Boolean
(Inquiry) Returns true if the object is a CScalar
200 201 202 203 204 205 206 |
# File 'ext/carray_attribute.c', line 200
VALUE
rb_ca_is_scalar (VALUE self)
{
CArray *ca;
Data_Get_Struct(self, CArray, ca);
return ( ca_is_scalar(ca) ) ? Qtrue : Qfalse;
}
|
#scale(xa, xb) ⇒ Object
96 97 98 |
# File 'lib/carray/construct.rb', line 96 def scale (xa, xb) template.scale!(xa, xb) end |
#scale!(xa, xb) ⇒ Object
90 91 92 93 94 |
# File 'lib/carray/construct.rb', line 90 def scale! (xa, xb) xa = xa.to_f xb = xb.to_f seq!(xa, (xb-xa)/(elements-1)) end |
#search ⇒ Object
[TBD].
698 699 700 701 702 703 704 705 706 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 |
# File 'ext/carray_order.c', line 698
static VALUE
rb_ca_linear_search (int argc, VALUE *argv, VALUE self)
{
volatile VALUE value, veps;
CArray *ca;
ca_size_t addr;
rb_scan_args(argc, argv, "11", (VALUE *) &value, (VALUE *) &veps);
Data_Get_Struct(self, CArray, ca);
ca_attach(ca);
addr = -1;
switch ( ca->data_type ) {
case CA_BOOLEAN:
case CA_INT8:
case CA_UINT8: proc_find_value(int8_t); break;
case CA_INT16:
case CA_UINT16: proc_find_value(int16_t); break;
case CA_INT32: proc_find_value(int32_t); break;
case CA_UINT32: proc_find_value(uint32_t); break;
case CA_INT64: proc_find_value(int64_t); break;
case CA_UINT64: proc_find_value(uint64_t); break;
case CA_FLOAT32: proc_find_value_float(float32_t, FLT_EPSILON); break;
case CA_FLOAT64: proc_find_value_float(float64_t, DBL_EPSILON); break;
case CA_FLOAT128: proc_find_value_float128(float128_t, DBL_EPSILON); break;
#ifdef HAVE_COMPLEX_H
case CA_CMPLX64: proc_find_value_cmplx(cmplx64_t, FLT_EPSILON); break;
case CA_CMPLX128: proc_find_value_cmplx(cmplx128_t, DBL_EPSILON); break;
case CA_CMPLX256: proc_find_value_cmplx(cmplx256_t, DBL_EPSILON); break;
#endif
case CA_OBJECT: proc_find_value_object(); break;
default:
rb_raise(rb_eCADataTypeError, "invalid data type");
}
ca_detach(ca);
return ( addr == -1 ) ? Qnil : SIZE2NUM(addr);
}
|
#search_index ⇒ Object
[TBD].
746 747 748 749 750 751 |
# File 'ext/carray_order.c', line 746
static VALUE
rb_ca_linear_search_index (int argc, VALUE *argv, VALUE self)
{
VALUE raddr = rb_ca_linear_search(argc, argv, self);
return ( NIL_P(raddr) ) ? Qnil : rb_ca_addr2index(self, raddr);
}
|
#search_nearest ⇒ Object
[TBD].
822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 |
# File 'ext/carray_order.c', line 822
static VALUE
rb_ca_linear_search_nearest (VALUE self, VALUE value)
{
CArray *ca;
ca_size_t addr;
Data_Get_Struct(self, CArray, ca);
ca_attach(ca);
switch ( ca->data_type ) {
case CA_BOOLEAN:
case CA_INT8: proc_nearest_addr(int8_t, NUM2LONG, fabs); break;
case CA_UINT8: proc_nearest_addr(uint8_t, NUM2ULONG, fabs); break;
case CA_INT16: proc_nearest_addr(int16_t, NUM2LONG, fabs); break;
case CA_UINT16: proc_nearest_addr(uint16_t, NUM2ULONG, fabs); break;
case CA_INT32: proc_nearest_addr(int32_t, NUM2LONG, fabs); break;
case CA_UINT32: proc_nearest_addr(uint32_t, NUM2ULONG, fabs); break;
case CA_INT64: proc_nearest_addr(int64_t, NUM2LL, fabs); break;
case CA_UINT64: proc_nearest_addr(uint64_t, rb_num2ull, fabs); break;
case CA_FLOAT32: proc_nearest_addr(float32_t, NUM2DBL, fabs); break;
case CA_FLOAT64: proc_nearest_addr(float64_t, NUM2DBL, fabs); break;
case CA_FLOAT128: proc_nearest_addr(float128_t, NUM2DBL, fabs); break;
#ifdef HAVE_COMPLEX_H
case CA_CMPLX64: proc_nearest_addr(cmplx64_t, NUM2CC, cabs); break;
case CA_CMPLX128: proc_nearest_addr(cmplx128_t, NUM2CC, cabs); break;
case CA_CMPLX256: proc_nearest_addr(cmplx256_t, NUM2CC, cabs); break;
#endif
case CA_OBJECT: proc_nearest_addr_VALUE(); break;
default:
rb_raise(rb_eCADataTypeError, "invalid data type for nearest_addr()");
}
ca_detach(ca);
return ( addr == -1 ) ? Qnil : SIZE2NUM(addr);
}
|
#search_nearest_index ⇒ Object
[TBD].
865 866 867 868 869 870 |
# File 'ext/carray_order.c', line 865
static VALUE
rb_ca_linear_search_nearest_index (VALUE self, VALUE value)
{
VALUE raddr = rb_ca_linear_search_nearest(self, value);
return ( NIL_P(raddr) ) ? Qnil : rb_ca_addr2index(self, raddr);
}
|
#select(&block) ⇒ Object
:nodoc:
168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/carray/obsolete.rb', line 168 def select (&block) # :nodoc: warn "CArray#select will be obsolete" case block.arity when 1 return self[*yield(self)] when -1, 0 return self[*instance_exec(&block)] else raise end end |
#seq(init_val = 0, step = 1{|elem| ... }) ⇒ Object
(Conversion) Generates sequential data with initial value init_val and step value step. For object array, if the second argument is Symbol object, it will be interpreted as stepping method and it is called for the last element in each step.
# call-seq:
# seq (init_val=0, step=1)
# seq (init_val=0, step=1) {|x| ... }
# seq (init_val=0, step=A_symbol) ### for object array
# seq (init_val=0, step=A_symbol) {|x| ...} ### for object array
#
# Generates sequential data with initial value `init_val`
# and step value `step`. For object array, if the second argument
# is Symbol object, it will be interpreted as stepping method and
# it is called for the last element in each step.
#
358 359 360 361 362 363 |
# File 'ext/carray_generate.c', line 358
static VALUE
rb_ca_seq_method (int argc, VALUE *argv, VALUE self)
{
volatile VALUE out = rb_ca_template(self);
return rb_ca_seq_bang_method(argc, argv, out);
}
|
#seq!(init_val = 0, step = 1{|elem| ... }) ⇒ Object
(Conversion, Destructive) Generates sequential data with initial value init_val and step value step. For object array, if the second argument is Symbol object, it will be interpreted as stepping method and it is called for the last element in each step.
# call-seq:
# seq (init_val=0, step=1)
# seq (init_val=0, step=1) {|x| ... }
# seq (init_val=0, step=A_symbol) ### for object array
# seq (init_val=0, step=A_symbol) {|x| ...} ### for object array
#
# Generates sequential data with initial value `init_val`
# and step value `step`. For object array, if the second argument
# is Symbol object, it will be interpreted as stepping method and
# it is called for the last element in each step.
#
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 |
# File 'ext/carray_generate.c', line 265
static VALUE
rb_ca_seq_bang_method (int argc, VALUE *argv, VALUE self)
{
volatile VALUE roffset, rstep;
CArray *ca;
rb_ca_modify(self);
Data_Get_Struct(self, CArray, ca);
/* delegate to rb_ca_seq_bang_object if data_type is object */
if ( ca_is_object_type(ca) ) {
return rb_ca_seq_bang_object(argc, argv, self);
}
rb_scan_args(argc, argv, "02", (VALUE *) &roffset, (VALUE *) &rstep);
ca_allocate(ca);
if ( ca_has_mask(ca) ) {
ca_clear_mask(ca); /* clear all mask */
}
if ( rb_block_given_p() ) { /* with block */
switch ( ca->data_type ) {
case CA_INT8: proc_seq_bang_with_block(int8_t, NUM2LONG, ); break;
case CA_UINT8: proc_seq_bang_with_block(uint8_t, NUM2ULONG, ); break;
case CA_INT16: proc_seq_bang_with_block(int16_t, NUM2LONG, ) ; break;
case CA_UINT16: proc_seq_bang_with_block(uint16_t, NUM2ULONG, ); break;
case CA_INT32: proc_seq_bang_with_block(int32_t, NUM2LONG, ); break;
case CA_UINT32: proc_seq_bang_with_block(uint32_t, NUM2ULONG, ); break;
case CA_INT64: proc_seq_bang_with_block(int64_t, NUM2LL, ); break;
case CA_UINT64: proc_seq_bang_with_block(uint64_t, rb_num2ull, ); break;
case CA_FLOAT32: proc_seq_bang_with_block(float32_t, NUM2DBL, ); break;
case CA_FLOAT64: proc_seq_bang_with_block(float64_t, NUM2DBL, ); break;
case CA_FLOAT128: proc_seq_bang_with_block(float128_t, NUM2DBL, ); break;
#ifdef HAVE_COMPLEX_H
case CA_CMPLX64: proc_seq_bang_with_block(cmplx64_t, (cmplx64_t) NUM2CC,); break;
case CA_CMPLX128: proc_seq_bang_with_block(cmplx128_t, NUM2CC, ); break;
case CA_CMPLX256: proc_seq_bang_with_block(cmplx256_t, (cmplx256_t) NUM2CC, ); break;
#endif
default: rb_raise(rb_eCADataTypeError,
"invalid data type of receiver");
}
}
else { /* without block */
switch ( ca->data_type ) {
case CA_INT8: proc_seq_bang(int8_t, NUM2LONG, ); break;
case CA_UINT8: proc_seq_bang(uint8_t, NUM2ULONG, ); break;
case CA_INT16: proc_seq_bang(int16_t, NUM2LONG, ) ; break;
case CA_UINT16: proc_seq_bang(uint16_t, NUM2ULONG, ); break;
case CA_INT32: proc_seq_bang(int32_t, NUM2LONG, ); break;
case CA_UINT32: proc_seq_bang(uint32_t, NUM2ULONG, ); break;
case CA_INT64: proc_seq_bang(int64_t, NUM2LL, ); break;
case CA_UINT64: proc_seq_bang(uint64_t, rb_num2ull, ); break;
case CA_FLOAT32: proc_seq_bang(float32_t, NUM2DBL, ); break;
case CA_FLOAT64: proc_seq_bang(float64_t, NUM2DBL, ); break;
case CA_FLOAT128: proc_seq_bang(float128_t, NUM2DBL, ); break;
#ifdef HAVE_COMPLEX_H
case CA_CMPLX64: proc_seq_bang(cmplx64_t, (cmplx64_t) NUM2CC, ); break;
case CA_CMPLX128: proc_seq_bang(cmplx128_t, NUM2CC, ); break;
case CA_CMPLX256: proc_seq_bang(cmplx256_t, (cmplx256_t) NUM2CC, ); break;
#endif
default: rb_raise(rb_eCADataTypeError,
"invalid data type of reciever");
}
}
ca_sync(ca);
ca_detach(ca);
return self;
}
|
#set(*idx) ⇒ Object
(Boolean, Modification) Sets true at the given index for the boolean array and returns self. It accept the arguments same as for CArray#[].
23 24 25 26 27 28 29 30 31 32 33 |
# File 'ext/carray_generate.c', line 23
static VALUE
rb_ca_boolean_set (int argc, VALUE *argv, VALUE self)
{
VALUE one = INT2NUM(1);
rb_ca_modify(self);
if ( ! rb_ca_is_boolean_type(self) ) {
rb_raise(rb_eCADataTypeError, "reciever should be a boolean array");
}
rb_ca_store2(self, argc, argv, one);
return self;
}
|
#dim ⇒ Object
(Attribute) Returns the Array object contains the dimensional shape of array (e.g. [2,3] for 2D 2x3 array, …).
98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'ext/carray_attribute.c', line 98
VALUE
rb_ca_dim (VALUE self)
{
volatile VALUE dim;
CArray *ca;
int i;
Data_Get_Struct(self, CArray, ca);
dim = rb_ary_new2(ca->ndim);
for (i=0; i<ca->ndim; i++) {
rb_ary_store(dim, i, SIZE2NUM(ca->dim[i]));
}
return dim;
}
|
#shift(*argv, &block) ⇒ Object
27 28 29 |
# File 'lib/carray/ordering.rb', line 27 def shift (*argv, &block) return self.shifted(*argv, &block).to_ca end |
#shift!(*argv, &block) ⇒ Object
roll / shift
22 23 24 25 |
# File 'lib/carray/ordering.rb', line 22 def shift! (*argv, &block) self[] = self.shifted(*argv, &block) return self end |
#shifted ⇒ Object
yard:
class CArray
def shifted
end
end
836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 |
# File 'ext/ca_obj_shift.c', line 836
VALUE
rb_ca_shift (int argc, VALUE *argv, VALUE self)
{
volatile VALUE obj, ropt, rfval = CA_NIL, rroll = Qnil, rcs;
CArray *ca;
CScalar *cs;
ca_size_t shift[CA_RANK_MAX];
int8_t roll[CA_RANK_MAX];
char *fill = NULL;
int8_t i;
Data_Get_Struct(self, CArray, ca);
ropt = rb_pop_options(&argc, &argv);
rb_scan_options(ropt, "roll,fill_value", &rroll, &rfval);
if ( argc != ca->ndim ) {
rb_raise(rb_eArgError, "# of arguments mismatch with ndim");
}
for (i=0; i<ca->ndim; i++) {
shift[i] = NUM2SIZE(argv[i]);
}
if ( rfval == CA_NIL ) {
if ( rb_block_given_p() ) {
rfval = rb_yield(self);
}
}
else {
/* rb_warn(":fill_value option for CArray#shifted will be obsoleted."); */
}
if ( rfval == CA_NIL ) {
rcs = rb_cscalar_new(ca->data_type, ca->bytes, NULL);
Data_Get_Struct(rcs, CScalar, cs);
fill = cs->ptr;
if ( ca_is_object_type(ca) ) {
*(VALUE *)fill = INT2NUM(0);
}
else {
memset(fill, 0, cs->bytes);
}
}
else if ( rfval == CA_UNDEF ) {
fill = NULL;
}
else {
rcs = rb_cscalar_new_with_value(ca->data_type, ca->bytes, rfval);
Data_Get_Struct(rcs, CScalar, cs);
fill = cs->ptr;
}
if ( NIL_P(rroll) ) {
for (i=0; i<ca->ndim; i++) {
roll[i] = 0;
}
}
else {
Check_Type(rroll, T_ARRAY);
if ( RARRAY_LEN(rroll) != ca->ndim ) {
rb_raise(rb_eArgError, "# of arguments mismatch with ndim");
}
for (i=0; i<ca->ndim; i++) {
roll[i] = NUM2INT(rb_ary_entry(rroll, i));
}
}
obj = rb_ca_shift_new(self, shift, fill, roll);
if ( rfval == CA_UNDEF ) {
CArray *co;
Data_Get_Struct(obj, CArray, co);
ca_create_mask(co);
}
return obj;
}
|
#sign ⇒ Object
138 139 140 141 142 143 144 145 146 |
# File 'lib/carray/math.rb', line 138 def sign out = self.zero out[self.lt(0)] = -1 out[self.gt(0)] = 1 if float? out[self.is_nan] = 0.0/0.0 end return out end |
#elements ⇒ Object
(Attribute) Returns the number of elements
83 84 85 86 87 88 89 |
# File 'ext/carray_attribute.c', line 83
VALUE
rb_ca_elements (VALUE self)
{
CArray *ca;
Data_Get_Struct(self, CArray, ca);
return SIZE2NUM(ca->elements);
}
|
#sort ⇒ Object
Returns a new CArray object containing ca’s elements sorted.
428 429 430 431 432 433 434 |
# File 'ext/carray_order.c', line 428
static VALUE
rb_ca_sorted_copy (VALUE self)
{
volatile VALUE out = rb_ca_copy(self);
rb_ca_data_type_inherit(out, self);
return rb_ca_sort_bang(out);
}
|
#sort! ⇒ Object
Sorts ca’s elements in place.
382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 |
# File 'ext/carray_order.c', line 382
static VALUE
rb_ca_sort_bang (VALUE self)
{
CArray *ca;
if ( rb_ca_is_any_masked(self) ) {
rb_ca_sort_bang(rb_ca_value_not_masked(self));
return self;
}
rb_ca_modify(self);
Data_Get_Struct(self, CArray, ca);
ca_attach(ca);
if ( ca_is_fixlen_type(ca) ) {
cmp_data *cmp_ptr, *p;
char *ca_ptr, *q;
ca_size_t i;
cmp_ptr = malloc_with_check(sizeof(cmp_data)*ca->elements);
ca_ptr = malloc_with_check(ca_length(ca));
for (i=0, p=cmp_ptr, q=ca->ptr; i<ca->elements; i++, p++, q+=ca->bytes) {
p->bytes = ca->bytes;
p->ptr = q;
}
qsort(cmp_ptr, ca->elements, sizeof(cmp_data), ca_qsort_cmp[CA_FIXLEN]);
for (i=0, p=cmp_ptr, q=ca_ptr; i<ca->elements; i++, p++, q+=ca->bytes) {
memcpy(q, p->ptr, ca->bytes);
}
free(ca->ptr);
ca->ptr = ca_ptr;
free(cmp_ptr);
}
else {
qsort(ca->ptr, ca->elements, ca->bytes, ca_qsort_cmp[ca->data_type]);
}
ca_sync(ca);
ca_detach(ca);
return self;
}
|
#sort_addr(*args) ⇒ Object
241 242 243 244 245 246 247 |
# File 'ext/carray_sort_addr.c', line 241
static VALUE
rb_ca_sort_addr (int argc, VALUE *argv, VALUE self)
{
VALUE list = rb_ary_new4(argc, argv);
rb_ary_unshift(list, self);
return rb_apply(rb_mCA, rb_intern("sort_addr"), list);
}
|
#sort_by(type = nil, opt = {}, &block) ⇒ Object
Returns the array which elements are sorted by the comparison method given as block
56 57 58 59 60 61 |
# File 'lib/carray/ordering.rb', line 56 def sort_by (type=nil, opt={}, &block) type, bytes = CArray.guess_type_and_bytes(type||data_type, opt[:bytes]||bytes) cmpary = convert(type, :bytes=>bytes, &block) return self[cmpary.sort_addr].to_ca end |
#sort_with(*others) ⇒ Object
68 69 70 71 |
# File 'lib/carray/ordering.rb', line 68 def sort_with (*others) addr = sort_addr ([self] + others).map { |x| x[addr].to_ca } end |
#sorted_by(type = nil, opt = {}, &block) ⇒ Object
Returns the reference which elements are sorted by the comparison method given as block
47 48 49 50 51 52 |
# File 'lib/carray/ordering.rb', line 47 def sorted_by (type=nil, opt={}, &block) type, bytes = CArray.guess_type_and_bytes(type||data_type, opt[:bytes]||bytes) cmpary = convert(type, :bytes=>bytes, &block) return self[cmpary.sort_addr] end |
#sorted_with(*others) ⇒ Object
63 64 65 66 |
# File 'lib/carray/ordering.rb', line 63 def sorted_with (*others) addr = sort_addr ([self] + others).map { |x| x[addr] } end |
#span(range) ⇒ Object
82 83 84 |
# File 'lib/carray/construct.rb', line 82 def span (range) return template.span!(range) end |
#span!(range) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/carray/construct.rb', line 58 def span! (range) first = range.begin.to_r last = range.end.to_r if integer? if range.exclude_end? step = ((last-1)-first+1)/elements else step = (last-first+1)/elements end else if range.exclude_end? step = (last-first)/elements else step = (last-first)/(elements-1) end end if integer? && step.denominator != 1 self[] = (first + seq * step).floor else seq!(first, step) end return self end |
#split(*argv) ⇒ Object
Returns object carray has elements of splitted carray at dimensions
which is given by arguments
a = CA_INT([[1,2,3], [4,5,6], [7,8,9]])
a.split(0)
[1,2,3], [4,5,6], [7,8,9]
a.split(1)
[1,4,7], [2,5,8], [3,6,9]
166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/carray/basic.rb', line 166 def split (*argv) odim = dim.values_at(*argv) out = CArray.object(*odim) idx = [nil] * ndim attach { out.map_with_index! do |o, v| argv.each_with_index do |r, i| idx[r] = v[i] end self[*idx].to_ca end } return out end |
#st ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/carray/struct.rb', line 79 def st unless has_data_class? raise "should have data_class" end unless @struct struct_class = Struct.new(nil, *data_class::MEMBERS) members = data_class::MEMBERS.map{|name| self[name]} @struct = struct_class.new(*members) end return @struct end |
#str_bytesize ⇒ Object
25 26 27 |
# File 'lib/carray/string.rb', line 25 def str_bytesize () return convert(:int, &:bytesize) end |
#str_capitalize ⇒ Object
87 88 89 |
# File 'lib/carray/string.rb', line 87 def str_capitalize () return convert(&:capitalize) end |
#str_center(*args) ⇒ Object
131 132 133 |
# File 'lib/carray/string.rb', line 131 def str_center (*args) return convert() {|s| s.center(*args) } end |
#str_chomp(*args) ⇒ Object
95 96 97 |
# File 'lib/carray/string.rb', line 95 def str_chomp (*args) return convert() {|s| s.chomp(*args) } end |
#str_chop ⇒ Object
99 100 101 |
# File 'lib/carray/string.rb', line 99 def str_chop () return convert(&:chop) end |
#str_chr ⇒ Object
103 104 105 |
# File 'lib/carray/string.rb', line 103 def str_chr () return convert(&:chr) end |
#str_clear ⇒ Object
107 108 109 |
# File 'lib/carray/string.rb', line 107 def str_clear () return convert(&:clear) end |
#str_count(*args) ⇒ Object
111 112 113 |
# File 'lib/carray/string.rb', line 111 def str_count (*args) return convert(:int) {|s| s.count(*args) } end |
#str_delete(*args) ⇒ Object
115 116 117 |
# File 'lib/carray/string.rb', line 115 def str_delete (*args) return convert() {|s| s.delete(*args) } end |
#str_delete_prefix(prefix) ⇒ Object
119 120 121 |
# File 'lib/carray/string.rb', line 119 def str_delete_prefix (prefix) return convert() {|s| s.delete_prefix(prefix) } end |
#str_delete_suffix(suffix) ⇒ Object
123 124 125 |
# File 'lib/carray/string.rb', line 123 def str_delete_suffix (suffix) return convert() {|s| s.delete_suffix(suffix) } end |
#str_downcase ⇒ Object
79 80 81 |
# File 'lib/carray/string.rb', line 79 def str_downcase () return convert(&:downcase) end |
#str_dump ⇒ Object
127 128 129 |
# File 'lib/carray/string.rb', line 127 def str_dump () return convert(&:dump) end |
#str_encode(*args) ⇒ Object
37 38 39 |
# File 'lib/carray/string.rb', line 37 def str_encode (*args) return convert() {|s| s.encode(*args) } end |
#str_encoding ⇒ Object
45 46 47 |
# File 'lib/carray/string.rb', line 45 def str_encoding () return convert(&:encoding) end |
#str_extract(regexp, replace = '\0') ⇒ Object
185 186 187 |
# File 'lib/carray/string.rb', line 185 def str_extract (regexp, replace = '\0') return convert {|s| regexp.match(s) {|m| m[0].sub(regexp, replace) } || "" } end |
#str_force_encoding(encoding) ⇒ Object
41 42 43 |
# File 'lib/carray/string.rb', line 41 def str_force_encoding (encoding) return convert() {|s| s.force_encoding(encoding) } end |
#str_format(*fmts) ⇒ Object
(Conversion) Creates object type array consist of string using the “::format” method. The Multiple format strings are given, they are applied cyclic in turn.
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 |
# File 'ext/carray_conversion.c', line 301
static VALUE
rb_ca_format (int argc, VALUE *argv, VALUE self)
{
volatile VALUE obj, elem, val;
CArray *ca;
ca_size_t i, j;
ID id_format = rb_intern("format");
Data_Get_Struct(self, CArray, ca);
obj = rb_ca_template_with_type(self, INT2NUM(CA_OBJECT), INT2NUM(0));
ca_attach(ca);
if ( ca_has_mask(ca) ) {
j = 0;
for (i=0; i<ca->elements; i++) {
val = CA_UNDEF;
if ( ! ca->mask->ptr[i] ) {
elem = rb_ca_fetch_addr(self, i);
val = rb_funcall(elem, id_format, 2, argv[j], elem);
}
rb_ca_store_addr(obj, i, val);
j++;
j = j % argc; /* cyclic referencing of argv */
}
}
else {
j = 0;
for (i=0; i<ca->elements; i++) {
elem = rb_ca_fetch_addr(self, i);
val = rb_funcall(elem, id_format, 2, argv[j], elem);
rb_ca_store_addr(obj, i, val);
j++;
j = j % argc; /* cyclic referencing of argv */
}
}
ca_detach(ca);
return obj;
}
|
#str_gsub(*args, &block) ⇒ Object
29 30 31 |
# File 'lib/carray/string.rb', line 29 def str_gsub (*args, &block) return convert() {|s| s.gsub(*args, &block) } end |
#str_includes(substr) ⇒ Object Also known as: str_contains
57 58 59 |
# File 'lib/carray/string.rb', line 57 def str_includes (substr) return test {|s| s.include?(substr) } end |
#str_index(*args) ⇒ Object
63 64 65 |
# File 'lib/carray/string.rb', line 63 def str_index (*args) return convert(:int) {|s| s.index(*args) } end |
#str_intern ⇒ Object
71 72 73 |
# File 'lib/carray/string.rb', line 71 def str_intern () return convert(&:intern) end |
#str_is_empty ⇒ Object
167 168 169 |
# File 'lib/carray/string.rb', line 167 def str_is_empty () return test(&:empty?) end |
#str_is_end_with(*args) ⇒ Object
49 50 51 |
# File 'lib/carray/string.rb', line 49 def str_is_end_with (*args) return test {|s| s.end_with?(*args) } end |
#str_is_start_with(*args) ⇒ Object
53 54 55 |
# File 'lib/carray/string.rb', line 53 def str_is_start_with (*args) return test {|s| s.start_with?(*args) } end |
#str_len ⇒ Object
17 18 19 |
# File 'lib/carray/string.rb', line 17 def str_len () return convert(:int, &:length) end |
#str_ljust(*args) ⇒ Object
135 136 137 |
# File 'lib/carray/string.rb', line 135 def str_ljust (*args) return convert() {|s| s.ljust(*args) } end |
#str_lstrip ⇒ Object
163 164 165 |
# File 'lib/carray/string.rb', line 163 def str_lstrip () return convert(&:lstrip) end |
#str_matches(*args) ⇒ Object
171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/carray/string.rb', line 171 def str_matches (*args) if args.size == 1 && args.first.is_a?(Regexp) regexp = args.first return test {|v| v =~ regexp } else mask = template(:boolean) { false } args.each do |str| addr = search(str) mask[addr] = true if addr end return mask end end |
#str_rindex(*args) ⇒ Object
67 68 69 |
# File 'lib/carray/string.rb', line 67 def str_rindex (*args) return convert(:int) {|s| s.rindex(*args) } end |
#str_rjust(*args) ⇒ Object
139 140 141 |
# File 'lib/carray/string.rb', line 139 def str_rjust (*args) return convert() {|s| s.rjust(*args) } end |
#str_rstrip ⇒ Object
159 160 161 |
# File 'lib/carray/string.rb', line 159 def str_rstrip () return convert(&:rstrip) end |
#str_scrub ⇒ Object
75 76 77 |
# File 'lib/carray/string.rb', line 75 def str_scrub () return convert(&:scrub) end |
#str_size ⇒ Object
21 22 23 |
# File 'lib/carray/string.rb', line 21 def str_size () return convert(:int, &:size) end |
#str_strip ⇒ Object
155 156 157 |
# File 'lib/carray/string.rb', line 155 def str_strip () return convert(&:strip) end |
#str_strptime(fmt) ⇒ Object
(Conversion) Creates object type array consist of Time objects which are created by ‘Time.strptime’ applied to the elements of the object. This method assumes all the elements of the objetct to be String.
353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 |
# File 'ext/carray_conversion.c', line 353
static VALUE
rb_ca_strptime (VALUE self, VALUE rfmt)
{
volatile VALUE obj, elem, val;
CArray *ca;
char *fmt;
struct tm tmv;
ca_size_t i;
ca = ca_wrap_readonly(self, CA_OBJECT);
if ( ! ca_is_object_type(ca) ) {
rb_raise(rb_eRuntimeError, "strptime can be applied only to object type.");
}
Check_Type(rfmt, T_STRING);
fmt = (char *) StringValuePtr(rfmt);
obj = rb_ca_template(self);
ca_attach(ca);
if ( ca_has_mask(ca) ) {
for (i=0; i<ca->elements; i++) {
val = CA_UNDEF;
if ( ! ca->mask->ptr[i] ) {
elem = rb_ca_fetch_addr(self, i);
if ( TYPE(elem) == T_STRING ) {
memset(&tmv, 0, sizeof(struct tm));
if ( strptime(StringValuePtr(elem), fmt, &tmv) ) {
val = rb_time_new(mktime(&tmv), 0);
}
}
}
rb_ca_store_addr(obj, i, val);
}
}
else {
for (i=0; i<ca->elements; i++) {
val = CA_UNDEF;
elem = rb_ca_fetch_addr(self, i);
if ( TYPE(elem) == T_STRING ) {
memset(&tmv, 0, sizeof(struct tm));
if ( strptime(StringValuePtr(elem), fmt, &tmv) ) {
val = rb_time_new(mktime(&tmv), 0);
}
}
rb_ca_store_addr(obj, i, val);
}
}
ca_detach(ca);
return obj;
}
|
#str_sub(*args, &block) ⇒ Object
33 34 35 |
# File 'lib/carray/string.rb', line 33 def str_sub (*args, &block) return convert() {|s| s.sub(*args, &block) } end |
#str_swapcase ⇒ Object
91 92 93 |
# File 'lib/carray/string.rb', line 91 def str_swapcase () return convert(&:swapcase) end |
#str_to_datetime(template = nil) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/carray/time.rb', line 17 def str_to_datetime (template = nil) if template return convert() {|v| DateTime.strptime(v, template) } else return convert() {|v| DateTime.parse(v) } end end |
#str_to_f ⇒ Object
147 148 149 |
# File 'lib/carray/string.rb', line 147 def str_to_f () return convert(&:to_f) end |
#str_to_i ⇒ Object
143 144 145 |
# File 'lib/carray/string.rb', line 143 def str_to_i () return convert(&:to_i) end |
#str_to_r ⇒ Object
151 152 153 |
# File 'lib/carray/string.rb', line 151 def str_to_r () return convert(&:to_r) end |
#str_to_time(template = nil) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/carray/time.rb', line 25 def str_to_time (template = nil) if template return str_strptime(template) else return convert() {|v| Time.parse(v) } end end |
#str_upcase ⇒ Object
83 84 85 |
# File 'lib/carray/string.rb', line 83 def str_upcase () return convert(&:upcase) end |
#swap_bytes ⇒ Object
(Conversion) Swaps the byte order of each element.
573 574 575 576 577 578 |
# File 'ext/carray_generate.c', line 573
VALUE
rb_ca_swap_bytes (VALUE self)
{
volatile VALUE out = rb_ca_copy(self);
return rb_ca_swap_bytes_bang(out);
}
|
#swap_bytes! ⇒ Object
(Conversion, Destructive) Swaps the byte order of each element.
481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 |
# File 'ext/carray_generate.c', line 481
VALUE
rb_ca_swap_bytes_bang (VALUE self)
{
CArray *ca;
int i;
rb_ca_modify(self);
if ( rb_ca_is_object_type(self) ) {
rb_raise(rb_eCADataTypeError, "object array can't swap bytes");
}
if ( rb_ca_is_fixlen_type(self) ) {
if ( rb_ca_has_data_class(self) ) {
volatile VALUE members = rb_ca_fields(self);
Check_Type(members, T_ARRAY);
for (i=0; i<RARRAY_LEN(members); i++) {
volatile VALUE obj = rb_ary_entry(members, i);
rb_ca_swap_bytes_bang(obj);
}
}
else {
Data_Get_Struct(self, CArray, ca);
ca_attach(ca);
ca_swap_bytes(ca->ptr, ca->bytes, ca->elements);
ca_sync(ca);
ca_detach(ca);
}
return self;
}
Data_Get_Struct(self, CArray, ca);
switch ( ca->data_type ) {
case CA_INT16:
case CA_UINT16:
ca_attach(ca);
ca_swap_bytes(ca->ptr, 2, ca->elements);
ca_sync(ca);
ca_detach(ca);
break;
case CA_INT32:
case CA_UINT32:
case CA_FLOAT32:
ca_attach(ca);
ca_swap_bytes(ca->ptr, 4, ca->elements);
ca_sync(ca);
ca_detach(ca);
break;
case CA_INT64:
case CA_UINT64:
case CA_FLOAT64:
ca_attach(ca);
ca_swap_bytes(ca->ptr, 8, ca->elements);
ca_sync(ca);
ca_detach(ca);
break;
case CA_FLOAT128:
ca_attach(ca);
ca_swap_bytes(ca->ptr, 16, ca->elements);
ca_sync(ca);
ca_detach(ca);
break;
case CA_CMPLX64:
ca_attach(ca);
ca_swap_bytes(ca->ptr, 4, 2 * ca->elements);
ca_sync(ca);
ca_detach(ca);
break;
case CA_CMPLX128:
ca_attach(ca);
ca_swap_bytes(ca->ptr, 8, 2 * ca->elements);
ca_sync(ca);
ca_detach(ca);
break;
case CA_CMPLX256:
ca_attach(ca);
ca_swap_bytes(ca->ptr, 16, 2 * ca->elements);
ca_sync(ca);
ca_detach(ca);
break;
}
return self;
}
|
#t ⇒ Object
yard:
class CArray
# create the virtual transposed array which dimension order is reversed.
def t
end
end
438 439 440 441 442 |
# File 'ext/ca_obj_farray.c', line 438
VALUE
rb_ca_farray (VALUE self)
{
return rb_ca_farray_new(self);
}
|
#template(data_type = self.data_type, bytes: 0) ⇒ Object
(Copy) Returns CArray object with same dimension with self The data type of the new carray object can be specified by data_type. For fixlen data type, the option :bytes is used to specified the data length.
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'ext/carray_copy.c', line 107
static VALUE
rb_ca_template_method (int argc, VALUE *argv, VALUE self)
{
volatile VALUE ropt = rb_pop_options(&argc, &argv);
volatile VALUE obj, rtype, rbytes = Qnil;
CArray *ca, *co;
int8_t data_type;
ca_size_t bytes;
rb_scan_args(argc, argv, "01", (VALUE *) &rtype);
rb_scan_options(ropt, "bytes", &rbytes);
Data_Get_Struct(self, CArray, ca);
if ( NIL_P(rtype) ) { /* data_type not given */
co = ca_template_safe(ca);
obj = ca_wrap_struct(co);
rb_ca_data_type_inherit(obj, self);
}
else {
rb_ca_guess_type_and_bytes(rtype, rbytes, &data_type, &bytes);
co = ca_template_safe2(ca, data_type, bytes);
obj = ca_wrap_struct(co);
rb_ca_data_type_import(obj, rtype);
}
if ( rb_block_given_p() ) { /* block given */
volatile VALUE rval = rb_yield_values(0);
if ( rval != self ) {
rb_ca_store_all(obj, rval);
}
}
return obj;
}
|
#test(&block) ⇒ Object
15 16 17 |
# File 'lib/carray/testing.rb', line 15 def test (&block) return convert(:boolean) {|v| yield(v) ? true : false } end |
#test_ca_to_cptr ⇒ Object
458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 |
# File 'ext/carray_conversion.c', line 458
static VALUE
rb_test_ca_to_cptr (VALUE self)
{
CArray *ca;
double ****a;
int i, j, k, l;
Data_Get_Struct(self, CArray, ca);
ca_attach(ca);
a = ca_to_cptr(ca);
for (i=0; i<ca->dim[0]; i++) {
for (j=0; j<ca->dim[1]; j++) {
for (k=0; k<ca->dim[2]; k++) {
for (l=0; l<ca->dim[3]; l++) {
printf("(%i, %i, %i, %i) -> %g\n", i, j, k, l, a[i][j][k][l]);
}
}
}
}
free(a);
ca_detach(ca);
return Qnil;
}
|
#time_ajd ⇒ Object
69 70 71 |
# File 'lib/carray/time.rb', line 69 def time_ajd return convert(:double, &:ajd) end |
#time_day ⇒ Object
49 50 51 |
# File 'lib/carray/time.rb', line 49 def time_day return convert(:int, &:day) end |
#time_format(template = nil) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/carray/time.rb', line 33 def time_format (template = nil) if template return str_strftime(template) else return convert(&:to_s) end end |
#time_hour ⇒ Object
53 54 55 |
# File 'lib/carray/time.rb', line 53 def time_hour return convert(:int, &:hour) end |
#time_is_leap ⇒ Object
73 74 75 |
# File 'lib/carray/time.rb', line 73 def time_is_leap return test(&:leap?) end |
#time_jd ⇒ Object
65 66 67 |
# File 'lib/carray/time.rb', line 65 def time_jd return convert(:int, &:jd) end |
#time_minute ⇒ Object
57 58 59 |
# File 'lib/carray/time.rb', line 57 def time_minute return convert(:int, &:minute) end |
#time_month ⇒ Object
45 46 47 |
# File 'lib/carray/time.rb', line 45 def time_month return convert(:int, &:month) end |
#time_second ⇒ Object
61 62 63 |
# File 'lib/carray/time.rb', line 61 def time_second return convert(:double) {|d| d.second + d.second_fraction } end |
#time_strptime(fmt) ⇒ Object
(Conversion) Creates object type array consist of strings which are created by ‘Time#strftime’ applied to the elements of the object. This method assumes all the elements of the objetct to be Time or DateTime.
415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 |
# File 'ext/carray_conversion.c', line 415
static VALUE
rb_ca_strftime (VALUE self, VALUE rfmt)
{
volatile VALUE obj, elem, val;
CArray *ca;
ca_size_t i;
ID id_strftime = rb_intern("strftime");
ca = ca_wrap_readonly(self, CA_OBJECT);
if ( ! ca_is_object_type(ca) ) {
rb_raise(rb_eRuntimeError, "strptime can be applied only to object type.");
}
obj = rb_ca_template(self);
ca_attach(ca);
if ( ca_has_mask(ca) ) {
for (i=0; i<ca->elements; i++) {
val = CA_UNDEF;
if ( ! ca->mask->ptr[i] ) {
elem = rb_ca_fetch_addr(self, i);
val = rb_funcall(elem, id_strftime, 1, rfmt);
}
rb_ca_store_addr(obj, i, val);
}
}
else {
for (i=0; i<ca->elements; i++) {
elem = rb_ca_fetch_addr(self, i);
val = rb_funcall(elem, id_strftime, 1, rfmt);
rb_ca_store_addr(obj, i, val);
}
}
ca_detach(ca);
return obj;
}
|
#time_year ⇒ Object
41 42 43 |
# File 'lib/carray/time.rb', line 41 def time_year return convert(:int, &:year) end |
#to_a ⇒ Object
(Conversion) Converts the array to Ruby’s array. For higher dimension, the array is nested ndim-1 times.
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'ext/carray_conversion.c', line 52
VALUE
rb_ca_to_a (VALUE self)
{
volatile VALUE ary;
CArray *ca;
ca_size_t idx[CA_RANK_MAX];
Data_Get_Struct(self, CArray, ca);
ary = rb_ary_new2(ca->dim[0]);
ca_attach(ca);
rb_ca_to_a_loop(self, 0, idx, ary);
ca_detach(ca);
return ary;
}
|
#to_binary(io = "", opt = {}) ⇒ Object
:nodoc:
113 114 115 116 117 |
# File 'lib/carray/obsolete.rb', line 113 def to_binary (io="", opt={}) # :nodoc: warn "CArray#to_binary will be obsolete, use CArray.dump" Serializer.new(io).save(self, opt) return io end |
#to_bit_string(nb) ⇒ Object
89 90 91 92 93 94 |
# File 'lib/carray/convert.rb', line 89 def to_bit_string (nb) hex = CArray.uint8(((nb*elements)/8.0).ceil) hex.bits[nil].paste([0], self.bits[false,[(nb-1)..0]].flatten) hex.bits[] = hex.bits[nil,[-1..0]] return hex.to_s end |
#to_ca ⇒ Object
(Copy) Creates CArray object from self with same contents includes mask state.
49 50 51 52 53 54 55 56 57 58 |
# File 'ext/carray_copy.c', line 49
VALUE
rb_ca_copy (VALUE self)
{
volatile VALUE obj;
CArray *ca;
Data_Get_Struct(self, CArray, ca);
obj = ca_wrap_struct(ca_copy(ca));
rb_ca_data_type_inherit(obj, self);
return obj;
}
|
#to_column ⇒ Object
Returns (n,1) array from 1-dimensional array
92 93 94 95 96 97 |
# File 'lib/carray/transform.rb', line 92 def to_column if ndim != 1 raise "ndim should be 1" end return self[:%,1] end |
#to_row ⇒ Object
Returns (1,n) array from 1-dimensional array
84 85 86 87 88 89 |
# File 'lib/carray/transform.rb', line 84 def to_row if ndim != 1 raise "ndim should be 1" end return self[1,:%] end |
#to_s ⇒ Object
(Conversion) Dumps the value array to a string.
190 191 192 193 194 |
# File 'ext/carray_conversion.c', line 190
static VALUE
rb_ca_to_s (VALUE self)
{
return rb_ca_dump_binary(0, NULL, self);
}
|
#to_type(data_type, bytes: nil) ⇒ Object
(Conversion) Returns an array of elements that are converted to the given data type from the object.
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 |
# File 'ext/carray_cast.c', line 288
static VALUE
rb_ca_to_type_internal (int argc, VALUE *argv, VALUE self)
{
volatile VALUE obj, rtype = Qnil, ropt, rbytes = Qnil;
CArray *ca, *cb;
int8_t data_type;
ca_size_t bytes;
Data_Get_Struct(self, CArray, ca);
rb_scan_args(argc, argv, "11", (VALUE *) &rtype, (VALUE *) &ropt);
rb_scan_options(ropt, "bytes", &rbytes);
rb_ca_guess_type_and_bytes(rtype, rbytes, &data_type, &bytes);
if ( rb_ca_has_data_class(self) && data_type == CA_OBJECT ) {
return rb_ca_data_class_to_object(self);
}
if ( rb_ca_is_object_type(self) && rb_obj_is_data_class(rtype) ) {
return rb_ca_object_to_data_class(self, rtype, bytes);
}
ca_update_mask(ca);
if ( ca_is_scalar(ca) ) {
obj = rb_cscalar_new(data_type, bytes, ca->mask);
}
else {
obj = rb_carray_new(data_type, ca->ndim, ca->dim, bytes, ca->mask);
}
rb_ca_data_type_import(obj, rtype);
Data_Get_Struct(obj, CArray, cb);
ca_attach(ca);
if ( ca_has_mask(ca) ) {
ca_cast_block_with_mask(cb->elements, ca, ca->ptr, cb, cb->ptr,
(boolean8_t*)ca->mask->ptr);
}
else {
ca_cast_block(cb->elements, ca, ca->ptr, cb, cb->ptr);
}
ca_detach(ca);
return obj;
}
|
#transform(type, dim, opt = {}) ⇒ Object
:nodoc:
180 181 182 183 |
# File 'lib/carray/obsolete.rb', line 180 def transform (type, dim, opt = {}) # :nodoc: warn("CArray#transform will be obsolete") return refer(type, dim, opt).to_ca end |
#transpose(*argv) ⇒ Object
57 58 59 |
# File 'lib/carray/transform.rb', line 57 def transpose (*argv) return self.transposed(*argv).to_ca end |
#transpose!(*argv) ⇒ Object
52 53 54 55 |
# File 'lib/carray/transform.rb', line 52 def transpose! (*argv) self[] = self.transposed(*argv) return self end |
#transposed ⇒ Object
yard:
class CArray
def transposed
end
end
519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 |
# File 'ext/ca_obj_transpose.c', line 519
static VALUE
rb_ca_trans (int argc, VALUE *argv, VALUE self)
{
volatile VALUE obj;
CArray *ca;
ca_size_t imap[CA_RANK_MAX];
int8_t i;
Data_Get_Struct(self, CArray, ca);
if ( argc == 0 ) {
for (i=0; i<ca->ndim; i++) {
imap[i] = ca->ndim - i - 1;
}
}
else if ( argc == ca->ndim ) {
for (i=0; i<ca->ndim; i++) {
imap[i] = NUM2SIZE(argv[i]);
}
}
else {
rb_raise(rb_eArgError, "# of arguments should be equal to ndim");
}
obj = rb_ca_trans_new(self, imap);
return obj;
}
|
#trim(min, max, fill_value = nil) ⇒ Object
(Conversion) Trims the data into the range between min and max. If fill_value is given, the element out of the range between min and max is filled by fill_value
745 746 747 748 749 750 |
# File 'ext/carray_generate.c', line 745
static VALUE
rb_ca_trim (int argc, VALUE *argv, VALUE self)
{
volatile VALUE out = rb_ca_copy(self);
return rb_ca_trim_bang(argc, argv, out);
}
|
#trim!(min, max, fill_value = nil) ⇒ Object
(Conversion) Trims the data into the range between min and max. If fill_value is given, the element out of the range between min and max is filled by fill_value
697 698 699 700 701 702 703 704 705 706 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 |
# File 'ext/carray_generate.c', line 697
static VALUE
rb_ca_trim_bang (int argc, VALUE *argv, VALUE self)
{
volatile VALUE rmin, rmax, rfval;
CArray *ca;
rb_ca_modify(self);
Data_Get_Struct(self, CArray, ca);
rb_scan_args(argc, argv, "21", (VALUE *) &rmin, (VALUE *) &rmax, (VALUE *) &rfval);
if ( rfval == CA_UNDEF ) {
ca_create_mask(ca);
}
ca_attach(ca);
switch ( ca->data_type ) {
case CA_INT8: proc_trim_bang(int8_t, NUM2INT); break;
case CA_UINT8: proc_trim_bang(uint8_t, NUM2UINT); break;
case CA_INT16: proc_trim_bang(int16_t, NUM2INT); break;
case CA_UINT16: proc_trim_bang(uint16_t, NUM2INT); break;
case CA_INT32: proc_trim_bang(int32_t, NUM2LONG); break;
case CA_UINT32: proc_trim_bang(uint32_t, NUM2LONG); break;
case CA_INT64: proc_trim_bang(int64_t, NUM2LONG); break;
case CA_UINT64: proc_trim_bang(uint64_t, NUM2LONG); break;
case CA_FLOAT32: proc_trim_bang(float32_t, NUM2DBL); break;
case CA_FLOAT64: proc_trim_bang(float64_t, NUM2DBL); break;
case CA_FLOAT128: proc_trim_bang(float128_t, NUM2DBL); break;
default:
rb_raise(rb_eCADataTypeError,
"can not trim for non-numeric or complex data type");
}
ca_detach(ca);
return self;
}
|
#true ⇒ Object
Returns the 8-bit integer CArray object filled with 1 which dimension size is same as self. The resulted array represents the logical array which has true for its all elements.
20 21 22 |
# File 'lib/carray/convert.rb', line 20 def true () return template(:boolean) { 1 } end |
#uint16 ⇒ Object
(Conversion) Short-Hand of “CArray#to_type(:uint16)”
408 409 410 411 |
# File 'ext/carray_cast.c', line 408
VALUE rb_ca_to_uint16 (VALUE self)
{
rb_ca_to_type_method_body(CA_UINT16);
}
|
#uint32 ⇒ Object
(Conversion) Short-Hand of “CArray#to_type(:uint32)”
426 427 428 429 |
# File 'ext/carray_cast.c', line 426
VALUE rb_ca_to_uint32 (VALUE self)
{
rb_ca_to_type_method_body(CA_UINT32);
}
|
#uint64 ⇒ Object
(Conversion) Short-Hand of “CArray#to_type(:uint64)”
444 445 446 447 |
# File 'ext/carray_cast.c', line 444
VALUE rb_ca_to_uint64 (VALUE self)
{
rb_ca_to_type_method_body(CA_UINT64);
}
|
#uint8 ⇒ Object Also known as: byte
(Conversion) Short-Hand of “CArray#to_type(:uint8)”
390 391 392 393 |
# File 'ext/carray_cast.c', line 390
VALUE rb_ca_to_uint8 (VALUE self)
{
rb_ca_to_type_method_body(CA_UINT8);
}
|
#unbound_repeat ⇒ Object
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 |
# File 'ext/ca_obj_unbound_repeat.c', line 292
VALUE
rb_ca_unbound_repeat (int argc, VALUE *argv, VALUE self)
{
CArray *ca;
int8_t ndim;
ca_size_t dim[CA_RANK_MAX];
int32_t rep_ndim;
ca_size_t rep_dim[CA_RANK_MAX];
ca_size_t elements, count, i;
Data_Get_Struct(self, CArray, ca);
rep_ndim = argc;
count = 0;
ndim = 0;
elements = 1;
for (i=0; i<rep_ndim; i++) {
if ( rb_obj_is_kind_of(argv[i], rb_cSymbol) ) {
if ( argv[i] == ID2SYM(rb_intern("*")) ) {
rep_dim[i] = 0;
}
else {
rb_raise(rb_eArgError, "unknown symbol (!= ':*') in arguments");
}
}
else {
if ( ! NIL_P(argv[i]) ) {
rb_raise(rb_eArgError, "invalid argument");
}
rep_dim[i] = ca->dim[count];
dim[ndim] = ca->dim[count];
elements *= ca->dim[count];
count++; ndim++;
}
}
if ( elements != ca->elements ) {
rb_raise(rb_eArgError, "mismatch in entity elements (%lli for %lli)", elements, ca->elements);
}
if ( ndim != ca->ndim ) {
rb_raise(rb_eArgError, "invalid number of nil's (%i for %i)", ndim, ca->ndim);
}
else {
return rb_ca_ubrep_new(self, rep_ndim, rep_dim);
}
}
|
#uniq ⇒ Object
Returns the array eliminated all the duplicated elements.
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/carray/testing.rb', line 43 def uniq ary = to_a.uniq if has_mask? ary.delete(UNDEF) end if has_data_class? return CArray.new(data_class, [ary.length]) { ary } else return CArray.new(data_type, [ary.length], :bytes=>bytes) { ary } end end |
#unmask(fill_value = nil) ⇒ Object
(Masking, Destructive) Unmask all elements of the object. If the optional argument fill_value is given, the masked elements are filled by fill_value. The returned array doesn’t have the mask array.
860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 |
# File 'ext/carray_mask.c', line 860
static VALUE
rb_ca_unmask_method (int argc, VALUE *argv, VALUE self)
{
volatile VALUE rfval = CA_NIL, rcs;
CArray *ca;
CScalar *cv;
char *fval = NULL;
rb_ca_modify(self);
if ( argc >= 1 ) {
rfval = argv[0];
}
Data_Get_Struct(self, CArray, ca);
if ( rfval != CA_NIL ) {
rcs = rb_cscalar_new_with_value(ca->data_type, ca->bytes, rfval);
Data_Get_Struct(rcs, CScalar, cv);
fval = cv->ptr;
}
ca_unmask(ca, fval);
return self;
}
|
#unmask_copy(fill_value = nil) ⇒ Object
(Masking, Conversion) Returns new unmasked array. If the optional argument fill_value is given, the masked elements are filled by fill_value. The returned array doesn’t have the mask array.
912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 |
# File 'ext/carray_mask.c', line 912
static VALUE
rb_ca_unmask_copy_method (int argc, VALUE *argv, VALUE self)
{
volatile VALUE obj, rfval = CA_NIL, rcs;
CArray *ca, *co;
CScalar *cv;
char *fval = NULL;
if ( argc >= 1 ) {
rfval = argv[0];
}
Data_Get_Struct(self, CArray, ca);
if ( rfval != CA_NIL ) {
rcs = rb_cscalar_new_with_value(ca->data_type, ca->bytes, rfval);
Data_Get_Struct(rcs, CScalar, cv);
fval = cv->ptr;
}
co = ca_unmask_copy(ca, fval);
obj = ca_wrap_struct(co);
rb_ca_data_type_inherit(obj, self);
return obj;
}
|
#unset(*idx) ⇒ Object
(Boolean, Modification) Sets false at the given index for the boolean array and returns self. It accept the arguments same as for CArray#[].
42 43 44 45 46 47 48 49 50 51 52 |
# File 'ext/carray_generate.c', line 42
static VALUE
rb_ca_boolean_unset (int argc, VALUE *argv, VALUE self)
{
VALUE zero = INT2NUM(0);
rb_ca_modify(self);
if ( ! rb_ca_is_boolean_type(self) ) {
rb_raise(rb_eCADataTypeError, "reciever should be a boolean array");
}
rb_ca_store2(self, argc, argv, zero);
return self;
}
|
#unsigned? ⇒ Boolean
(Inquiry) Return true if self is unsigned integer type array
498 499 500 501 502 503 504 |
# File 'ext/carray_attribute.c', line 498
VALUE
rb_ca_is_unsigned_type (VALUE self)
{
CArray *ca;
Data_Get_Struct(self, CArray, ca);
return ca_is_unsigned_type(ca) ? Qtrue : Qfalse;
}
|
#valid_addr?(*addr) ⇒ Boolean
(Inquiry) Returns true if the given number is valid as array address for the object
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 |
# File 'ext/carray_test.c', line 259
static VALUE
rb_ca_is_valid_addr (VALUE self, VALUE raddr)
{
CArray *ca;
ca_size_t addr;
Data_Get_Struct(self, CArray, ca);
addr = NUM2SIZE(raddr);
if ( addr < 0 ) {
addr += ca->elements;
}
if ( addr < 0 || addr >= ca->elements ) {
return Qfalse;
}
else {
return Qtrue;
}
}
|
#valid_index?(*idx) ⇒ Boolean
(Inquiry) Returns true if the given number list is valid as array index for the object
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 |
# File 'ext/carray_test.c', line 227
static VALUE
rb_ca_is_valid_index (int argc, VALUE *argv, VALUE self)
{
CArray *ca;
ca_size_t idx;
int i;
Data_Get_Struct(self, CArray, ca);
if ( argc != ca->ndim ) {
rb_raise(rb_eArgError,
"invalid # of arguments (%i for %i)", argc, ca->ndim);
}
for (i=0; i<ca->ndim; i++) {
idx = NUM2SIZE(argv[i]);
if ( idx < 0 ) {
idx += ca->dim[i];
}
if ( idx < 0 || idx >= ca->dim[i] ) {
return Qfalse;
}
}
return Qtrue;
}
|
#value ⇒ Object
(Masking, Inquiry) Returns new array which refers the data of self. The data of masked elements of self can be accessed via the returned array. The value array can’t be set mask.
649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 |
# File 'ext/carray_mask.c', line 649
VALUE
rb_ca_value_array (VALUE self)
{
VALUE obj;
CArray *ca, *co;
Data_Get_Struct(self, CArray, ca);
obj = rb_ca_refer_new(self, ca->data_type, ca->ndim, ca->dim, ca->bytes, 0);
Data_Get_Struct(obj, CArray, co);
ca_set_flag(co, CA_FLAG_VALUE_ARRAY);
return obj;
}
|
#value_array? ⇒ Boolean
(Inquiry) Returns true if self is a value array
378 379 380 381 382 383 384 |
# File 'ext/carray_attribute.c', line 378
VALUE
rb_ca_is_value_array (VALUE self)
{
CArray *ca;
Data_Get_Struct(self, CArray, ca);
return ( ca_is_value_array(ca) ) ? Qtrue : Qfalse;
}
|
#variance ⇒ Object
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 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 |
# File 'ext/carray_stat.c', line 807
static VALUE
rb_ca_variance (int argc, VALUE *argv, VALUE self)
{
volatile VALUE out, rmin_count = Qnil, rfval = Qnil;
CArray *ca;
ca_size_t min_count;
if ( argc > 0 ) {
rb_scan_args(argc, argv, "02", (VALUE *) &rmin_count, (VALUE *) &rfval);
}
Data_Get_Struct(self, CArray, ca);
if ( ca->elements == 0 ) {
return ( NIL_P(rfval) ) ? CA_UNDEF : rfval;
}
min_count = ( NIL_P(rmin_count) || ! ca_has_mask(ca) ) ?
ca->elements - 1 : NUM2SIZE(rmin_count);
if ( min_count < 0 ) {
min_count += ca->elements;
}
ca_attach(ca);
switch ( ca->data_type ) {
case CA_BOOLEAN:
case CA_INT8: proc_variance(int8_t,); break;
case CA_UINT8: proc_variance(uint8_t,); break;
case CA_INT16: proc_variance(int16_t,); break;
case CA_UINT16: proc_variance(uint16_t,); break;
case CA_INT32: proc_variance(int32_t,); break;
case CA_UINT32: proc_variance(uint32_t,); break;
case CA_INT64: proc_variance(int64_t,); break;
case CA_UINT64: proc_variance(uint64_t,); break;
case CA_FLOAT32: proc_variance(float32_t,); break;
case CA_FLOAT64: proc_variance(float64_t,); break;
case CA_FLOAT128: proc_variance(float128_t,); break;
case CA_OBJECT: proc_variance(VALUE,NUM2DBL); break;
default: rb_raise(rb_eRuntimeError, "invalid data type");
}
ca_detach(ca);
return out;
}
|
#variancep ⇒ Object
704 705 706 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 741 742 743 744 745 746 747 748 749 750 |
# File 'ext/carray_stat.c', line 704
static VALUE
rb_ca_variancep (int argc, VALUE *argv, VALUE self)
{
volatile VALUE out, rmin_count = Qnil, rfval = Qnil;
CArray *ca;
ca_size_t min_count;
if ( argc > 0 ) {
rb_scan_args(argc, argv, "02", (VALUE *) &rmin_count, (VALUE *) &rfval);
}
Data_Get_Struct(self, CArray, ca);
if ( ca->elements == 0 ) {
return ( NIL_P(rfval) ) ? CA_UNDEF : rfval;
}
min_count = ( NIL_P(rmin_count) || ! ca_has_mask(ca) ) ?
ca->elements - 1 : NUM2SIZE(rmin_count);
if ( min_count < 0 ) {
min_count += ca->elements;
}
ca_attach(ca);
switch ( ca->data_type ) {
case CA_BOOLEAN:
case CA_INT8: proc_variancep(int8_t,); break;
case CA_UINT8: proc_variancep(uint8_t,); break;
case CA_INT16: proc_variancep(int16_t,); break;
case CA_UINT16: proc_variancep(uint16_t,); break;
case CA_INT32: proc_variancep(int32_t,); break;
case CA_UINT32: proc_variancep(uint32_t,); break;
case CA_INT64: proc_variancep(int64_t,); break;
case CA_UINT64: proc_variancep(uint64_t,); break;
case CA_FLOAT32: proc_variancep(float32_t,); break;
case CA_FLOAT64: proc_variancep(float64_t,); break;
case CA_FLOAT128: proc_variancep(float128_t,); break;
case CA_OBJECT: proc_variancep(VALUE,NUM2DBL); break;
default: rb_raise(rb_eRuntimeError, "invalid data type");
}
ca_detach(ca);
return out;
}
|
#virtual? ⇒ Boolean
(Inquiry) Returns true if self is a virtural array (not an entity array).
249 250 251 252 253 254 255 |
# File 'ext/carray_attribute.c', line 249
VALUE
rb_ca_is_virtual (VALUE self)
{
CArray *ca;
Data_Get_Struct(self, CArray, ca);
return ( ca_is_virtual(ca) ) ? Qtrue : Qfalse;
}
|
#where ⇒ Object
(Conversion) Returns the 1d index array for non-zero elements of self
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 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 |
# File 'ext/carray_generate.c', line 62
VALUE
rb_ca_where (VALUE self)
{
volatile VALUE bool, obj;
CArray *ca, *co;
boolean8_t *p, *m;
ca_size_t *q;
ca_size_t i, count;
bool = ( ! rb_ca_is_boolean_type(self) ) ? rb_ca_to_boolean(self) : self;
Data_Get_Struct(bool, CArray, ca);
ca_attach(ca);
/* calculate elements of output array */
p = (boolean8_t *) ca->ptr;
m = ca_mask_ptr(ca);
count = 0;
if ( m ) {
for (i=0; i<ca->elements; i++) {
if ( ( ! *m ) && ( *p ) ) { count++; } /* not-masked && true */
m++; p++;
}
}
else {
for (i=0; i<ca->elements; i++) {
if ( *p ) { count++; } /* true */
p++;
}
}
/* create output array */
obj = rb_carray_new(CA_SIZE, 1, &count, 0, NULL);
Data_Get_Struct(obj, CArray, co);
/* store address which elements is true to output array */
p = (boolean8_t *) ca->ptr;
q = (ca_size_t *) co->ptr;
m = ca_mask_ptr(ca);
if ( m ) {
for (i=0; i<ca->elements; i++) { /* not-masked && true */
if ( ( ! *m ) && ( *p ) ) { *q = i; q++; }
m++; p++;
}
}
else { /* true */
for (i=0; i<ca->elements; i++) {
if ( *p ) { *q = i; q++; }
p++;
}
}
ca_detach(ca);
return obj;
}
|
#where_range ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/carray/testing.rb', line 31 def where_range w = where x = (w - w.shifted(1){-2}).sub!(1).where y = (w - w.shifted(-1){-2}).add!(1).where list = [] x.each_addr do |i| list.push(w[x[i]]..w[y[i]]) end return list end |
#window ⇒ Object
yard:
class CArray
def window (*argv)
end
end
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 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 |
# File 'ext/ca_obj_window.c', line 711
VALUE
rb_ca_window (int argc, VALUE *argv, VALUE self)
{
volatile VALUE obj, ropt, rfval = CA_NIL, rbounds = Qnil, rcs;
CArray *ca;
CScalar *cs;
ca_size_t start[CA_RANK_MAX];
ca_size_t count[CA_RANK_MAX];
int32_t bounds = CA_BOUNDS_FILL;
char *fill = NULL;
char *cbounds;
ca_size_t i;
Data_Get_Struct(self, CArray, ca);
ropt = rb_pop_options(&argc, &argv);
rb_scan_options(ropt, "bounds,fill_value", &rbounds, &rfval);
if ( argc != ca->ndim ) {
rb_raise(rb_eArgError, "ndim mismatch");
}
for (i=0; i<argc; i++) {
ca_size_t offset, len, step;
volatile VALUE arg = argv[i];
ca_parse_range_without_check(arg, ca->dim[i], &offset, &len, &step);
if ( step != 1 || len < 0 ) {
rb_raise(rb_eArgError,
"first index should smaller than last index. "
"The index range notation such as 0..-1 can't be used in CArray#window");
}
start[i] = offset;
count[i] = len;
}
if ( rfval == CA_NIL ) {
if ( rb_block_given_p() ) {
rfval = rb_yield(self);
}
}
else {
/* rb_warn(":fill_value option for CArray#window will be obsoleted."); */
}
if ( rfval == CA_NIL ) {
;
}
else if ( rfval == CA_UNDEF ) {
bounds = CA_BOUNDS_MASK;
}
else {
rcs = rb_cscalar_new_with_value(ca->data_type, ca->bytes, rfval);
Data_Get_Struct(rcs, CScalar, cs);
fill = cs->ptr;
}
if ( ! NIL_P(rbounds) ) {
switch ( TYPE(rbounds) ) {
case T_STRING:
cbounds = StringValuePtr(rbounds);
if ( rfval == CA_UNDEF && strncmp(cbounds, "fill", 4)
&& strncmp(cbounds, "mask", 4) ) {
rb_raise(rb_eRuntimeError, "conflicted bounds and fill_value");
}
if ( ! strncmp(cbounds, "ruby", 4) ) {
bounds = CA_BOUNDS_RUBY;
}
else if ( ! strncmp(cbounds, "strict", 6) ) {
bounds = CA_BOUNDS_STRICT;
}
else if ( ! strncmp(cbounds, "nearest", 7) ) {
bounds = CA_BOUNDS_NEAREST;
}
else if ( ! strncmp(cbounds, "periodic", 8) ) {
bounds = CA_BOUNDS_PERIODIC;
}
else if ( ! strncmp(cbounds, "reflect", 7) ) {
bounds = CA_BOUNDS_REFLECT;
}
else if ( ! strncmp(cbounds, "mask", 4) ) {
rb_warn("CAWindow option :bounds=>\"mask\" will be obsolete");
rb_warn("use ca.window(...) { UNDEF }");
bounds = CA_BOUNDS_MASK;
}
else if ( ! strncmp(cbounds, "fill", 4) ) {
bounds = CA_BOUNDS_FILL;
}
else {
rb_raise(rb_eRuntimeError,
"unknown option value '%s' for :bounds", cbounds);
}
break;
case T_FIXNUM:
bounds = NUM2INT(rbounds);
break;
default:
rb_raise(rb_eRuntimeError, "invalid option value for :bounds");
}
}
obj = rb_ca_window_new(self, start, count, bounds, fill);
return obj;
}
|
#window_iterator(*argv) ⇒ Object
:nodoc:
146 147 148 149 |
# File 'lib/carray/obsolete.rb', line 146 def window_iterator (*argv) # :nodoc: warn "CArray#window_iterator will be obsolete, use CArray#windows" return windows(*argv) end |
#windows(*args, &block) ⇒ Object
298 299 300 |
# File 'lib/carray/iterator.rb', line 298 def windows (*args, &block) return CAWindowIterator.new(self.window(*args, &block)) end |
#wmean ⇒ Object
587 588 589 590 591 592 593 594 595 596 597 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 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 |
# File 'ext/carray_stat.c', line 587
static VALUE
rb_ca_wmean (int argc, VALUE *argv, VALUE self)
{
volatile VALUE out, weight = argv[0], rmin_count = Qnil, rfval = Qnil, tmp;
CArray *ca, *cw;
ca_size_t min_count;
if ( argc > 1 ) {
rb_scan_args(argc, argv, "12", (VALUE *) &weight, (VALUE *) &rmin_count, (VALUE *) &rfval);
}
Data_Get_Struct(self, CArray, ca);
cw = ca_wrap_readonly(weight, ca->data_type);
ca_check_same_elements(ca, cw);
if ( ca->elements == 0 ) {
return ( NIL_P(rfval) ) ? CA_UNDEF : rfval;
}
if ( ca_has_mask(cw) ) {
ca = ca_copy(ca);
tmp = ca_wrap_struct(ca);
ca_copy_mask_overlay(ca, ca->elements, 1, cw);
}
min_count = ( NIL_P(rmin_count) || ( ! ca_has_mask(ca) ) ) ?
ca->elements - 1 : NUM2SIZE(rmin_count);
if ( min_count < 0 ) {
min_count += ca->elements;
}
ca_attach_n(2, ca, cw);
switch ( ca->data_type ) {
case CA_BOOLEAN:
case CA_INT8: proc_wmean(int8_t, double,,rb_float_new); break;
case CA_UINT8: proc_wmean(uint8_t,double,,rb_float_new); break;
case CA_INT16: proc_wmean(int16_t,double,,rb_float_new); break;
case CA_UINT16: proc_wmean(uint16_t,double,,rb_float_new); break;
case CA_INT32: proc_wmean(int32_t,double,,rb_float_new); break;
case CA_UINT32: proc_wmean(uint32_t,double,,rb_float_new); break;
case CA_INT64: proc_wmean(int64_t,double,,rb_float_new); break;
case CA_UINT64: proc_wmean(uint64_t,double,,rb_float_new); break;
case CA_FLOAT32: proc_wmean(float32_t,double,,rb_float_new); break;
case CA_FLOAT64: proc_wmean(float64_t,double,,rb_float_new); break;
case CA_FLOAT128: proc_wmean(float128_t,double,,rb_float_new); break;
#ifdef HAVE_COMPLEX_H
case CA_CMPLX64: proc_wmean(cmplx64_t,cmplx128_t,,rb_ccomplex_new); break;
case CA_CMPLX128: proc_wmean(cmplx128_t,cmplx128_t,,rb_ccomplex_new); break;
case CA_CMPLX256: proc_wmean(cmplx256_t,cmplx128_t,,rb_ccomplex_new); break;
#endif
case CA_OBJECT: proc_wmean(VALUE,double,NUM2DBL,rb_float_new); break;
default: rb_raise(rb_eRuntimeError, "invalid data type");
}
ca_detach_n(2, ca, cw);
return out;
}
|
#wsum ⇒ Object
373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 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 431 432 433 |
# File 'ext/carray_stat.c', line 373
static VALUE
rb_ca_wsum (int argc, VALUE *argv, VALUE self)
{
volatile VALUE out, weight = argv[0], rmin_count = Qnil, rfval = Qnil, tmp;
CArray *ca, *cw;
ca_size_t min_count;
if ( argc > 1 ) {
rb_scan_args(argc, argv, "12", (VALUE *) &weight, (VALUE *) &rmin_count, (VALUE *) &rfval);
}
Data_Get_Struct(self, CArray, ca);
cw = ca_wrap_readonly(weight, ca->data_type);
ca_check_same_elements(ca, cw);
if ( ca->elements == 0 ) {
return ( NIL_P(rfval) ) ? CA_UNDEF : rfval;
}
if ( ca_has_mask(cw) ) {
ca = ca_copy(ca);
tmp = ca_wrap_struct(ca);
ca_copy_mask_overlay(ca, ca->elements, 1, cw);
}
min_count = ( NIL_P(rmin_count) || ( ! ca_has_mask(ca) ) ) ?
ca->elements - 1 : NUM2SIZE(rmin_count);
if ( min_count < 0 ) {
min_count += ca->elements;
}
ca_attach_n(2, ca, cw);
switch ( ca->data_type ) {
case CA_BOOLEAN:
case CA_INT8: proc_wsum(int8_t, double,,rb_float_new); break;
case CA_UINT8: proc_wsum(uint8_t,double,,rb_float_new); break;
case CA_INT16: proc_wsum(int16_t,double,,rb_float_new); break;
case CA_UINT16: proc_wsum(uint16_t,double,,rb_float_new); break;
case CA_INT32: proc_wsum(int32_t,double,,rb_float_new); break;
case CA_UINT32: proc_wsum(uint32_t,double,,rb_float_new); break;
case CA_INT64: proc_wsum(int64_t,double,,rb_float_new); break;
case CA_UINT64: proc_wsum(uint64_t,double,,rb_float_new); break;
case CA_FLOAT32: proc_wsum(float32_t,double,,rb_float_new); break;
case CA_FLOAT64: proc_wsum(float64_t,double,,rb_float_new); break;
case CA_FLOAT128: proc_wsum(float128_t,double,,rb_float_new); break;
#ifdef HAVE_COMPLEX_H
case CA_CMPLX64: proc_wsum(cmplx64_t,cmplx128_t,,rb_ccomplex_new); break;
case CA_CMPLX128: proc_wsum(cmplx128_t,cmplx128_t,,rb_ccomplex_new); break;
case CA_CMPLX256: proc_wsum(cmplx256_t,cmplx128_t,,rb_ccomplex_new); break;
#endif
case CA_OBJECT: proc_wsum(VALUE,double,NUM2DBL,rb_float_new); break;
default: rb_raise(rb_eRuntimeError, "invalid data type");
}
ca_detach_n(2, ca, cw);
return out;
}
|