Module: CArray::DataTypeNewConstructor

Defined in:
lib/carray/construct.rb,
lib/carray/construct.rb

Overview

Constructors added to every typed class (Float64, Int32, ...) so the class itself names the element type. Each forwards to the CArray equivalent with data_type: filled in.

Instance Method Summary collapse

Instance Method Details

#from_memory_view(obj) ⇒ CArray

Returns a fresh CArray interpreted as this typed subclass's data_type, imported by copy from a MemoryView producer. Forwards to CArray.from_memory_view(obj, data_type: self::DataType); the result is always 1-D (chain .reshape for higher rank).

Parameters:

  • obj (Object) —

    MemoryView producer.

Returns:



325
326
327
# File 'lib/carray/construct.rb', line 325

def from_memory_view (obj)
  CArray.from_memory_view(obj, data_type: self::DataType)
end

#new(*shape) ⇒ CArray

Allocates a new CArray of this typed subclass with the given shape.

Parameters:

  • shape (Array<Integer>) —

    shape of the new CArray.

Returns:



313
314
315
# File 'lib/carray/construct.rb', line 313

def new (*shape)
  CArray.new(self::DataType, shape)
end

#wrap_memory_view(obj) ⇒ CAWrap

Returns a zero-copy CAWrap over obj's MemoryView interpreted as this typed subclass's data_type. Forwards to CArray.wrap_memory_view(obj, data_type: self::DataType); the result is always 1-D (chain .reshape for higher rank).

Here the receiver names the element type, not the class of the result: the call forwards with CArray as the receiver, so a CAWrap comes back. Choosing the class is the other reading of the receiver, and it lives on CArray.wrap_memory_view itself.

Parameters:

  • obj (Object) —

    MemoryView producer.

Returns:



341
342
343
# File 'lib/carray/construct.rb', line 341

def wrap_memory_view (obj)
  CArray.wrap_memory_view(obj, data_type: self::DataType)
end