Class: CAMonOp
- Inherits:
-
Object
- Object
- CAMonOp
- Defined in:
- lib/carray/lazy.rb
Overview
CAMonOp / CALazyMarker surface methods.
Materialise-on-first-touch for Enumerable receivers, MV export reject,
inspect/dump_tree summary that does NOT materialise.
Constant Summary collapse
- OP_NAMES =
op_id => :name reverse lookup
CArray::LAZY_MONOP_OP_IDS.invert.freeze
Instance Method Summary collapse
-
#dump_tree(indent = 0) ⇒ String
Returns an ASCII summary of the lazy expression tree.
-
#each({ |value| ... }) {|value| ... } ⇒ Object
Materialises
selfand yields each element of the resulting entity. -
#inspect ⇒ String
Returns a short summary of the lazy chain without materialising.
-
#sort(*args, **kwargs) ⇒ CArray
Materialises
selfinto a copy and returnsentity.sort(*args, **kwargs). -
#to_a ⇒ Array
Materialises
selfand returns the resulting Array. -
#to_memory_view ⇒ void
bulk-memory-view / Numo / Apache Arrow consumers go through the MV protocol, which requires a contiguous backing buffer.
-
#to_s ⇒ String
Alias of #inspect.
Instance Method Details
#dump_tree(indent = 0) ⇒ String
591 592 593 594 595 596 597 598 599 600 |
# File 'lib/carray/lazy.rb', line 591 def dump_tree(indent = 0) pad = " " * indent out = +"#{pad}#{op_label}\n" out << if parent.is_a?(CAMonOp) parent.dump_tree(indent + 1) else "#{" " * (indent + 1)}#{parent.class}(#{parent.data_type_name}, #{parent.shape.inspect})\n" end out end |
#each({ |value| ... }) {|value| ... } ⇒ Object
607 608 609 |
# File 'lib/carray/lazy.rb', line 607 def each(&block) to_ca.each(&block) end |
#inspect ⇒ String
575 576 577 |
# File 'lib/carray/lazy.rb', line 575 def inspect "#<CAMonOp #{op_label}(#{parent.inspect})>" end |
#sort(*args, **kwargs) ⇒ CArray
622 623 624 |
# File 'lib/carray/lazy.rb', line 622 def sort(*args, **kwargs) copy.sort(*args, **kwargs) end |
#to_memory_view ⇒ void
bulk-memory-view / Numo / Apache Arrow consumers go through the MV protocol, which requires a contiguous backing buffer. Lazy views have no backing buffer until materialised; raise with a clear hint.
MemoryView is consulted via to_memory_view_internal on the receiver
in some setups; the safest cross-cutting hook is the to_memory_view
method (defined by carray_memory_view producer). We override to
raise. Importers that probe via rb_memory_view_get will hit the
producer slot, which we DON'T currently override at C-level — but
the MV producer for CAView rejects backing-bufferless views by
default; tests below verify both Ruby-level and C-level reject.
643 644 645 646 647 648 |
# File 'lib/carray/lazy.rb', line 643 def to_memory_view raise TypeError, "lazy view (CAMonOp) has no backing buffer; call `.copy` " \ "first to materialise into an entity before exporting via " \ "MemoryView." end |
#to_s ⇒ String
582 583 584 |
# File 'lib/carray/lazy.rb', line 582 def to_s inspect end |