Module: CArray::DataTypeNewConstructor

Included in:
Boolean, Complex128, Complex64, Fixlen, Float32, Float64, Int16, Int32, Int64, Int8, Object, UInt16, UInt32, UInt64, UInt8
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:



264
265
266
# File 'lib/carray/construct.rb', line 264

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:



252
253
254
# File 'lib/carray/construct.rb', line 252

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:

  • (CAWrap)


280
281
282
# File 'lib/carray/construct.rb', line 280

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