npy 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +6 -1
  3. data/lib/npy.rb +17 -12
  4. data/lib/npy/version.rb +1 -1
  5. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3d65145c08fd1a4b752d272bfdd1a68495637eabb29092b1adb090f77d32abb2
4
- data.tar.gz: bd7fd9b4bb57ad565dc3a368e1fdeeb23481196838ed5deb84a2dd153f303998
3
+ metadata.gz: 220dfbefca45a554d1a0f673385f832f11539ad1bc3113f285ae91144defe035
4
+ data.tar.gz: 923f706a1ea48ec546c0b94b19fbe0db4ef0351538555f1d20c6ea707b381122
5
5
  SHA512:
6
- metadata.gz: fd14323a074d5aef907ebc3c8457ff5301cd8b612f362901676d2e114668cb2d998e84fa17896a444590ba397337adfc5d761883c82c4a850ac479f1efde8801
7
- data.tar.gz: 61eedeea139e6e0d086f18777becb33b0f0d5272655d401e46241fa215ac9b9f6dacf943e477273b72c9a812415f13fb35727f7bc26cc95508bc2d823aad7070
6
+ metadata.gz: 4ca365c5f2acc98aedeed97d435c6c2e792a90c944affa2c448a2e19eea052a36165b16858e0e4b4314d2f9bf108ece56f8788931a62b31b140c4934dcca4cc3
7
+ data.tar.gz: ec7528bfa28dbb45d22275856e87c362d1a814bfdbb45a8fe41b86e960fafcf5d19af0cebf19dab518c642d32a7bf2c6ed27c8cf62d2d673793f3b75947f264e
@@ -1,8 +1,13 @@
1
+ ## 0.2.0
2
+
3
+ - Added support for loading `bool` type (as `uint8` for now)
4
+ - Return `NArray` object for rank-0 arrays
5
+
1
6
  ## 0.1.2
2
7
 
3
8
  - Added support for saving and loading IO objects
4
9
  - Added `load_npz_string`
5
- - Fixed bug with 1 dimensional arrays
10
+ - Fixed bug with rank-1 arrays
6
11
 
7
12
  ## 0.1.1
8
13
 
data/lib/npy.rb CHANGED
@@ -27,7 +27,10 @@ module Npy
27
27
  "<f4" => Numo::SFloat,
28
28
  "<f8" => Numo::DFloat,
29
29
  "<c8" => Numo::SComplex,
30
- "<c16" => Numo::DComplex
30
+ "<c16" => Numo::DComplex,
31
+ # must come last
32
+ # as save uses first match
33
+ "|b1" => Numo::UInt8
31
34
  }
32
35
 
33
36
  class << self
@@ -85,18 +88,17 @@ module Npy
85
88
  descr, fortran_order, shape = parse_header(header)
86
89
  raise Error, "Fortran order not supported" if fortran_order
87
90
 
88
- # numo can't handle empty shapes
89
- empty_shape = shape.empty?
90
- shape = [1] if empty_shape
91
-
92
91
  klass = TYPE_MAP[descr]
93
92
  raise Error, "Type not supported: #{descr}" unless klass
94
93
 
95
94
  # use from_string instead of from_binary for max compatibility
96
95
  # from_binary introduced in 0.9.0.4
97
- result = klass.from_string(io.read, shape)
98
- result = result[0] if empty_shape
99
- result
96
+ # numo from_string can't handle rank0
97
+ if shape.empty?
98
+ klass.cast(klass.from_string(io.read, [1])[0])
99
+ else
100
+ klass.from_string(io.read, shape)
101
+ end
100
102
  end
101
103
 
102
104
  # TODO make private
@@ -145,9 +147,13 @@ module Npy
145
147
  end
146
148
 
147
149
  def save_io(f, arr)
148
- empty_shape = arr.is_a?(Numeric)
149
- arr = Numo::NArray.cast([arr]) if empty_shape
150
- arr = Numo::NArray.cast(arr) if arr.is_a?(Array)
150
+ unless arr.is_a?(Numo::NArray)
151
+ begin
152
+ arr = Numo::NArray.cast(arr)
153
+ rescue TypeError
154
+ # do nothing
155
+ end
156
+ end
151
157
 
152
158
  # desc
153
159
  descr = TYPE_MAP.find { |_, v| arr.is_a?(v) }
@@ -155,7 +161,6 @@ module Npy
155
161
 
156
162
  # shape
157
163
  shape = arr.shape
158
- shape = [] if empty_shape
159
164
 
160
165
  # header
161
166
  header = "{'descr': '#{descr[0]}', 'fortran_order': False, 'shape': (#{shape.join(", ")}#{shape.size == 1 ? "," : nil}), }".b
@@ -1,3 +1,3 @@
1
1
  module Npy
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: npy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-09-16 00:00:00.000000000 Z
11
+ date: 2019-10-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: numo-narray