daru 0.0.3 → 0.0.3.1
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/README.md +269 -13
- data/lib/daru/accessors/array_wrapper.rb +8 -0
- data/lib/daru/accessors/dataframe_by_row.rb +17 -0
- data/lib/daru/accessors/dataframe_by_vector.rb +17 -0
- data/lib/daru/accessors/mdarray_wrapper.rb +9 -0
- data/lib/daru/accessors/nmatrix_wrapper.rb +9 -0
- data/lib/daru/dataframe.rb +59 -20
- data/lib/daru/{io.rb → io/io.rb} +1 -1
- data/lib/daru/math/arithmetic/dataframe.rb +28 -0
- data/lib/daru/math/arithmetic/vector.rb +71 -0
- data/lib/daru/math/statistics/dataframe.rb +10 -0
- data/lib/daru/math/statistics/vector.rb +9 -0
- data/lib/daru/monkeys.rb +5 -5
- data/lib/daru/vector.rb +20 -9
- data/lib/version.rb +1 -1
- data/spec/dataframe_spec.rb +73 -44
- data/spec/{io_spec.rb → io/io_spec.rb} +0 -0
- data/spec/math/arithmetic/dataframe_spec.rb +5 -0
- data/spec/math/arithmetic/vector_spec.rb +51 -0
- data/spec/math/statistics/dataframe_spec.rb +5 -0
- data/spec/math/statistics/vector_spec.rb +12 -0
- data/spec/vector_spec.rb +19 -19
- metadata +22 -7
- data/lib/daru/dataframe_by_row.rb +0 -15
- data/lib/daru/dataframe_by_vector.rb +0 -15
File without changes
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'spec_helper.rb'
|
2
|
+
|
3
|
+
describe Daru::Vector do
|
4
|
+
before :each do
|
5
|
+
@dv1 = Daru::Vector.new [1,2,3,4], name: :boozy, index: [:bud, :kf, :henie, :corona]
|
6
|
+
@dv2 = Daru::Vector.new [1,2,3,4], name: :mayer, index: [:obi, :wan, :kf, :corona]
|
7
|
+
end
|
8
|
+
|
9
|
+
context "#+" do
|
10
|
+
it "adds matching indexes of the other vector" do
|
11
|
+
expect(@dv1 + @dv2).to eq(Daru::Vector.new([5, 8], name: :boozy, index: [:kf, :corona]))
|
12
|
+
end
|
13
|
+
|
14
|
+
it "adds number to each element of the entire vector" do
|
15
|
+
expect(@dv1 + 5).to eq(Daru::Vector.new [6,7,8,9], name: :boozy, index: [:bud, :kf, :henie, :corona])
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context "#-" do
|
20
|
+
it "subtracts matching indexes of the other vector" do
|
21
|
+
expect(@dv1 - @dv2).to eq(Daru::Vector.new([-1,0], name: :boozy, index: [:kf, :corona]))
|
22
|
+
end
|
23
|
+
|
24
|
+
it "subtracts number from each element of the entire vector" do
|
25
|
+
expect(@dv1 - 5).to eq(Daru::Vector.new [-4,-3,-2,-1], name: :boozy, index: [:bud, :kf, :henie, :corona])
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context "#*"
|
30
|
+
it "multiplies matching indexes of the other vector" do
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
it "multiplies number to each element of the entire vector" do
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context "#\/" do
|
40
|
+
it "divides matching indexes of the other vector" do
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
it "divides number from each element of the entire vector" do
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context "#%" do
|
50
|
+
|
51
|
+
end
|
data/spec/vector_spec.rb
CHANGED
@@ -3,7 +3,7 @@ require 'spec_helper.rb'
|
|
3
3
|
describe Daru::Vector do
|
4
4
|
context "#initialize" do
|
5
5
|
it "initializes from an Array" do
|
6
|
-
dv = Daru::Vector.new
|
6
|
+
dv = Daru::Vector.new [1,2,3,4,5], name: :ravan, index: [:ek, :don, :teen, :char, :pach]
|
7
7
|
|
8
8
|
expect(dv.name) .to eq(:ravan)
|
9
9
|
expect(dv.index).to eq(Daru::Index.new [:ek, :don, :teen, :char, :pach])
|
@@ -12,7 +12,7 @@ describe Daru::Vector do
|
|
12
12
|
it "accepts Index object" do
|
13
13
|
idx = Daru::Index.new [:yoda, :anakin, :obi, :padme, :r2d2]
|
14
14
|
|
15
|
-
dv = Daru::Vector.new
|
15
|
+
dv = Daru::Vector.new [1,2,3,4,5], name: :yoga, index: idx
|
16
16
|
|
17
17
|
expect(dv.name) .to eq(:yoga)
|
18
18
|
expect(dv.index).to eq(idx)
|
@@ -20,23 +20,23 @@ describe Daru::Vector do
|
|
20
20
|
|
21
21
|
it "raises error for improper Index" do
|
22
22
|
expect {
|
23
|
-
dv = Daru::Vector.new
|
23
|
+
dv = Daru::Vector.new [1,2,3,4,5], name: :yoga, index: [:i, :j, :k]
|
24
24
|
}.to raise_error
|
25
25
|
|
26
26
|
expect {
|
27
27
|
idx = Daru::Index.new [:i, :j, :k]
|
28
|
-
dv = Daru::Vector.new
|
28
|
+
dv = Daru::Vector.new [1,2,3,4,5], name: :yoda, index: idx
|
29
29
|
}.to raise_error
|
30
30
|
end
|
31
31
|
|
32
32
|
it "initializes without specifying an index" do
|
33
|
-
dv = Daru::Vector.new
|
33
|
+
dv = Daru::Vector.new [1,2,3,4,5], name: :vishnu
|
34
34
|
|
35
35
|
expect(dv.index).to eq(Daru::Index.new [0,1,2,3,4])
|
36
36
|
end
|
37
37
|
|
38
38
|
it "inserts nils for extra indices" do
|
39
|
-
dv = Daru::Vector.new
|
39
|
+
dv = Daru::Vector.new [1,2,3], name: :yoga, index: [0,1,2,3,4]
|
40
40
|
|
41
41
|
expect(dv).to eq([1,2,3,nil,nil].dv(:yoga))
|
42
42
|
end
|
@@ -44,7 +44,7 @@ describe Daru::Vector do
|
|
44
44
|
|
45
45
|
context "#[]" do
|
46
46
|
before :each do
|
47
|
-
@dv = Daru::Vector.new
|
47
|
+
@dv = Daru::Vector.new [1,2,3,4,5], name: :yoga, index: [:yoda, :anakin, :obi, :padme, :r2d2]
|
48
48
|
end
|
49
49
|
|
50
50
|
it "returns an element after passing an index" do
|
@@ -56,14 +56,14 @@ describe Daru::Vector do
|
|
56
56
|
end
|
57
57
|
|
58
58
|
it "returns a vector with given indices for multiple indices" do
|
59
|
-
expect(@dv[:yoda, :anakin]).to eq(Daru::Vector.new(
|
60
|
-
[:yoda, :anakin]))
|
59
|
+
expect(@dv[:yoda, :anakin]).to eq(Daru::Vector.new([1,2], name: :yoda,
|
60
|
+
index: [:yoda, :anakin]))
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
64
64
|
context "#[]=" do
|
65
65
|
before :each do
|
66
|
-
@dv = Daru::Vector.new
|
66
|
+
@dv = Daru::Vector.new [1,2,3,4,5], name: :yoga, index: [:yoda, :anakin, :obi, :padme, :r2d2]
|
67
67
|
end
|
68
68
|
|
69
69
|
it "assigns at the specified index" do
|
@@ -81,7 +81,7 @@ describe Daru::Vector do
|
|
81
81
|
|
82
82
|
context "#concat" do
|
83
83
|
before :each do
|
84
|
-
@dv = Daru::Vector.new
|
84
|
+
@dv = Daru::Vector.new [1,2,3,4,5], name: :yoga, index: [:warwick, :thompson, :jackson, :fender, :esp]
|
85
85
|
end
|
86
86
|
|
87
87
|
it "concatenates a new element at the end of vector with index" do
|
@@ -94,7 +94,7 @@ describe Daru::Vector do
|
|
94
94
|
end
|
95
95
|
|
96
96
|
it "concatenates without index if index is default numeric" do
|
97
|
-
vector = Daru::Vector.new
|
97
|
+
vector = Daru::Vector.new [1,2,3,4,5], name: :nums
|
98
98
|
|
99
99
|
vector.concat 6
|
100
100
|
|
@@ -111,35 +111,35 @@ describe Daru::Vector do
|
|
111
111
|
|
112
112
|
context "#delete" do
|
113
113
|
it "deletes specified value in the vector" do
|
114
|
-
dv = Daru::Vector.new
|
114
|
+
dv = Daru::Vector.new [1,2,3,4,5], name: :a
|
115
115
|
|
116
116
|
dv.delete 3
|
117
117
|
|
118
|
-
expect(dv).to eq(Daru::Vector.new
|
118
|
+
expect(dv).to eq(Daru::Vector.new [1,2,4,5], name: :a)
|
119
119
|
end
|
120
120
|
end
|
121
121
|
|
122
122
|
context "#delete_at" do
|
123
123
|
before :each do
|
124
|
-
@dv = Daru::Vector.new
|
124
|
+
@dv = Daru::Vector.new [1,2,3,4,5], name: :a, index: [:one, :two, :three, :four, :five]
|
125
125
|
end
|
126
126
|
|
127
127
|
it "deletes element of specified index" do
|
128
128
|
@dv.delete_at :one
|
129
129
|
|
130
|
-
expect(@dv).to eq(Daru::Vector.new
|
130
|
+
expect(@dv).to eq(Daru::Vector.new [2,3,4,5], name: :a, index: [:two, :three, :four, :five])
|
131
131
|
end
|
132
132
|
|
133
133
|
it "deletes element of specified integer index" do
|
134
134
|
@dv.delete_at 2
|
135
135
|
|
136
|
-
expect(@dv).to eq(Daru::Vector.new
|
136
|
+
expect(@dv).to eq(Daru::Vector.new [1,2,4,5], name: :a, index: [:one, :two, :four, :five])
|
137
137
|
end
|
138
138
|
end
|
139
139
|
|
140
140
|
context "#index_of" do
|
141
141
|
it "returns index of specified value" do
|
142
|
-
dv = Daru::Vector.new
|
142
|
+
dv = Daru::Vector.new [1,2,3,4,5], name: :a, index: [:one, :two, :three, :four, :five]
|
143
143
|
|
144
144
|
expect(dv.index_of(1)).to eq(:one)
|
145
145
|
end
|
@@ -147,7 +147,7 @@ describe Daru::Vector do
|
|
147
147
|
|
148
148
|
context "#to_hash" do
|
149
149
|
it "returns the vector as a hash" do
|
150
|
-
dv = Daru::Vector.new
|
150
|
+
dv = Daru::Vector.new [1,2,3,4,5], name: :a, index: [:one, :two, :three, :four, :five]
|
151
151
|
|
152
152
|
expect(dv.to_hash).to eq({one: 1, two: 2, three: 3, four: 4, five: 5})
|
153
153
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: daru
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.3
|
4
|
+
version: 0.0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sameer Deshmukh
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-11-
|
11
|
+
date: 2014-11-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -100,11 +100,18 @@ files:
|
|
100
100
|
- Rakefile
|
101
101
|
- daru.gemspec
|
102
102
|
- lib/daru.rb
|
103
|
+
- lib/daru/accessors/array_wrapper.rb
|
104
|
+
- lib/daru/accessors/dataframe_by_row.rb
|
105
|
+
- lib/daru/accessors/dataframe_by_vector.rb
|
106
|
+
- lib/daru/accessors/mdarray_wrapper.rb
|
107
|
+
- lib/daru/accessors/nmatrix_wrapper.rb
|
103
108
|
- lib/daru/dataframe.rb
|
104
|
-
- lib/daru/dataframe_by_row.rb
|
105
|
-
- lib/daru/dataframe_by_vector.rb
|
106
109
|
- lib/daru/index.rb
|
107
|
-
- lib/daru/io.rb
|
110
|
+
- lib/daru/io/io.rb
|
111
|
+
- lib/daru/math/arithmetic/dataframe.rb
|
112
|
+
- lib/daru/math/arithmetic/vector.rb
|
113
|
+
- lib/daru/math/statistics/dataframe.rb
|
114
|
+
- lib/daru/math/statistics/vector.rb
|
108
115
|
- lib/daru/monkeys.rb
|
109
116
|
- lib/daru/vector.rb
|
110
117
|
- lib/version.rb
|
@@ -112,7 +119,11 @@ files:
|
|
112
119
|
- spec/fixtures/countries.json
|
113
120
|
- spec/fixtures/matrix_test.csv
|
114
121
|
- spec/index_spec.rb
|
115
|
-
- spec/io_spec.rb
|
122
|
+
- spec/io/io_spec.rb
|
123
|
+
- spec/math/arithmetic/dataframe_spec.rb
|
124
|
+
- spec/math/arithmetic/vector_spec.rb
|
125
|
+
- spec/math/statistics/dataframe_spec.rb
|
126
|
+
- spec/math/statistics/vector_spec.rb
|
116
127
|
- spec/monkeys_spec.rb
|
117
128
|
- spec/spec_helper.rb
|
118
129
|
- spec/vector_spec.rb
|
@@ -145,7 +156,11 @@ test_files:
|
|
145
156
|
- spec/fixtures/countries.json
|
146
157
|
- spec/fixtures/matrix_test.csv
|
147
158
|
- spec/index_spec.rb
|
148
|
-
- spec/io_spec.rb
|
159
|
+
- spec/io/io_spec.rb
|
160
|
+
- spec/math/arithmetic/dataframe_spec.rb
|
161
|
+
- spec/math/arithmetic/vector_spec.rb
|
162
|
+
- spec/math/statistics/dataframe_spec.rb
|
163
|
+
- spec/math/statistics/vector_spec.rb
|
149
164
|
- spec/monkeys_spec.rb
|
150
165
|
- spec/spec_helper.rb
|
151
166
|
- spec/vector_spec.rb
|