예제 #1
0
 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)
예제 #2
0
    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)
예제 #3
0
    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)
예제 #4
0
    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)
예제 #5
0
    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)
예제 #6
0
파일: core.py 프로젝트: sanskar107/Open3D-1
    def __init__(self, shape, dtype=None, device=None, size=None):
        if isinstance(shape, list) or isinstance(shape, tuple):
            shape = SizeVector(shape)
        elif isinstance(shape, SizeVector):
            pass
        else:
            raise ValueError('shape must be a list, tuple, or SizeVector')

        if dtype is None:
            dtype = Dtype.Float32
        if device is None:
            device = Device("CPU:0")
        if size is None:
            size = 0

        super(TensorList, self).__init__(shape, dtype, device, size)
예제 #7
0
파일: core.py 프로젝트: sanskar107/Open3D-1
    def from_tensors(tensors, device=None):
        """
        Returns a TensorList from a list of existing tensors.
        Args:
            tensors: The list of Tensor to construct from.
                     The tensors' shapes should be compatible.
            device: The device where the tensorlist is targeted.
        """

        if not isinstance(tensors, list) and not isinstance(tensors, tuple):
            raise ValueError('tensors must be a list or tuple')

        for tensor in tensors:
            if not isinstance(tensor, Tensor):
                raise ValueError(
                    'every element of the input list must be a valid tensor')
        if device is None:
            device = Device("CPU:0")

        return super(TensorList, TensorList).from_tensors(tensors, device)