Class: NArray
- Inherits:
-
Object
- Object
- NArray
- Defined in:
- lib/narray_extext.rb
Class Method Summary collapse
- .build(typecode, *sizes) ⇒ Object
- .complex_typecode?(typecode) ⇒ Boolean
- .filled(typecode, data, *sizes) ⇒ Object
Instance Method Summary collapse
Class Method Details
.build(typecode, *sizes) ⇒ Object
13 14 15 16 17 |
# File 'lib/narray_extext.rb', line 13 def self.build(typecode, *sizes) nary = new(typecode, *sizes) (0 ... nary.size).each{|i| nary[i] = yield(*nary.ndindex_from_1dindex(i)) } nary end |
.complex_typecode?(typecode) ⇒ Boolean
29 30 31 |
# File 'lib/narray_extext.rb', line 29 def self.complex_typecode?(typecode) typecode == NArray::DCOMPLEX || typecode == NArray::SCOMPLEX end |
.filled(typecode, data, *sizes) ⇒ Object
33 34 35 36 37 |
# File 'lib/narray_extext.rb', line 33 def self.filled(typecode, data, *sizes) naray = new(typecode, *sizes) naray.fill(data) naray end |
Instance Method Details
#each_with_index ⇒ Object
25 26 27 |
# File 'lib/narray_extext.rb', line 25 def each_with_index (0 ... size).each{|i| yield(self[i], *ndindex_from_1dindex(i)) } end |
#ndindex_from_1dindex(i) ⇒ Object
19 20 21 22 23 |
# File 'lib/narray_extext.rb', line 19 def ndindex_from_1dindex(i) ret = [] shape.each{|n| ret << i%n; i /= n } ret end |
#real? ⇒ Boolean
9 10 11 |
# File 'lib/narray_extext.rb', line 9 def real? typecode == DFLOAT || typecode == SFLOAT end |
#square? ⇒ Boolean
4 5 6 7 |
# File 'lib/narray_extext.rb', line 4 def square? shape = self.shape rank == 2 && shape[0] == shape[1] end |