object_table 0.3.2 → 0.3.3
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/.travis.yml +1 -0
- data/lib/object_table/column.rb +7 -0
- data/lib/object_table/masked_column.rb +1 -0
- data/lib/object_table/stacker.rb +0 -4
- data/lib/object_table/version.rb +1 -1
- data/lib/object_table/view.rb +5 -1
- data/spec/object_table/column_spec.rb +18 -0
- data/spec/object_table/masked_column_spec.rb +16 -0
- data/spec/support/view_example.rb +25 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f10d601ed67075300f3995f95c7a1306f88bc5fd
|
4
|
+
data.tar.gz: 5f34487c7a30211f6c136a414eb95c7efc117417
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec0065ab83ec9d73a40cfab503b573af4ccee8b39909195a6ead7b769716f1bd7ffbb6aea6b8167aecbcf697a867999c8332762c6dcd201628d99b4e5cd48f03
|
7
|
+
data.tar.gz: f2d06e95a91c37418b62f96abe5e69d4d5bbadf53ea0a32b7b15d7a243bd620fad6eb23ca1cd129c103613d57cd9fff7b6a284647f1bdc211928d1152452715d
|
data/.travis.yml
CHANGED
data/lib/object_table/column.rb
CHANGED
@@ -13,11 +13,18 @@ module ObjectTable::Column
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
+
|
16
17
|
def self.stack(*columns)
|
17
18
|
columns = columns.reject(&:empty?)
|
18
19
|
return NArray[] if columns.empty?
|
19
20
|
return columns[0].clone if columns.length == 1
|
20
21
|
|
22
|
+
if columns.map{|x| x.shape}.uniq.length == 1
|
23
|
+
new_col = NArray.to_na(columns)
|
24
|
+
new_col = new_col.reshape(*new_col.shape[0...-2], new_col.shape[-2] * new_col.shape[-1])
|
25
|
+
return new_col
|
26
|
+
end
|
27
|
+
|
21
28
|
new_rows = columns.map{|x| x.shape[-1]}.reduce(:+)
|
22
29
|
first_col = columns.first
|
23
30
|
new_col = NArray.new(first_col.typecode, *first_col.shape[0...-1], new_rows)
|
data/lib/object_table/stacker.rb
CHANGED
@@ -28,10 +28,6 @@ module ObjectTable::Stacker
|
|
28
28
|
if segments.all?{|seg| seg.is_a? Array}
|
29
29
|
column = NArray.to_na(segments.flatten(1))
|
30
30
|
|
31
|
-
elsif segments.all?{|seg| seg.is_a? NArray} and segments.map{|seg| seg.shape}.uniq.length == 1
|
32
|
-
column = NArray.to_na(segments)
|
33
|
-
column = column.reshape(*column.shape[0...-2], column.shape[-2] * column.shape[-1])
|
34
|
-
|
35
31
|
else
|
36
32
|
segments.map!{|seg| NArray.to_na seg}
|
37
33
|
column = ObjectTable::Column.stack(*segments)
|
data/lib/object_table/version.rb
CHANGED
data/lib/object_table/view.rb
CHANGED
@@ -19,7 +19,11 @@ class ObjectTable::View
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def clone
|
22
|
-
|
22
|
+
if nrows == 0
|
23
|
+
cols = @parent.columns.map{|k, v| [k, NArray.new(v.typecode, 0)]}
|
24
|
+
else
|
25
|
+
cols = @parent.columns.map{|k, v| [k, v[false, indices]]}
|
26
|
+
end
|
23
27
|
__table_cls__.new(cols)
|
24
28
|
end
|
25
29
|
|
@@ -70,6 +70,24 @@ describe ObjectTable::Column do
|
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
73
|
+
context 'when arguments all have the same dimensions' do
|
74
|
+
let(:columns) do
|
75
|
+
[
|
76
|
+
NArray.float(10, 20, 30).random!,
|
77
|
+
NArray.float(10, 20, 30).random!,
|
78
|
+
NArray.float(10, 20, 30).random!,
|
79
|
+
NArray.float(10, 20, 30).random!,
|
80
|
+
]
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'should stack them' do
|
84
|
+
expect(subject[false, 0...30]).to eq columns[0]
|
85
|
+
expect(subject[false, 30...60]).to eq columns[1]
|
86
|
+
expect(subject[false, 60...90]).to eq columns[2]
|
87
|
+
expect(subject[false, 90...120]).to eq columns[3]
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
73
91
|
end
|
74
92
|
|
75
93
|
end
|
@@ -169,6 +169,22 @@ describe ObjectTable::MaskedColumn do
|
|
169
169
|
it 'should clone the data' do
|
170
170
|
expect(clone.to_a).to eql subject.to_a
|
171
171
|
end
|
172
|
+
|
173
|
+
context 'with an empty mask' do
|
174
|
+
let(:indices) { NArray[] }
|
175
|
+
|
176
|
+
it 'should clone the data' do
|
177
|
+
expect(clone.to_a).to eql subject.to_a
|
178
|
+
end
|
179
|
+
|
180
|
+
context 'with an empty parent' do
|
181
|
+
let(:parent) { NArray[] }
|
182
|
+
|
183
|
+
it 'should clone the data' do
|
184
|
+
expect(clone.to_a).to eql subject.to_a
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
172
188
|
end
|
173
189
|
|
174
190
|
describe 'operations' do
|
@@ -242,6 +242,31 @@ RSpec.shared_examples 'a table view' do |cls|
|
|
242
242
|
expect(v).to_not be_a ObjectTable::MaskedColumn
|
243
243
|
end
|
244
244
|
end
|
245
|
+
|
246
|
+
context 'with an empty view' do
|
247
|
+
let(:block) { Proc.new{col1 > col1.max} }
|
248
|
+
|
249
|
+
it 'should clone the view' do
|
250
|
+
expect(clone).to eql subject
|
251
|
+
clone.columns.each do |k, v|
|
252
|
+
expect(v).to be_a NArray
|
253
|
+
expect(v).to_not be_a ObjectTable::MaskedColumn
|
254
|
+
end
|
255
|
+
end
|
256
|
+
|
257
|
+
context 'with an empty parent' do
|
258
|
+
let(:table) { ObjectTable.new(col1: [], col2: []) }
|
259
|
+
|
260
|
+
it 'should clone the view' do
|
261
|
+
expect(clone).to eql subject
|
262
|
+
clone.columns.each do |k, v|
|
263
|
+
expect(v).to be_a NArray
|
264
|
+
expect(v).to_not be_a ObjectTable::MaskedColumn
|
265
|
+
end
|
266
|
+
end
|
267
|
+
end
|
268
|
+
end
|
269
|
+
|
245
270
|
end
|
246
271
|
|
247
272
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: object_table
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cheney Lin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: narray
|