narray_ffi 1.1.1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/narray_ffi.rb +60 -0
  3. data/narray_ffi.gemspec +1 -1
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 510a401c952751ea163855b174e72a2f871c25d4
4
- data.tar.gz: 9e81c0380bc8e31ec91a82c5f72b4df4344b0516
3
+ metadata.gz: 7999260e1d1b305db5f0c534e2f5f1e6323fc3ba
4
+ data.tar.gz: 6e439735e3139f0df821b53201c9fe4158d2ecce
5
5
  SHA512:
6
- metadata.gz: 5ef3e44b7ad2999b1cee2146a63d4f34828d27e588d2952bfdff3120e62d17588e7d11dad16801f6c2de80a2db8f96ce5dcef71d759200bba7b0e8083f512282
7
- data.tar.gz: 85840bd05ac8574a205185d5a4f2582161b8135df5870d0e6a7a33dfbb0c1fb7c871a7dbf5c852da9a721951f334b6b27f6a02f4c63a927de192f11e4eaa66c2
6
+ metadata.gz: bf8a6c49ba47dda532a414e2b14d94dfe16c5c4a4fb311fb14839496a9b4fbe3f02b3e687420a32f8f4abc9c1e55f307b4dd3d5c5acdae195e14e51e11f6b25f
7
+ data.tar.gz: 7c0974b9fe5933755a955acb059b7da3e3f3a0cfcf21a9019d8146e5abf7fccef624084a70bc60659ff31e818ad4436b0c367f62d4ec9d500797824dc215cb43
data/lib/narray_ffi.rb CHANGED
@@ -1,3 +1,63 @@
1
1
  require "narray"
2
2
  require "ffi"
3
3
  require "narray_ffi_c.so"
4
+
5
+ class ANArray < NArray
6
+
7
+ FFITYPECODES = {
8
+ NArray::BYTE => :char,
9
+ NArray::SINT => :short,
10
+ NArray::INT => :int,
11
+ NArray::SFLOAT => :float,
12
+ NArray::FLOAT => :double,
13
+ NArray::SCOMPLEX => :float,
14
+ NArray::COMPLEX => :double
15
+ }
16
+
17
+ def self.new(typecode, alignment, *size)
18
+ raise "Wrong type code" if not FFITYPECODES[typecode]
19
+ raise "Invalid alignment" unless alignment > 0 and ( alignment & (alignment - 1) == 0 )
20
+ total = size[0]
21
+ size[1..-1].each { |sz| total = total * sz }
22
+ total = 2*total if typecode == NArray::COMPLEX or typecode == NArray::SCOMPLEX
23
+ mem = FFI::MemoryPointer::new( FFITYPECODES[typecode], total + alignment - 1 )
24
+ address = mem.address
25
+ offset = address & (alignment - 1)
26
+ offset = alignment - offset unless offset == 0
27
+ mem = mem.slice(offset, total*mem.type_size)
28
+ return NArray.to_na(mem, typecode, *size)
29
+ end
30
+
31
+ def self.byte(alignment, *size)
32
+ return self.new(NArray::BYTE, alignment, *size)
33
+ end
34
+
35
+ def self.sint(alignment, *size)
36
+ return self.new(NArray::SINT, alignment, *size)
37
+ end
38
+
39
+ def self.int(alignment, *size)
40
+ return self.new(NArray::INT, alignment, *size)
41
+ end
42
+
43
+ def self.sfloat(alignment, *size)
44
+ return self.new(NArray::SFLOAT, alignment, *size)
45
+ end
46
+
47
+ def self.float(alignment, *size)
48
+ return self.new(NArray::FLOAT, alignment, *size)
49
+ end
50
+
51
+ def self.scomplex(alignment, *size)
52
+ return self.new(NArray::SCOMPLEX, alignment, *size)
53
+ end
54
+
55
+ def self.complex(alignment, *size)
56
+ return self.new(NArray::COMPLEX, alignment, *size)
57
+ end
58
+
59
+ def self.object(alignment, *size)
60
+ return self.new(NArray::OBJECT, alignment, *size)
61
+ end
62
+
63
+ end
data/narray_ffi.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'narray_ffi'
3
- s.version = "1.1.1"
3
+ s.version = "1.2.0"
4
4
  s.author = "Brice Videau"
5
5
  s.email = "brice.videau@imag.fr"
6
6
  s.homepage = "https://forge.imag.fr/projects/opencl-ruby/"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: narray_ffi
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brice Videau