Class: CAMonOp

Inherits:
Object
  • Object
show all
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

Instance Method Details

#dump_tree(indent = 0) ⇒ String

Returns an ASCII summary of the lazy expression tree. Does not materialise.

Parameters:

  • indent (Integer) (defaults to: 0)

    leading indentation depth.

Returns:

  • (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

Materialises self and yields each element of the resulting entity.

Yield Parameters:

  • value (Object)

Returns:

  • (Object)


607
608
609
# File 'lib/carray/lazy.rb', line 607

def each(&block)
  to_ca.each(&block)
end

#inspectString

Returns a short summary of the lazy chain without materialising.

Returns:

  • (String)


575
576
577
# File 'lib/carray/lazy.rb', line 575

def inspect
  "#<CAMonOp #{op_label}(#{parent.inspect})>"
end

#sort(*args, **kwargs) ⇒ CArray

Materialises self into a copy and returns entity.sort(*args, **kwargs).

Returns:



622
623
624
# File 'lib/carray/lazy.rb', line 622

def sort(*args, **kwargs)
  copy.sort(*args, **kwargs)
end

#to_aArray

Materialises self and returns the resulting Array.

Returns:



614
615
616
# File 'lib/carray/lazy.rb', line 614

def to_a
  to_ca.to_a
end

#to_memory_viewvoid

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.

This method returns an undefined value.

Not supported: a lazy view has no backing buffer.

Raises:

  • (TypeError)

    always; call .copy first.

Raises:

  • (TypeError)


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_sString

Alias of #inspect.

Returns:

  • (String)


582
583
584
# File 'lib/carray/lazy.rb', line 582

def to_s
  inspect
end