ndav-numo-narray 0.0.5 → 0.0.6

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: beb01a99fd5dc21a663a24670645f31481edd507106bed7737f31223c1e666a8
4
- data.tar.gz: 7c3f16c422223a95c7fe0ed71e377dce9ee497cb72460ea15406b8150dc555ff
3
+ metadata.gz: 027ca1006dbe7107f356ed21e6e5f0e2ea2c1c4388a96707b00ae0fe02c3b113
4
+ data.tar.gz: b13b224ddde18cc20dc0b28086575b4208004fecc6e81d7658e66a66c5473de4
5
5
  SHA512:
6
- metadata.gz: 72f42d4ac0170bc12d69d68b2c4d7ce8674419f39a24321b90696b38af8faf1f901cdaaf6ef3880a4003137b0bc61e1571f03e9d56b0fdc91516834c2df82a80
7
- data.tar.gz: 03ba05a8b1fd7757f2e5fbbad4f201c92cf95a42bff75f2b13cdc998e85b5b07b766d3893402256122439d2d87dcf43e3c279ed7a689ff165acac65b238658f6
6
+ metadata.gz: 3b13d07e24b6f66d7f65a88f7f019147527fc11bb6b1bdf7d04cc8a8b0f6347ecdaa25cf21534d909e3b9a7c78e3ba4f018ea99872206a95500d2ad12c564527
7
+ data.tar.gz: f9d15da6cc2a660508d266015211735a7498c1926b75936132b8bb2e19ae0c5fa44f48822a79dcb0d142986ac577ec4f1993c2745fea3c5e8843e87ec42e38c1
@@ -19,23 +19,7 @@ class NDAV
19
19
  ::Numo::DFloat => "d"
20
20
  }
21
21
 
22
- FORMAT_TO_CLASS = CLASS_TO_FORMAT.invert
23
- case IO::Buffer::HOST_ENDIAN
24
- when IO::Buffer::LITTLE_ENDIAN
25
- FORMAT_TO_CLASS.update({
26
- "v" => ::Numo::UInt16,
27
- "V" => ::Numo::UInt32,
28
- "e" => ::Numo::SFloat,
29
- "E" => ::Numo::DFloat
30
- })
31
- when IO::Buffer::BIG_ENDIAN
32
- FORMAT_TO_CLASS.update({
33
- "n" => ::Numo::UInt16,
34
- "N" => ::Numo::UInt32,
35
- "g" => ::Numo::SFloat,
36
- "G" => ::Numo::DFloat
37
- })
38
- end
22
+ FORMAT_TO_CLASS = Hash.new {|classes, format| classes[format] = class_from_format(format)}
39
23
 
40
24
  class << self
41
25
  def na_get_pointer_for_read(numo)
@@ -61,6 +45,47 @@ class NDAV
61
45
  ptr.size = numo.byte_size
62
46
  ptr
63
47
  end
48
+
49
+ FORMAT_TO_CLASS = CLASS_TO_FORMAT.invert
50
+ def class_from_format(format)
51
+ item_desc = ITEM_DESCS[format]
52
+ return unless item_desc.length == 1
53
+
54
+ component = item_desc[0]
55
+ return unless component.repeat == 1
56
+
57
+ klass = FORMAT_TO_CLASS[component.format]
58
+ return klass if klass
59
+
60
+ prefix = case component.format
61
+ when "i", "j" then "Int"
62
+ when "I", "J" then "UInt"
63
+ end
64
+ return ::Numo.const_get("#{prefix}#{component.size * 8}") if prefix
65
+
66
+ case IO::Buffer::HOST_ENDIAN
67
+ in IO::Buffer::LITTLE_ENDIAN
68
+ return unless component.little_endian?
69
+
70
+ klass = case component.format
71
+ when "v" then ::Numo::UInt16
72
+ when "V" then ::Numo::UInt32
73
+ when "e" then ::Numo::SFloat
74
+ when "E" then ::Numo::DFloat
75
+ end
76
+ return klass if klass
77
+ in IO::Buffer::BIG_ENDIAN
78
+ return if component.little_endian?
79
+
80
+ klass = case component.format
81
+ when "n" then ::Numo::UInt16
82
+ when "N" then ::Numo::UInt32
83
+ when "g" then ::Numo::SFloat
84
+ when "G" then ::Numo::DFloat
85
+ end
86
+ return klass if klass
87
+ end
88
+ end
64
89
  end
65
90
 
66
91
  module FFI
@@ -78,7 +103,7 @@ class NDAV
78
103
  def from_ndav(ndav)
79
104
  format = ndav.format
80
105
  cls = FORMAT_TO_CLASS[format]
81
- raise ArgumentError, "unsupported format: #{format}, currently supported: #{FORMAT_TO_CLASS.keys}" unless cls
106
+ raise ArgumentError, "unsupported format: #{format}" unless cls
82
107
 
83
108
  shape = ndav.shape
84
109
  if ndav.row_major_contiguous?
@@ -93,7 +118,7 @@ class NDAV
93
118
  end
94
119
 
95
120
  module MemoryViewable
96
- def ndav_descriptor(writable: false, column_major: false, **)
121
+ def ndav_descriptor(writable:, column_major:, **)
97
122
  format = CLASS_TO_FORMAT[self.class]
98
123
  unless format
99
124
  warn "unsupported class: #{self.class}, currently supported: #{CLASS_TO_FORMAT.keys}"
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "ndav-numo-narray"
3
- s.version = "0.0.5"
3
+ s.version = "0.0.6"
4
4
  s.authors = ["Kitaiti Makoto"]
5
5
  s.summary = "N-Dimensional Array View for Numo::NArray"
6
6
  s.licenses = ["BSD-3-Clause"]
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
9
9
  s.files = Dir.chdir(__dir__) {`git ls-files -z`.split("\x0")}
10
10
  s.extensions << "ext/extconf.rb"
11
11
 
12
- s.add_runtime_dependency "ndav", ">= 0.0.6"
12
+ s.add_runtime_dependency "ndav", ">= 0.0.7"
13
13
  s.add_runtime_dependency "numo-narray-alt"
14
14
 
15
15
  s.add_development_dependency "rake"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ndav-numo-narray
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
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: numo-narray-alt
28
28
  requirement: !ruby/object:Gem::Requirement