npy 0.1.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -4
- data/LICENSE.txt +1 -1
- data/README.md +11 -2
- data/lib/npy/version.rb +1 -1
- data/lib/npy.rb +17 -12
- metadata +11 -67
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6d5637c2e20e478c9f1855df76759468e46e21249b1fd0e3b080eef78c350edf
|
4
|
+
data.tar.gz: 5eb0e7e49204b260cbbb3b973fc4b8875c048e2b18092978506056ee3f7c1ea6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0a532bd08dede3cbe8a77b9acd72e0befba09886c5fdc497caa2a1a04c1f2e2f2e8f3b2e38f7952d54b0cfbd77861c65eaea5911f50905e885960fae03c0fca4
|
7
|
+
data.tar.gz: 3e266ffe7ab3f63faa5b9abf1a9106cb24bc03d934e15681f17be5c924f7a26939e5af91ca52e5cc52b75ba46923ea631cf3f73dd0743580f571f0d5085a49a5
|
data/CHANGELOG.md
CHANGED
@@ -1,15 +1,24 @@
|
|
1
|
-
## 0.
|
1
|
+
## 0.3.0 (2022-09-27)
|
2
|
+
|
3
|
+
- Dropped support for Ruby < 2.7
|
4
|
+
|
5
|
+
## 0.2.0 (2019-10-27)
|
6
|
+
|
7
|
+
- Added support for loading `bool` type (as `uint8` for now)
|
8
|
+
- Return `NArray` object for rank-0 arrays
|
9
|
+
|
10
|
+
## 0.1.2 (2019-09-15)
|
2
11
|
|
3
12
|
- Added support for saving and loading IO objects
|
4
13
|
- Added `load_npz_string`
|
5
|
-
- Fixed bug with 1
|
14
|
+
- Fixed bug with rank-1 arrays
|
6
15
|
|
7
|
-
## 0.1.1
|
16
|
+
## 0.1.1 (2019-09-14)
|
8
17
|
|
9
18
|
- Added support for saving files
|
10
19
|
- Added support for npy version 2.0 and 3.0
|
11
20
|
- Fixed error with empty shapes
|
12
21
|
|
13
|
-
## 0.1.0
|
22
|
+
## 0.1.0 (2019-09-12)
|
14
23
|
|
15
24
|
- First release
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -4,14 +4,14 @@ Save and load NumPy `npy` and `npz` files in Ruby - no Python required
|
|
4
4
|
|
5
5
|
:fire: Uses [Numo](https://github.com/ruby-numo/numo-narray) for blazing performance
|
6
6
|
|
7
|
-
[![Build Status](https://
|
7
|
+
[![Build Status](https://github.com/ankane/npy/workflows/build/badge.svg?branch=master)](https://github.com/ankane/npy/actions)
|
8
8
|
|
9
9
|
## Installation
|
10
10
|
|
11
11
|
Add this line to your application’s Gemfile:
|
12
12
|
|
13
13
|
```ruby
|
14
|
-
gem
|
14
|
+
gem "npy"
|
15
15
|
```
|
16
16
|
|
17
17
|
## Getting Started
|
@@ -90,3 +90,12 @@ Everyone is encouraged to help improve this project. Here are a few ways you can
|
|
90
90
|
- Fix bugs and [submit pull requests](https://github.com/ankane/npy/pulls)
|
91
91
|
- Write, clarify, or fix documentation
|
92
92
|
- Suggest or add new features
|
93
|
+
|
94
|
+
To get started with development:
|
95
|
+
|
96
|
+
```sh
|
97
|
+
git clone https://github.com/ankane/npy.git
|
98
|
+
cd npy
|
99
|
+
bundle install
|
100
|
+
bundle exec rake test
|
101
|
+
```
|
data/lib/npy/version.rb
CHANGED
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
|
-
|
98
|
-
|
99
|
-
|
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
|
-
|
149
|
-
|
150
|
-
|
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
|
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.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kane
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-09-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: numo-narray
|
@@ -30,72 +30,16 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '2.3'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
41
|
-
|
42
|
-
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ">="
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: rake
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: minitest
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - ">="
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '5'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - ">="
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '5'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: benchmark-ips
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - ">="
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '0'
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - ">="
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '0'
|
97
|
-
description:
|
98
|
-
email: andrew@chartkick.com
|
40
|
+
version: '2.3'
|
41
|
+
description:
|
42
|
+
email: andrew@ankane.org
|
99
43
|
executables: []
|
100
44
|
extensions: []
|
101
45
|
extra_rdoc_files: []
|
@@ -110,7 +54,7 @@ homepage: https://github.com/ankane/npy
|
|
110
54
|
licenses:
|
111
55
|
- MIT
|
112
56
|
metadata: {}
|
113
|
-
post_install_message:
|
57
|
+
post_install_message:
|
114
58
|
rdoc_options: []
|
115
59
|
require_paths:
|
116
60
|
- lib
|
@@ -118,15 +62,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
118
62
|
requirements:
|
119
63
|
- - ">="
|
120
64
|
- !ruby/object:Gem::Version
|
121
|
-
version: '2.
|
65
|
+
version: '2.7'
|
122
66
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
67
|
requirements:
|
124
68
|
- - ">="
|
125
69
|
- !ruby/object:Gem::Version
|
126
70
|
version: '0'
|
127
71
|
requirements: []
|
128
|
-
rubygems_version: 3.
|
129
|
-
signing_key:
|
72
|
+
rubygems_version: 3.3.7
|
73
|
+
signing_key:
|
130
74
|
specification_version: 4
|
131
75
|
summary: Save and load NumPy npy and npz files in Ruby
|
132
76
|
test_files: []
|