Sha256: 2f1ed403d5b420390cd1b2ca476b854ec8708423b9d264652c57ad31cea6ed44
Contents?: true
Size: 942 Bytes
Versions: 2
Compression:
Stored size: 942 Bytes
Contents
require 'narray' module ObjectTable::Column def self.length_of(array) case array when Array array.length when NArray array.shape.last or 0 else raise "Expected Array or NArray, got #{array}" end end 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 end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
object_table-0.3.4 | lib/object_table/column.rb |
object_table-0.3.3 | lib/object_table/column.rb |