Class: NArray

Inherits:
Object
  • Object
show all
Defined in:
lib/narray_extext.rb

Class Method Summary collapse

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

Returns:

  • (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_indexObject



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

Returns:

  • (Boolean)


9
10
11
# File 'lib/narray_extext.rb', line 9

def real?
  typecode == DFLOAT || typecode == SFLOAT
end

#square?Boolean

Returns:

  • (Boolean)


4
5
6
7
# File 'lib/narray_extext.rb', line 4

def square?
  shape = self.shape
  rank == 2 && shape[0] == shape[1]
end