neon.backends.nervanacpu.CPUTensor

class neon.backends.nervanacpu.CPUTensor(backend, shape=None, dtype=<class 'numpy.float32'>, ary=None, name=None, persist_values=True, base=None)[source]

Bases: neon.backends.backend.Tensor

The n-dimensional array data structure that resides in host memory, and is meant to be manipulated on the CPU. wrapped numpy.ndarray tensor.

Parameters:
  • dtype (numpy.ndtype, optional) – underlying data type of the elements.
  • ary (data array, optional) – optionally it can be instantiated with a data array
  • persist_values (bool, optional) – If set to True (the default), the values assigned to this Tensor will persist across multiple begin and end calls. Setting to False may provide a performance increase if values do not need to be maintained across such calls

See also

NervanaCPU class

__init__(backend, shape=None, dtype=<class 'numpy.float32'>, ary=None, name=None, persist_values=True, base=None)[source]

Methods

__init__(backend[, shape, dtype, ary, name, …])
asnumpyarray() Deprecated.
copy(a) Construct and return a deep copy of the Tensor passed.
copy_from(a) Alias of copy.
dimension_reorder(new_order) Re-orders dimensions of a tensor without preserving data
fill(value) Assign specified value to each element of this CPUTensor.
get() Return the array.
hist(tag) Compute a histogram of the current tensor values.
raw() Access the raw buffer.
reshape(*shape) Return a reshaped view.
set(value) Wrap the value into NervanaCPU tensor.
share(shape[, dtype, name]) Return a view: ary, where ary.size <= self.size.
take(indices[, axis]) Select a subset of elements from an array across an axis.
transpose([out]) Return a transposed view of the data.
T

Return a transposed view.

For 2D tensor, will do a normal transpose For 3D tensor, will keep the 0 dim, swap the 1 and 2 dimensions

asnumpyarray()[source]

Deprecated. Scheduled to be removed in 2.0. Use get() instead.

copy(a)[source]

Construct and return a deep copy of the Tensor passed.

Arguments:
a (Tensor): the object to copy
Returns:new array object with the same values as input tensor
Return type:Tensor
copy_from(a)[source]

Alias of copy.

Parameters:a (Tensor) – the object to copy
Returns:new array object with the same values as input tensor
Return type:Tensor
dimension_reorder(new_order)

Re-orders dimensions of a tensor without preserving data

Parameters:new_order (list) – new order of dimensions
fill(value)[source]

Assign specified value to each element of this CPUTensor.

Parameters:value (numeric) – The value to be assigned to each element.
Returns:updated view of the data.
Return type:CPUTensor
get()[source]

Return the array.

hist(tag)[source]

Compute a histogram of the current tensor values.

Parameters:tag (string) – Tag to identify the current state of the tensor, useful for disambiguating multiple histograms of the same tensor at different points in time.
Returns:Tensor containing the histogram data.
raw()[source]

Access the raw buffer.

Returns:A device specific pointer
Return type:pointer
reshape(*shape)[source]

Return a reshaped view.

set(value)[source]

Wrap the value into NervanaCPU tensor.

Parameters:value – Array or single input. If it is array, check and Convert the dtype and shape. If it is single value, broadcast to the memory
Returns:self
share(shape, dtype=None, name=None)[source]

Return a view: ary, where ary.size <= self.size. Allows easy sharing of temporary memory This is mostly provided for compatibility, – dtype is ignored

take(indices, axis=None)[source]

Select a subset of elements from an array across an axis.

Parameters:
  • indices (Tensor, numpy ndarray) – indicies of elements to select
  • axis (int) – axis across which to select the values
Returns:

Tensor with selected values

Return type:

Tensor

transpose(out=None)[source]

Return a transposed view of the data. Alias of .T property