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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8b283bc238922ed7b80fc82225cbb758c6a0bf44
4
- data.tar.gz: 144b36aec60ae08d7ef391351dc6ec5e14d4c33c
3
+ metadata.gz: f10d601ed67075300f3995f95c7a1306f88bc5fd
4
+ data.tar.gz: 5f34487c7a30211f6c136a414eb95c7efc117417
5
5
  SHA512:
6
- metadata.gz: 4ae62ff61696c06ab3c4edd2974dc68cd4508de97388a0194d347865c2f617a3cd1694f87f6afdaa6cafd4fadca011e131cebf2f09925e6ea46de959b5eab2ea
7
- data.tar.gz: 38110c1fc518f9d8bc5d0ab4b964eab0a266fb94641ee71c636510bcd1ab710901f9af64c61a677800e4617ac993e74610e69e3eff704079e503d38e499e72ad
6
+ metadata.gz: ec0065ab83ec9d73a40cfab503b573af4ccee8b39909195a6ead7b769716f1bd7ffbb6aea6b8167aecbcf697a867999c8332762c6dcd201628d99b4e5cd48f03
7
+ data.tar.gz: f2d06e95a91c37418b62f96abe5e69d4d5bbadf53ea0a32b7b15d7a243bd620fad6eb23ca1cd129c103613d57cd9fff7b6a284647f1bdc211928d1152452715d
data/.travis.yml CHANGED
@@ -3,3 +3,4 @@ rvm:
3
3
  - 1.9.3
4
4
  - 2.0.0
5
5
  - 2.1.0
6
+ - 2.2.0
@@ -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)
@@ -40,6 +40,7 @@ class ObjectTable::MaskedColumn < NArray
40
40
  end
41
41
 
42
42
  def clone
43
+ return NArray.new(typecode, 0) if empty?
43
44
  NArray.cast(self).clone
44
45
  end
45
46
 
@@ -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)
@@ -1,3 +1,3 @@
1
1
  class ObjectTable
2
- VERSION = "0.3.2"
2
+ VERSION = "0.3.3"
3
3
  end
@@ -19,7 +19,11 @@ class ObjectTable::View
19
19
  end
20
20
 
21
21
  def clone
22
- cols = ObjectTable::BasicGrid[@parent.columns.map{|k, v| [k, v[false, indices]]}]
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.2
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-21 00:00:00.000000000 Z
11
+ date: 2015-03-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: narray