def eye(n, dtype=Dtype.Float64, device=Device("CPU:0")): """ Create an identity square matrix. Args: n (int): size of square matrix dtype (Dtype): Data type of the tensor. device (Device): Device where the tensor is created. """ return super(Tensor, Tensor).eye(n, dtype, device)
def __init__(self, data, dtype=None, device=None): if isinstance(data, (tuple, list, int, float)): data = np.array(data) if not isinstance(data, np.ndarray): raise ValueError("data must be a list, tuple, or Numpy array.") if dtype is None: dtype = _numpy_dtype_to_dtype(data.dtype) if device is None: device = Device("CPU:0") super(Tensor, self).__init__(data, dtype, device)
def ones(shape, dtype, device=Device("CPU:0")): """ Create a tensor with fill with ones. Args: shape (list, tuple, SizeVector): Shape of the tensor. dtype (Dtype): Data type of the tensor. device (Device): Device where the tensor is created. """ if not isinstance(shape, SizeVector): shape = SizeVector(shape) return super(Tensor, Tensor).ones(shape, dtype, device)
def empty(shape, dtype, device=Device("CPU:0")): """ Create a tensor with uninitilized values. Args: shape (list, tuple, SizeVector): Shape of the tensor. dtype (Dtype): Data type of the tensor. device (Device): Device where the tensor is created. """ if not isinstance(shape, SizeVector): shape = SizeVector(shape) return super(Tensor, Tensor).empty(shape, dtype, device)
def full(shape, fill_value, dtype, device=Device("CPU:0")): """ Create a tensor with fill with the specified value. Args: shape (list, tuple, SizeVector): Shape of the tensor. fill_value (scalar): The value to be filled. dtype (Dtype): Data type of the tensor. device (Device): Device where the tensor is created. """ if not isinstance(shape, SizeVector): shape = SizeVector(shape) return super(Tensor, Tensor).full(shape, fill_value, dtype, device)