daru 0.0.2.3 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.txt +10 -0
- data/README.md +17 -10
- data/Rakefile +5 -0
- data/daru.gemspec +2 -0
- data/lib/daru.rb +1 -1
- data/lib/daru/dataframe.rb +426 -146
- data/lib/daru/dataframe_by_row.rb +15 -0
- data/lib/daru/dataframe_by_vector.rb +15 -0
- data/lib/daru/index.rb +83 -0
- data/lib/daru/io.rb +30 -0
- data/lib/daru/monkeys.rb +18 -10
- data/lib/daru/vector.rb +178 -47
- data/lib/version.rb +1 -1
- data/spec/dataframe_spec.rb +550 -0
- data/spec/fixtures/countries.json +7794 -0
- data/spec/index_spec.rb +54 -0
- data/spec/io_spec.rb +49 -0
- data/spec/monkeys_spec.rb +6 -0
- data/spec/spec_helper.rb +10 -1
- data/spec/vector_spec.rb +155 -0
- metadata +47 -10
- data/spec/jruby/dataframe_spec.rb +0 -1
- data/spec/jruby/vector_spec.rb +0 -20
- data/spec/mri/dataframe_spec.rb +0 -139
- data/spec/mri/vector_spec.rb +0 -104
data/spec/mri/vector_spec.rb
DELETED
@@ -1,104 +0,0 @@
|
|
1
|
-
require 'spec_helper.rb'
|
2
|
-
|
3
|
-
describe Daru::Vector do
|
4
|
-
context "#initialize" do
|
5
|
-
it "creates a vector object with an Array" do
|
6
|
-
vector = Daru::Vector.new [1,2,3,4,5], :mowgli
|
7
|
-
|
8
|
-
expect(vector[1]) .to eq(2)
|
9
|
-
expect(vector.name).to eq(:mowgli)
|
10
|
-
end
|
11
|
-
|
12
|
-
it "creates a vector object with a Range" do
|
13
|
-
vector = Daru::Vector.new 1..5, :bakasur
|
14
|
-
|
15
|
-
expect(vector[1]) .to eq(2)
|
16
|
-
expect(vector.name).to eq(:bakasur)
|
17
|
-
end
|
18
|
-
|
19
|
-
it "creates a vector object with an NMatrix" do
|
20
|
-
vector = Daru::Vector.new(NMatrix.new([5], [1,2,3,4,5],
|
21
|
-
dtype: :int32), :scotty)
|
22
|
-
|
23
|
-
expect(vector[1]) .to eq(2)
|
24
|
-
expect(vector.name).to eq(:scotty)
|
25
|
-
end
|
26
|
-
|
27
|
-
it "creates a vector object with a Matrix" do
|
28
|
-
vector = Daru::Vector.new Matrix[[1,2,3,4,5]], :ravan
|
29
|
-
|
30
|
-
expect(vector[1]) .to eq(2)
|
31
|
-
expect(vector.name).to eq(:ravan)
|
32
|
-
end
|
33
|
-
|
34
|
-
it "creates a vector object with a Hash with different values" do
|
35
|
-
vector = Daru::Vector.new({orion: [1,2,3,4,5]})
|
36
|
-
|
37
|
-
expect(vector[1]) .to eq(2)
|
38
|
-
expect(vector.name).to eq(:orion)
|
39
|
-
|
40
|
-
vector = Daru::Vector.new({ kirk: 1..5 })
|
41
|
-
|
42
|
-
expect(vector[1]) .to eq(2)
|
43
|
-
expect(vector.name).to eq(:kirk)
|
44
|
-
|
45
|
-
vector = Daru::Vector.new({ spock: NMatrix.new([5], [1,2,3,4,5],
|
46
|
-
dtype: :int32) })
|
47
|
-
|
48
|
-
expect(vector[1]) .to eq(2)
|
49
|
-
expect(vector.name).to eq(:spock)
|
50
|
-
end
|
51
|
-
|
52
|
-
it "auto assigns a name if not specified" do
|
53
|
-
earth = Daru::Vector.new 1..5
|
54
|
-
organion = Daru::Vector.new 1..5
|
55
|
-
|
56
|
-
expect(earth.name == organion.name).to eq(false)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
context "tests for methods" do # TODO: Name this better
|
61
|
-
before do
|
62
|
-
@anakin = Daru::Vector.new NMatrix.new([5], [1,2,3,4,5]), :anakin
|
63
|
-
@luke = Daru::Vector.new NMatrix.new([3], [3,4,5,6]) , :luke
|
64
|
-
end
|
65
|
-
|
66
|
-
it "checks for an each block" do
|
67
|
-
sum = 0
|
68
|
-
|
69
|
-
@anakin.each{ |e| sum += e}
|
70
|
-
expect(sum).to eq(15)
|
71
|
-
end
|
72
|
-
|
73
|
-
it "checks for inequality of vectors" do
|
74
|
-
expect(@anakin == @luke).to be(false)
|
75
|
-
end
|
76
|
-
|
77
|
-
it "calculates maximum value" do
|
78
|
-
expect(@anakin.max).to eq(5)
|
79
|
-
end
|
80
|
-
|
81
|
-
it "calculates minimmum value" do
|
82
|
-
expect(@anakin.min).to eq(1)
|
83
|
-
end
|
84
|
-
|
85
|
-
it "delegates to the internal array storage" do
|
86
|
-
expect(@anakin.size).to eq(@anakin.to_a.size)
|
87
|
-
end
|
88
|
-
|
89
|
-
it "assigns on index" do
|
90
|
-
@anakin[0] = 666
|
91
|
-
expect(@anakin[0]).to eq(666)
|
92
|
-
end
|
93
|
-
|
94
|
-
it "returns only the vector object" do
|
95
|
-
expect(@anakin.vector == NMatrix.new([5], [1,2,3,4,5])).to be(true)
|
96
|
-
end
|
97
|
-
|
98
|
-
it "tests for equality" do
|
99
|
-
clone = Daru::Vector.new NMatrix.new([5], [1,2,3,4,5]), :clone
|
100
|
-
|
101
|
-
expect(@anakin == clone).to be(false)
|
102
|
-
end
|
103
|
-
end
|
104
|
-
end if RUBY_ENGINE == 'ruby'
|