numru 0.1.5 → 0.1.6

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
  SHA1:
3
- metadata.gz: 8aa49fdc1a2913c89900e9490e95f91d4a019fdb
4
- data.tar.gz: 7dea6e54ac80ec81c637157b43dbf7d0d87204d7
3
+ metadata.gz: 4f090f8ca0cccf588a98c4618e9a659de7c65e47
4
+ data.tar.gz: 39fc7589265d7e67504e8b56b6dc5f58cf41541b
5
5
  SHA512:
6
- metadata.gz: b5f9b2e5d9c0ef85a8d748e3c53daecc0913ff84a9569cf4b874e33e058e3c7619ee2cb139cacff028f7041bd3768d3359ba9f161d644421f9b7a1e06c36876a
7
- data.tar.gz: 9511612994ef71a501cf2728f818c0f8689e8c9d09d18ee4f6ae4c54e9a8dfe06a6eda795d0141a247d6538ba3dac382e82d4e4c81f2b29e252e54f716a3fbfb
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.4)
5
- rubypython
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
- ## Development
104
+ The motive is not just to build a wrapper for NumPy but to adapt it to Ruby.
57
105
 
58
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
106
+ Rough plan
59
107
 
60
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
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__('__eq__', NumRu.extract_np_obj(arg))
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
- obj = @np_obj.__send__ "#{m}!", *args
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
- obj = @@np.__send__ "#{m}!", *args
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
@@ -1,3 +1,3 @@
1
1
  module Numru
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.6"
3
3
  end
data/numru.gemspec CHANGED
@@ -28,5 +28,5 @@ Gem::Specification.new do |spec|
28
28
  spec.add_development_dependency "rspec", "~> 3.0"
29
29
  spec.add_development_dependency 'pry', '~> 0.11'
30
30
 
31
- spec.add_dependency 'lokeshh_rubypython'
31
+ spec.add_dependency 'lokeshh_rubypython', '~>0.7.1'
32
32
  end
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.5
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-01 00:00:00.000000000 Z
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: '0'
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: '0'
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.8
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