Class: ANArray
- Inherits:
-
NArray
- Object
- NArray
- ANArray
- Defined in:
- lib/narray_ffi.rb
Constant Summary collapse
- FFITYPECODES =
{ NArray::BYTE => :char, NArray::SINT => :short, NArray::INT => :int, NArray::SFLOAT => :float, NArray::FLOAT => :double, NArray::SCOMPLEX => :float, NArray::COMPLEX => :double }
Class Method Summary collapse
- .byte(alignment, *size) ⇒ Object
- .complex(alignment, *size) ⇒ Object
- .float(alignment, *size) ⇒ Object
- .int(alignment, *size) ⇒ Object
- .new(typecode, alignment, *size) ⇒ Object
- .object(alignment, *size) ⇒ Object
- .scomplex(alignment, *size) ⇒ Object
- .sfloat(alignment, *size) ⇒ Object
- .sint(alignment, *size) ⇒ Object
Class Method Details
.byte(alignment, *size) ⇒ Object
30 31 32 |
# File 'lib/narray_ffi.rb', line 30 def self.byte(alignment, *size) return self.new(NArray::BYTE, alignment, *size) end |
.complex(alignment, *size) ⇒ Object
54 55 56 |
# File 'lib/narray_ffi.rb', line 54 def self.complex(alignment, *size) return self.new(NArray::COMPLEX, alignment, *size) end |
.float(alignment, *size) ⇒ Object
46 47 48 |
# File 'lib/narray_ffi.rb', line 46 def self.float(alignment, *size) return self.new(NArray::FLOAT, alignment, *size) end |
.int(alignment, *size) ⇒ Object
38 39 40 |
# File 'lib/narray_ffi.rb', line 38 def self.int(alignment, *size) return self.new(NArray::INT, alignment, *size) end |
.new(typecode, alignment, *size) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/narray_ffi.rb', line 17 def self.new(typecode, alignment, *size) raise "Wrong type code" if not FFITYPECODES[typecode] raise "Invalid alignment" unless alignment > 0 and ( alignment & (alignment - 1) == 0 ) total = size.reduce(:*) total = 2*total if typecode == NArray::COMPLEX or typecode == NArray::SCOMPLEX mem = FFI::MemoryPointer::new( FFITYPECODES[typecode], total + alignment - 1 ) address = mem.address offset = address & (alignment - 1) offset = alignment - offset unless offset == 0 mem = mem.slice(offset, total*mem.type_size) return NArray.to_na(mem, typecode, *size) end |
.object(alignment, *size) ⇒ Object
58 59 60 |
# File 'lib/narray_ffi.rb', line 58 def self.object(alignment, *size) return self.new(NArray::OBJECT, alignment, *size) end |
.scomplex(alignment, *size) ⇒ Object
50 51 52 |
# File 'lib/narray_ffi.rb', line 50 def self.scomplex(alignment, *size) return self.new(NArray::SCOMPLEX, alignment, *size) end |
.sfloat(alignment, *size) ⇒ Object
42 43 44 |
# File 'lib/narray_ffi.rb', line 42 def self.sfloat(alignment, *size) return self.new(NArray::SFLOAT, alignment, *size) end |
.sint(alignment, *size) ⇒ Object
34 35 36 |
# File 'lib/narray_ffi.rb', line 34 def self.sint(alignment, *size) return self.new(NArray::SINT, alignment, *size) end |