numru 0.1.5 → 0.1.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 +4 -4
- data/Gemfile.lock +5 -5
- data/README.md +54 -4
- data/lib/numru.rb +5 -11
- data/lib/numru/version.rb +1 -1
- data/numru.gemspec +1 -1
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4f090f8ca0cccf588a98c4618e9a659de7c65e47
|
4
|
+
data.tar.gz: 39fc7589265d7e67504e8b56b6dc5f58cf41541b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5f62e96260fdfa4eaaf393f484dc1220467f3a2ffef6ef637523f1790ff235d1410bbf1d636270aea0a120716d364278aac10ead4d41bd784250053f652ff22f
|
7
|
+
data.tar.gz: 1e18e3062466782e414cd4a6bfa6fbf30dc5adca629a769be0fef64ed44ed9c41dec5f2ddc9839eea063c10949da5c0c8307bbe13ebcb1f14c5282a1b47590d5
|
data/Gemfile.lock
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
numru (0.1.
|
5
|
-
|
4
|
+
numru (0.1.5)
|
5
|
+
lokeshh_rubypython (~> 0.7.1)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
@@ -11,6 +11,9 @@ GEM
|
|
11
11
|
coderay (1.1.2)
|
12
12
|
diff-lcs (1.3)
|
13
13
|
ffi (1.0.11)
|
14
|
+
lokeshh_rubypython (0.7.1)
|
15
|
+
blankslate (>= 2.1.2.3)
|
16
|
+
ffi (~> 1.0.7)
|
14
17
|
method_source (0.9.0)
|
15
18
|
pry (0.11.3)
|
16
19
|
coderay (~> 1.1.0)
|
@@ -29,9 +32,6 @@ GEM
|
|
29
32
|
diff-lcs (>= 1.2.0, < 2.0)
|
30
33
|
rspec-support (~> 3.7.0)
|
31
34
|
rspec-support (3.7.1)
|
32
|
-
rubypython (0.6.4)
|
33
|
-
blankslate (>= 2.1.2.3)
|
34
|
-
ffi (~> 1.0.7)
|
35
35
|
|
36
36
|
PLATFORMS
|
37
37
|
ruby
|
data/README.md
CHANGED
@@ -46,18 +46,68 @@ nr = NumRu
|
|
46
46
|
[24, 25, 26]]])
|
47
47
|
|
48
48
|
```
|
49
|
-
Keyword arguments are not supported. For that use hash.
|
49
|
+
2. Keyword arguments are not supported. For that use hash instead.
|
50
50
|
```rb
|
51
51
|
> x = nr.array [1, 2, 3], dtype: :complex
|
52
52
|
=> array([1.+0.j, 2.+0.j, 3.+0.j])
|
53
53
|
|
54
|
+
> x = nr.array [1, 2, 3], dtype: nr.int32
|
55
|
+
=> array([1, 2, 3], dtype=int32)
|
54
56
|
```
|
57
|
+
3. Indexing is similar to numpy except it use Ruby Range instead of Python Slice
|
58
|
+
```rb
|
59
|
+
> x = nr.array(20.times.map { |i| i**2 }).reshape 4, 5
|
60
|
+
=> array([[ 0, 1, 4, 9, 16],
|
61
|
+
[ 25, 36, 49, 64, 81],
|
62
|
+
[100, 121, 144, 169, 196],
|
63
|
+
[225, 256, 289, 324, 361]])
|
64
|
+
> x[0]
|
65
|
+
=> array([[ 0, 1, 4, 9, 16]])
|
66
|
+
> x[[0, 1]]
|
67
|
+
=> array([[ 0, 1, 4, 9, 16],
|
68
|
+
[25, 36, 49, 64, 81]])
|
69
|
+
> x[0..1]
|
70
|
+
=> array([[ 0, 1, 4, 9, 16],
|
71
|
+
[25, 36, 49, 64, 81]])
|
72
|
+
> x[0..-1, -1]
|
73
|
+
=> array([ 16, 81, 196, 361])
|
74
|
+
> x[0..-1, -2..-1]
|
75
|
+
=> array([[ 9, 16],
|
76
|
+
[ 64, 81],
|
77
|
+
[169, 196],
|
78
|
+
[324, 361]])
|
79
|
+
|
80
|
+
```
|
81
|
+
4. Slicing is supported too but it has to be wrapped inside quotes
|
82
|
+
```rb
|
83
|
+
> x = nr.arange(25).reshape(5, 5).T
|
84
|
+
=> array([[ 0, 5, 10, 15, 20],
|
85
|
+
[ 1, 6, 11, 16, 21],
|
86
|
+
[ 2, 7, 12, 17, 22],
|
87
|
+
[ 3, 8, 13, 18, 23],
|
88
|
+
[ 4, 9, 14, 19, 24]])
|
89
|
+
> x['::', '::-1']
|
90
|
+
=> array([[20, 15, 10, 5, 0],
|
91
|
+
[21, 16, 11, 6, 1],
|
92
|
+
[22, 17, 12, 7, 2],
|
93
|
+
[23, 18, 13, 8, 3],
|
94
|
+
[24, 19, 14, 9, 4]])
|
95
|
+
> x[':3', ':3']
|
96
|
+
=> array([[ 0, 5, 10],
|
97
|
+
[ 1, 6, 11],
|
98
|
+
[ 2, 7, 12]])
|
99
|
+
|
100
|
+
```
|
101
|
+
|
102
|
+
## In development
|
55
103
|
|
56
|
-
|
104
|
+
The motive is not just to build a wrapper for NumPy but to adapt it to Ruby.
|
57
105
|
|
58
|
-
|
106
|
+
Rough plan
|
59
107
|
|
60
|
-
|
108
|
+
1. Provide all numpy functionality
|
109
|
+
2. Provide `map`, `each`, etc.
|
110
|
+
3. TODO: Think and discuss how to rubify the API
|
61
111
|
|
62
112
|
## Contributing
|
63
113
|
|
data/lib/numru.rb
CHANGED
@@ -70,15 +70,7 @@ class NumRu
|
|
70
70
|
end
|
71
71
|
|
72
72
|
def ==(arg)
|
73
|
-
@np_obj.__send__('
|
74
|
-
end
|
75
|
-
|
76
|
-
def < arg
|
77
|
-
@np_obj.__send__('__lt__', NumRu.extract_np_obj(arg))
|
78
|
-
end
|
79
|
-
|
80
|
-
def > arg
|
81
|
-
@np_obj.__send__('__gt__', NumRu.extract_np_obj(arg))
|
73
|
+
@np_obj.__send__('==', NumRu.preprocess_arg(arg))
|
82
74
|
end
|
83
75
|
|
84
76
|
def self.arg_to_s arg
|
@@ -93,13 +85,15 @@ class NumRu
|
|
93
85
|
|
94
86
|
def method_missing(m, *args)
|
95
87
|
args.map! { |i| NumRu.preprocess_arg i }
|
96
|
-
|
88
|
+
m = "#{m}!" if args.any? { |i| i.respond_to?(:class) && i.class == Hash }
|
89
|
+
obj = @np_obj.__send__ m, *args
|
97
90
|
NumRu.return_or_wrap obj
|
98
91
|
end
|
99
92
|
|
100
93
|
def self.method_missing(m, *args)
|
101
94
|
args.map! { |i| NumRu.preprocess_arg i }
|
102
|
-
|
95
|
+
m = "#{m}!" if args.any? { |i| i.respond_to?(:class) && i.class == Hash }
|
96
|
+
obj = @@np.__send__ m, *args
|
103
97
|
return_or_wrap obj
|
104
98
|
end
|
105
99
|
|
data/lib/numru/version.rb
CHANGED
data/numru.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: numru
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- lokeshh
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-03-
|
11
|
+
date: 2018-03-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -70,16 +70,16 @@ dependencies:
|
|
70
70
|
name: lokeshh_rubypython
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
75
|
+
version: 0.7.1
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - "
|
80
|
+
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
82
|
+
version: 0.7.1
|
83
83
|
description:
|
84
84
|
email:
|
85
85
|
- lokeshhsharma@gmail.com
|
@@ -120,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
120
120
|
version: '0'
|
121
121
|
requirements: []
|
122
122
|
rubyforge_project:
|
123
|
-
rubygems_version: 2.6.
|
123
|
+
rubygems_version: 2.6.14
|
124
124
|
signing_key:
|
125
125
|
specification_version: 4
|
126
126
|
summary: This gem is equivalent of NumPy in Python
|