Module: ObjectTable::Column

Defined in:
lib/object_table/column.rb

Class Method Summary collapse

Class Method Details

._stack(columns) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/object_table/column.rb', line 16

def self._stack(columns)
  columns = columns.reject(&:empty?)
  return NArray[] if columns.empty?
  return columns[0].clone if columns.length == 1

  if columns.map{|x| x.shape}.uniq.length == 1
    new_col = NArray.to_na(columns)
    new_col = new_col.reshape(*new_col.shape[0...-2], new_col.shape[-2] * new_col.shape[-1])
    return new_col
  end

  new_rows = columns.map{|x| x.shape[-1]}.reduce(:+)
  first_col = columns.first
  new_col = NArray.new(first_col.typecode, *first_col.shape[0...-1], new_rows)

  columns.reduce(0) do |row, col|
    end_row = row + col.shape[-1]
    new_col[false, row ... end_row] = col
    end_row
  end

  new_col
end

.length_of(array) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/object_table/column.rb', line 5

def self.length_of(array)
  case array
  when Array then array.length
  when NArray then (array.shape.last or 0)
  else nil
  end
end

.stack(*columns) ⇒ Object



14
# File 'lib/object_table/column.rb', line 14

def self.stack(*columns); _stack(columns); end