Sha256: 3973f04fb3be04e4060fdb2ed2f1c07e1c2523663a2aab7d0848ec2c952f3a43
Contents?: true
Size: 1.31 KB
Versions: 4
Compression:
Stored size: 1.31 KB
Contents
require_relative 'column' class ObjectTable::MaskedColumn < ObjectTable::Column attr_accessor :indices, :parent, :padded_dims def self.mask(parent, indices) if parent.rank > 1 padded_dims = [nil] * (parent.rank - 1) else padded_dims = [] end masked = parent.slice(*padded_dims, indices) if masked.rank <= 0 column = self.new(masked.typecode, 0) else column = self.new(masked.typecode, *masked.shape) column.super_slice_assign(masked) end column.parent = parent column.indices = indices column.padded_dims = padded_dims column end # let ObjectTable::Column do this, since we've overriden []= def self.make(*args) ObjectTable::Column.make(*args) end alias_method :super_slice_assign, :[]= def []=(*keys, value) unless parent.nil? or ((value.is_a?(Array) or value.is_a?(NArray)) and value.empty?) parent[*padded_dims, indices[*keys]] = value end super end # make destructive methods affect parent %w{ fill! indgen! indgen random! map! collect! conj! imag= mod! add! div! sbt! mul! }.each do |op| define_method(op) do |*args, &block| result = super(*args, &block) parent[*padded_dims, indices] = result if parent result end end def clone ObjectTable::Column.cast(self).clone end end
Version data entries
4 entries across 4 versions & 1 rubygems