numpy 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '08e0b6b70b4a54e1eeff1046f3cdb8edfb59b2e10718bcfaf739660af0dd9418'
4
- data.tar.gz: 356e3fcf60046142282b71aa11c3fe0976389155a26e65390ed6401b30af6516
3
+ metadata.gz: e1d276c3ad0422a4d70644c598d56cfe5796bbf5afd6454732868f594eedcaef
4
+ data.tar.gz: da4219c7991eb69bc3be277463bd9ece4bebf2b9c1c72d9c49584f308a07b970
5
5
  SHA512:
6
- metadata.gz: 603dbf1b5d7a89a649f4ac074735c4d12ad4af1a565dd7c6ce4e82fa4c927c9059e18b102aaa6e44e2c49a59918c079a894aaf9fc463b521ed4f3a1b6c239eae
7
- data.tar.gz: 9d723c03c0012ea111569b84f8f3d9af4b4a5ebffe09c98e5eec036935d2849140b661112a876f8366a2168267a0690d09fdd00ca09a8db34e24145084240ef2
6
+ metadata.gz: 26702a4ed9e3700743cb64623df90b05f5df6996182fc5bfece2af94532efe339407f6486d52054a750ea75ecd435cc79e01064648e869966b30becadff5ba5c
7
+ data.tar.gz: 5d3ec29e3afb2043fa686806a816d117a1cc266826d949563924850efa5bc0521c728ac7f315933e982c5858c62ed3a6bc48a291a3f06b9a2535e35282cfa028
data/CHANGES.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 0.4.0
2
+
3
+ * Add `Numpy::NDArray#to_narray`
4
+
1
5
  # 0.3.0
2
6
 
3
7
  * Add `Numpy::NDArray#to_a`
data/lib/numpy/ndarray.rb CHANGED
@@ -21,5 +21,53 @@ module Numpy
21
21
  end
22
22
  }
23
23
  end
24
+
25
+ def to_narray
26
+ load_numo_narray
27
+
28
+ # Suppress warning from PyCall
29
+ begin
30
+ save, $VERBOSE = $VERBOSE, nil
31
+ dtype = self.dtype
32
+ ensure
33
+ $VERBOSE = save
34
+ end
35
+
36
+ _, narray_klass = self.class.narray_class_map.find { |dt, kl| dtype == dt }
37
+ unless narray_klass
38
+ raise TypeError,
39
+ "Unable to convert numpy's %p array to Numo::NArray" % dtype
40
+ end
41
+
42
+ # TODO: Use MemoryView feature
43
+ narray_klass[*to_a]
44
+ end
45
+
46
+ def self.narray_class_map
47
+ @narray_class_map ||= [
48
+ [ Numpy.int64 , Numo::Int64 ],
49
+ [ Numpy.int32 , Numo::Int32 ],
50
+ [ Numpy.int16 , Numo::Int16 ],
51
+ [ Numpy.int8 , Numo::Int8 ],
52
+ [ Numpy.uint64 , Numo::Int64 ],
53
+ [ Numpy.uint32 , Numo::Int32 ],
54
+ [ Numpy.uint16 , Numo::Int16 ],
55
+ [ Numpy.uint8 , Numo::Int8 ],
56
+ [ Numpy.bool8 , Numo::UInt8 ],
57
+ [ Numpy.float32 , Numo::SFloat ],
58
+ [ Numpy.float64 , Numo::DFloat ],
59
+ [ Numpy.object , Numo::RObject ]
60
+ ].freeze
61
+ end
62
+
63
+ private def load_numo_narray
64
+ begin
65
+ require "numo/narray"
66
+ rescue LoadError
67
+ raise RuntimeError,
68
+ "Unable to load numo/narray library; " +
69
+ "please do gem install numo-narray before use to_narray method"
70
+ end
71
+ end
24
72
  end
25
73
  end
data/lib/numpy/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Numpy
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
data/numpy.gemspec CHANGED
@@ -26,4 +26,5 @@ Gem::Specification.new do |spec|
26
26
  spec.add_development_dependency "bundler"
27
27
  spec.add_development_dependency "rake"
28
28
  spec.add_development_dependency "test-unit"
29
+ spec.add_development_dependency "numo-narray"
29
30
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: numpy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kenta Murata
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-04-29 00:00:00.000000000 Z
11
+ date: 2021-06-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pycall
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: numo-narray
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  description: Numpy wrapper for Ruby
70
84
  email:
71
85
  - mrkn@mrkn.jp