r_type 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.travis.yml +14 -0
- data/Gemfile +3 -0
- data/Guardfile +9 -0
- data/LICENSE.txt +22 -0
- data/README.md +131 -0
- data/Rakefile +9 -0
- data/bin/r_console +17 -0
- data/lib/r_type.rb +41 -0
- data/lib/r_type/convert.rb +28 -0
- data/lib/r_type/core_ext.rb +30 -0
- data/lib/r_type/core_ext/boolean_delegate_r.rb +8 -0
- data/lib/r_type/core_ext/delegate_checker.rb +11 -0
- data/lib/r_type/core_ext/numeric_delegate_r.rb +20 -0
- data/lib/r_type/helper.rb +4 -0
- data/lib/r_type/helper/matrix_multiply.rb +13 -0
- data/lib/r_type/helper/robj_delegatable.rb +78 -0
- data/lib/r_type/helper/robj_delegatable_class_methods.rb +35 -0
- data/lib/r_type/helper/ruby_compareable.rb +9 -0
- data/lib/r_type/r.rb +50 -0
- data/lib/r_type/type/array.rb +7 -0
- data/lib/r_type/type/base.rb +14 -0
- data/lib/r_type/type/data_frame.rb +7 -0
- data/lib/r_type/type/function.rb +8 -0
- data/lib/r_type/type/integer.rb +7 -0
- data/lib/r_type/type/list.rb +7 -0
- data/lib/r_type/type/matrix.rb +65 -0
- data/lib/r_type/type/numeric.rb +7 -0
- data/lib/r_type/type/string.rb +7 -0
- data/lib/r_type/type/vector.rb +10 -0
- data/lib/r_type/version.rb +3 -0
- data/r_type.gemspec +28 -0
- data/sample/sample1.rb +34 -0
- data/sample/sample2.rb +38 -0
- data/sample/sample3.rb +79 -0
- data/sample/sample4.rb +43 -0
- data/sample/sample5.rb +61 -0
- data/spec/convert_spec.rb +93 -0
- data/spec/core_ext/boolean_delegate_r_spec.rb +39 -0
- data/spec/core_ext/numeric_delegate_r_spec.rb +27 -0
- data/spec/helper/robj_delegatable_spec.rb +68 -0
- data/spec/r_spec.rb +54 -0
- data/spec/spec_helper.rb +34 -0
- data/spec/type/base_spec.rb +52 -0
- data/spec/type/matrix_spec.rb +157 -0
- metadata +196 -0
@@ -0,0 +1,157 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RType::Matrix do
|
4
|
+
let(:matrix) { RType::R.matrix [1, 2, 3, 4], ncol: 2 }
|
5
|
+
let(:vector) { RType::R.c [10, 100] }
|
6
|
+
|
7
|
+
subject { matrix }
|
8
|
+
|
9
|
+
its(:to_ruby) { should == Matrix[[1, 3], [2, 4]] }
|
10
|
+
|
11
|
+
it 'should auto-convert between R and Ruby' do
|
12
|
+
matrix = subject
|
13
|
+
matrix.to_ruby.should == Matrix[[1, 3], [2, 4]]
|
14
|
+
matrix = matrix * 2
|
15
|
+
matrix.to_ruby.should == Matrix[[2, 6], [4, 8]]
|
16
|
+
matrix = matrix + 10
|
17
|
+
matrix.to_ruby.should == Matrix[[12, 16], [14, 18]]
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#multiplication' do
|
21
|
+
context 'robj * robj-matrix' do
|
22
|
+
subject { matrix * matrix }
|
23
|
+
it { should == Matrix.rows([[7, 15], [10, 22]]) }
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'robj * robj-vector' do
|
27
|
+
subject { matrix * vector }
|
28
|
+
it { should == Matrix.rows([[310], [420]]) }
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'robj * ruby-array' do
|
32
|
+
subject { matrix * [100, 10] }
|
33
|
+
it { should == Matrix.rows([[130], [240]]) }
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'ruby-array * robj' do
|
37
|
+
subject { [100, 10] * matrix }
|
38
|
+
it { should == Matrix.rows([[120, 340]]) }
|
39
|
+
end
|
40
|
+
|
41
|
+
context 'robj * ruby-number' do
|
42
|
+
subject { matrix * 10 }
|
43
|
+
it { should == Matrix.rows([[10, 30], [20, 40]]) }
|
44
|
+
end
|
45
|
+
|
46
|
+
context 'ruby-number * robj' do
|
47
|
+
subject { 10 * matrix }
|
48
|
+
it { should == Matrix.rows([[10, 30], [20, 40]]) }
|
49
|
+
end
|
50
|
+
|
51
|
+
context 'robj + ruby-number' do
|
52
|
+
subject { matrix + 10 }
|
53
|
+
it { should == Matrix.rows([[11, 13], [12, 14]]) }
|
54
|
+
end
|
55
|
+
|
56
|
+
context 'ruby-number + robj' do
|
57
|
+
subject { 10 + matrix }
|
58
|
+
it { should == Matrix.rows([[11, 13], [12, 14]]) }
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe '#method_missing' do
|
63
|
+
before do
|
64
|
+
matrix.should_receive(:to_ruby).and_return { double('matrix', hoge: 789) }
|
65
|
+
end
|
66
|
+
|
67
|
+
subject { matrix.hoge }
|
68
|
+
|
69
|
+
it 'delegate to ruby Matrix' do
|
70
|
+
should == 789
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe '#=~' do
|
75
|
+
subject { matrix =~ 3 }
|
76
|
+
|
77
|
+
it 'Matrix[[false, true], [false, false]]' do
|
78
|
+
subject[1, 1].should be_false
|
79
|
+
subject[1, 2].should be_true
|
80
|
+
subject[2, 1].should be_false
|
81
|
+
subject[2, 2].should be_false
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe '#<' do
|
86
|
+
subject { matrix < 4 }
|
87
|
+
|
88
|
+
it 'Matrix[[true, true], [true, false]]' do
|
89
|
+
subject[1, 1].should be_true
|
90
|
+
subject[1, 2].should be_true
|
91
|
+
subject[2, 1].should be_true
|
92
|
+
subject[2, 2].should be_false
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
describe 'ClassMethods' do
|
97
|
+
describe '.I' do
|
98
|
+
subject { RType::Matrix.I 3 }
|
99
|
+
it { should == RType::Matrix[[1,0,0], [0,1,0], [0,0,1]] }
|
100
|
+
end
|
101
|
+
|
102
|
+
describe '.zero' do
|
103
|
+
subject { RType::Matrix.zero 3 }
|
104
|
+
it { should == RType::Matrix[[0,0,0], [0,0,0], [0,0,0]] }
|
105
|
+
end
|
106
|
+
|
107
|
+
describe '.rows' do
|
108
|
+
subject { RType::Matrix.rows [[1,2], [3,4]] }
|
109
|
+
it { should == RType::Matrix[[1,2], [3,4]] }
|
110
|
+
end
|
111
|
+
|
112
|
+
describe '.columns' do
|
113
|
+
subject { RType::Matrix.columns [[1,2], [3,4]] }
|
114
|
+
it { should == RType::Matrix[[1,3], [2,4]] }
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
describe '#[] accessor' do
|
119
|
+
context '[1, 2]' do
|
120
|
+
subject { matrix[1, 2] }
|
121
|
+
it { should == 3 }
|
122
|
+
end
|
123
|
+
|
124
|
+
context '[2, 1]' do
|
125
|
+
subject { matrix[2, 1] }
|
126
|
+
it { should == 2 }
|
127
|
+
end
|
128
|
+
|
129
|
+
context '[nil, 1]' do
|
130
|
+
subject { matrix[nil, 1] }
|
131
|
+
it { should == [1, 2] }
|
132
|
+
end
|
133
|
+
|
134
|
+
context '[2, nil]' do
|
135
|
+
subject { matrix[2, nil] }
|
136
|
+
it { should == [2, 4] }
|
137
|
+
end
|
138
|
+
|
139
|
+
context '[ Matrix[[true, false], [false, true]] ]' do
|
140
|
+
subject { matrix[ RType::Matrix[[true, false], [false, true]] ] }
|
141
|
+
it { should == [1, 4] }
|
142
|
+
end
|
143
|
+
|
144
|
+
context '[ Matrix[[true, false], [false, true]] ] = 10' do
|
145
|
+
before { matrix[ RType::Matrix[[true, false], [false, true]] ] = 10 }
|
146
|
+
subject { matrix }
|
147
|
+
it { should == RType::Matrix[[10, 3], [2, 10]] }
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
describe ::Matrix do
|
153
|
+
subject { ::Matrix.rows [[1,3], [2,4]] }
|
154
|
+
|
155
|
+
its(:as_r) { should == RType::R.matrix([1,2,3,4], ncol: 2) }
|
156
|
+
its('as_r.to_ruby') { should == subject }
|
157
|
+
end
|
metadata
ADDED
@@ -0,0 +1,196 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: r_type
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tatsuya Takamura
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-06-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rsruby
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.5'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
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: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.13.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 2.13.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec-mocks
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 2.13.0
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 2.13.0
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: guard
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ~>
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 1.8.0
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ~>
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 1.8.0
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: guard-rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ~>
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 3.0.1
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ~>
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 3.0.1
|
111
|
+
description: RType is a wrapper library for RSRuby.
|
112
|
+
email:
|
113
|
+
- tkmr2000@gmail.com
|
114
|
+
executables:
|
115
|
+
- r_console
|
116
|
+
extensions: []
|
117
|
+
extra_rdoc_files: []
|
118
|
+
files:
|
119
|
+
- .gitignore
|
120
|
+
- .travis.yml
|
121
|
+
- Gemfile
|
122
|
+
- Guardfile
|
123
|
+
- LICENSE.txt
|
124
|
+
- README.md
|
125
|
+
- Rakefile
|
126
|
+
- bin/r_console
|
127
|
+
- lib/r_type.rb
|
128
|
+
- lib/r_type/convert.rb
|
129
|
+
- lib/r_type/core_ext.rb
|
130
|
+
- lib/r_type/core_ext/boolean_delegate_r.rb
|
131
|
+
- lib/r_type/core_ext/delegate_checker.rb
|
132
|
+
- lib/r_type/core_ext/numeric_delegate_r.rb
|
133
|
+
- lib/r_type/helper.rb
|
134
|
+
- lib/r_type/helper/matrix_multiply.rb
|
135
|
+
- lib/r_type/helper/robj_delegatable.rb
|
136
|
+
- lib/r_type/helper/robj_delegatable_class_methods.rb
|
137
|
+
- lib/r_type/helper/ruby_compareable.rb
|
138
|
+
- lib/r_type/r.rb
|
139
|
+
- lib/r_type/type/array.rb
|
140
|
+
- lib/r_type/type/base.rb
|
141
|
+
- lib/r_type/type/data_frame.rb
|
142
|
+
- lib/r_type/type/function.rb
|
143
|
+
- lib/r_type/type/integer.rb
|
144
|
+
- lib/r_type/type/list.rb
|
145
|
+
- lib/r_type/type/matrix.rb
|
146
|
+
- lib/r_type/type/numeric.rb
|
147
|
+
- lib/r_type/type/string.rb
|
148
|
+
- lib/r_type/type/vector.rb
|
149
|
+
- lib/r_type/version.rb
|
150
|
+
- r_type.gemspec
|
151
|
+
- sample/sample1.rb
|
152
|
+
- sample/sample2.rb
|
153
|
+
- sample/sample3.rb
|
154
|
+
- sample/sample4.rb
|
155
|
+
- sample/sample5.rb
|
156
|
+
- spec/convert_spec.rb
|
157
|
+
- spec/core_ext/boolean_delegate_r_spec.rb
|
158
|
+
- spec/core_ext/numeric_delegate_r_spec.rb
|
159
|
+
- spec/helper/robj_delegatable_spec.rb
|
160
|
+
- spec/r_spec.rb
|
161
|
+
- spec/spec_helper.rb
|
162
|
+
- spec/type/base_spec.rb
|
163
|
+
- spec/type/matrix_spec.rb
|
164
|
+
homepage: https://github.com/ttakamura
|
165
|
+
licenses:
|
166
|
+
- MIT
|
167
|
+
metadata: {}
|
168
|
+
post_install_message:
|
169
|
+
rdoc_options: []
|
170
|
+
require_paths:
|
171
|
+
- lib
|
172
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
173
|
+
requirements:
|
174
|
+
- - '>='
|
175
|
+
- !ruby/object:Gem::Version
|
176
|
+
version: '0'
|
177
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
178
|
+
requirements:
|
179
|
+
- - '>='
|
180
|
+
- !ruby/object:Gem::Version
|
181
|
+
version: '0'
|
182
|
+
requirements: []
|
183
|
+
rubyforge_project:
|
184
|
+
rubygems_version: 2.0.3
|
185
|
+
signing_key:
|
186
|
+
specification_version: 4
|
187
|
+
summary: RType is a wrapper library for RSRuby.
|
188
|
+
test_files:
|
189
|
+
- spec/convert_spec.rb
|
190
|
+
- spec/core_ext/boolean_delegate_r_spec.rb
|
191
|
+
- spec/core_ext/numeric_delegate_r_spec.rb
|
192
|
+
- spec/helper/robj_delegatable_spec.rb
|
193
|
+
- spec/r_spec.rb
|
194
|
+
- spec/spec_helper.rb
|
195
|
+
- spec/type/base_spec.rb
|
196
|
+
- spec/type/matrix_spec.rb
|