Class: CABinOp
- Inherits:
-
Object
- Object
- CABinOp
- Defined in:
- lib/carray/lazy.rb
Overview
Lazy element-wise view of a binary operation on two operands. Nothing is computed until the chain is forced, so a composed expression evaluates in one pass instead of materialising an intermediate per operator.
Produced by an operator on .lazy operands or inside CArray.fuse, not
constructed directly.
Constant Summary collapse
- OP_NAMES =
op_id => :name reverse lookup
CArray::LAZY_BINOP_OP_IDS.invert.merge( OP_IPOWER => :ipow, ).freeze
Instance Method Summary collapse
-
#dump_tree(indent = 0) ⇒ String
Returns an ASCII summary of the lazy expression tree, walking both children.
-
#each({ |value| ... }) ⇒ Object
Materialises
selfand yields each element. -
#inspect ⇒ String
Returns a summary of the binop chain without materialising.
-
#sort(*args, **kwargs) ⇒ CArray
Materialises
selfand sorts the resulting entity. -
#to_a ⇒ Array
Materialises
selfand returns the resulting Array. -
#to_memory_view ⇒ Object
Not supported for lazy binops.
-
#to_s ⇒ String
Alias of #inspect.
Instance Method Details
#dump_tree(indent = 0) ⇒ String
687 688 689 690 691 692 693 694 695 696 697 698 |
# File 'lib/carray/lazy.rb', line 687 def dump_tree(indent = 0) pad = " " * indent out = +"#{pad}#{op_label}\n" [parent, __binop_right__].each do |child| out << if child.is_a?(CAMonOp) || child.is_a?(CABinOp) child.dump_tree(indent + 1) else "#{" " * (indent + 1)}#{child.class}(#{child.data_type_name}, #{child.shape.inspect})\n" end end out end |
#each({ |value| ... }) ⇒ Object
703 704 705 |
# File 'lib/carray/lazy.rb', line 703 def each(&block) to_ca.each(&block) end |
#inspect ⇒ String
672 673 674 |
# File 'lib/carray/lazy.rb', line 672 def inspect "#<CABinOp #{op_label}(#{parent.inspect}, #{__binop_right__.inspect})>" end |
#sort(*args, **kwargs) ⇒ CArray
717 718 719 |
# File 'lib/carray/lazy.rb', line 717 def sort(*args, **kwargs) to_ca.sort(*args, **kwargs) end |
#to_memory_view ⇒ Object
724 725 726 727 728 729 |
# File 'lib/carray/lazy.rb', line 724 def to_memory_view raise TypeError, "lazy view (CABinOp) has no backing buffer; call `.to_ca` " \ "first to materialise into an entity before exporting via " \ "MemoryView." end |
#to_s ⇒ String
679 680 681 |
# File 'lib/carray/lazy.rb', line 679 def to_s inspect end |