ndav-torch-tensor 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '0680ecfdc12ff8c7439ae719364591beeae64666e91c0cc33b47429222848682'
4
- data.tar.gz: 3ee2acec3f638e8918828496250a85f7b531750b9bfaa366c1f2d31b2b126f84
3
+ metadata.gz: ea390bc80d0a532c10da276aac487657743f4e188a93db24424662c22be0e7c4
4
+ data.tar.gz: 620f47e4a3feda6a59958562a4e4463ba6fd2afa2cb03cb2b2b75846fe80bd7f
5
5
  SHA512:
6
- metadata.gz: d0aa2feab3aed3844acaea511a61eda04befd736db3a7009bb4627421cfafe486d21e9300e0bf2ea02483215879c461b555c59857ccbaf8eeaba6944db4b576f
7
- data.tar.gz: 94eac20b44cf43b958eb817992e3c11fdb4541b0853fb70c720e5ed0d27affc061f7f528c5688c5c43c7ecf6e4b37dba5273b7958e699ae11b33da8e127f66b5
6
+ metadata.gz: 3c026d68364bc1a9a8511372dfb9ad2f2d83d8cb1887a1c744575cf8121bf3722d96d536b61bf1f996d0fd3c5b79ad3011cedc4ccb2fa58275510cb7ae60f85c
7
+ data.tar.gz: be8683e7369a631c60f64564f7884c6ee47bdc317885cfdb0b208edf9df66c52fbf0cb8788175ee3be8629bb859d5517d051ef40070731810d125a78edea7ea0
@@ -31,31 +31,38 @@ class NDAV
31
31
  float64: "d"
32
32
  }
33
33
 
34
- FORMAT_TO_TYPE = ITEM_SIZES.to_h {|format, size|
35
- suffix = size * 8
36
- type = case format
37
- when "s!", "c", "s", "l", "q", "i", "i!", "l!", "q!"
38
- :"int#{suffix}"
39
- when "S!", "C", "S", "L", "Q", "I", "I!", "L!", "Q!"
40
- :"uint#{suffix}"
41
- when "f", "d"
42
- :"float#{suffix}"
43
- else
44
- case IO::Buffer::HOST_ENDIAN
45
- when IO::Buffer::LITTLE_ENDIAN
46
- if ["v", "V", "e", "E"].include? format
47
- :"float#{suffix}"
48
- end
49
- when IO::Buffer::BIG_ENDIAN
50
- if ["n", "N", "g", "G"].include? format
51
- :"float#{suffix}"
52
- end
53
- end
54
- end
55
- [format, type]
56
- }
34
+ FORMAT_TO_TYPE = Hash.new {|types, format| types[format] = type_from_format(format)}
35
+
36
+ class << self
37
+ def type_from_format(format)
38
+ item_desc = ITEM_DESCS[format]
39
+ return unless item_desc.length == 1
57
40
 
58
- TYPE_SIZES = TYPE_TO_FORMAT.transform_values {|format| ITEM_SIZES[format]}
41
+ component = item_desc[0]
42
+ return unless component.repeat == 1
43
+
44
+ suffix = component.size * 8
45
+ case component.format
46
+ when "c", "s", "l", "q", "i", "j"
47
+ :"int#{suffix}"
48
+ when "C", "S", "L", "Q", "I", "J"
49
+ :"uint#{suffix}"
50
+ when "f", "d"
51
+ :"float#{suffix}"
52
+ else
53
+ case IO::Buffer::HOST_ENDIAN
54
+ when IO::Buffer::LITTLE_ENDIAN
55
+ if ["v", "V", "e", "E"].include? format
56
+ :"float#{suffix}"
57
+ end
58
+ when IO::Buffer::BIG_ENDIAN
59
+ if ["n", "N", "g", "G"].include? format
60
+ :"float#{suffix}"
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
59
66
 
60
67
  module MemoryViewable
61
68
  def ndav_descriptor(**)
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "ndav-torch-tensor"
3
- s.version = "0.0.4"
3
+ s.version = "0.0.5"
4
4
  s.authors = ["Kitaiti Makoto"]
5
5
  s.summary = "N-Dimensional Array View for Torch::Tensors"
6
6
  s.licenses = ["MIT"]
@@ -8,7 +8,7 @@ Gem::Specification.new do |s|
8
8
 
9
9
  s.files = Dir.chdir(__dir__) {`git ls-files -z`.split("\x0")}
10
10
 
11
- s.add_runtime_dependency "ndav", ">= 0.0.6"
11
+ s.add_runtime_dependency "ndav", ">= 0.0.7"
12
12
  s.add_runtime_dependency "torch-rb"
13
13
 
14
14
  s.add_development_dependency "rake"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ndav-torch-tensor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kitaiti Makoto
@@ -15,14 +15,14 @@ dependencies:
15
15
  requirements:
16
16
  - - ">="
17
17
  - !ruby/object:Gem::Version
18
- version: 0.0.6
18
+ version: 0.0.7
19
19
  type: :runtime
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
23
23
  - - ">="
24
24
  - !ruby/object:Gem::Version
25
- version: 0.0.6
25
+ version: 0.0.7
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: torch-rb
28
28
  requirement: !ruby/object:Gem::Requirement