class CPU(T)
- CPU(T)
- Num::Backend::Storage(T)
- Reference
- Object
Defined in:
tensor/backends/cpu/impl_allocation.crtensor/backends/cpu/impl_data_structure.cr
Constructors
-
.new(shape : Array(Int), order : Num::OrderType, value : T)
Initialize a CPU storage from an initial capacity and an initial value, which will fill the buffer
-
.new(shape : Array(Int), strides : Array(Int), value : T)
Initialize a CPU storage from an initial capacity and an initial value, which will fill the buffer
-
.new(hostptr : Pointer(T), shape : Array(Int), strides : Array(Int))
Initialize a CPU storage from a hostptr and initial shape.
-
.new(shape : Array(Int), order : Num::OrderType)
Initialize a CPU storage from an initial capacity.
-
.new(shape : Array(Int), strides : Array(Int))
Initialize a CPU storage from an initial capacity.
Class Method Summary
-
.base(dtype : U.class) : CPU(U).class forall U
Return a generic class of a specific generic type, to allow for explicit return types in functions that return a different storage type than the parent Tensor
Instance Method Summary
-
#data : Pointer(T)
Raw Crystal pointer that holds a
CPU(T)
s data -
#to_hostptr : Pointer(T)
Converts a CPU storage to a crystal pointer
-
#to_unsafe
Returns the raw Crystal pointer associated with a
CPU(T)
Instance methods inherited from class Num::Backend::Storage(T)
to_unsafe
to_unsafe,
update_metadata(shape : Array(Int32), strides : Array(Int32))
update_metadata
Constructor methods inherited from class Num::Backend::Storage(T)
new(shape : Array(Int), order : Num::OrderType, value : T)new(shape : Array(Int), strides : Array(Int), value : T)
new(hostptr : Pointer(T), shape : Array(Int), strides : Array(Int))
new(shape : Array(Int), order : Num::OrderType)
new(shape : Array(Int), strides : Array(Int)) new
Constructor Detail
Initialize a CPU storage from an initial capacity and an initial value, which will fill the buffer
Arguments
- shape :
Array(Int)
- Shape of the parentTensor
- order :
Array(Int)
- Memory layout of the parentTensor
- value :
T
- Initial value to populate the buffer
Examples
CPU.new([10, 10], 3.4)
Initialize a CPU storage from an initial capacity and an initial value, which will fill the buffer
Arguments
- shape :
Array(Int)
- Shape of the parentTensor
- strides :
Array(Int)
- Strides of the parentTensor
- value :
T
- Initial value to populate the buffer
Examples
CPU.new([10, 10], 3.4)
Initialize a CPU storage from a hostptr and initial shape. The shape is not required for this storage type, but is needed by other implementations to ensure copy requirements have the right pointer size.
Arguments
- data :
Pointer(T)
- Existing databuffer for aTensor
- shape :
Array(Int)
- Shape of the parentTensor
- strides :
Array(Int)
- Strides of the parentTensor
Examples
a = Pointer(Int32).malloc(10)
s = CPU.new(a, [5, 2])
Initialize a CPU storage from an initial capacity. The data will be filled with zeros
Arguments
- shape :
Array(Int)
- Shape of the parentTensor
- order :
Array(Int)
- Memory layout of the parentTensor
Examples
CPU.new([2, 3, 4])
Initialize a CPU storage from an initial capacity. The data will be filled with zeros
Arguments
Examples
CPU.new([2, 3, 4])
Class Method Detail
Return a generic class of a specific generic type, to allow for explicit return types in functions that return a different storage type than the parent Tensor
Examples
a = CPU(Float32).new([10])
# Cannot do
# a.class.new ...
a.class.base(Float64).new([10])