Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
tensor2: TensorBase
mat:
Matrix to the operation
beta: ,optional
alpha: ,optional
Returns
-------
TensorBase:
Output Tensor
"""
_ensure_tensorbase(tensor1)
_ensure_tensorbase(tensor2)
_ensure_tensorbase(mat)
if tensor2.data.ndim != 3:
print("dimension of tensor2 is not 3")
elif tensor1.data.ndim != 3:
print("dimension of tensor1 is not 3")
elif mat.data.ndim != 3:
print("dimension of mat is not 3")
elif tensor1.encrypted or tensor2.encrypted or mat.encrypted:
return NotImplemented
else:
mmul = np.matmul(tensor1.data, tensor2.data)
out = (mat.data * beta) + (mmul * alpha)
return TensorBase(out)
for each floating point number x : a >= x
Behavior is independent of a tensor's shape.
Parameters
----------
tensor: TensorBase
input Tensor
Returns
-------
TensorBase:
Output Tensor
"""
tensor = _ensure_tensorbase(tensor)
if tensor.encrypted is True:
return NotImplemented
return TensorBase(np.ceil(tensor.data))
input: TensorBase
the first input tensor
other: TensorBase
the second input tensor
dim: int, optional
the dimension to take the cross-product in. Default is -1
Returns
-------
TensorBase: The result Tensor
"""
input = _ensure_tensorbase(input)
other = _ensure_tensorbase(other)
if input.encrypted or other.encrypted:
return NotImplemented
# Verify that the shapes of both vectors are same
if input.shape() != other.shape():
raise ValueError('inconsistent dimensions {} and {}'.format(
input.shape(), other.shape()))
# verify that the given dim is valid
if dim < -len(input.shape()) or dim >= len(input.shape()):
raise ValueError('invalid dim. Should be between {} and {}'.format(
-len(input.shape()), len(input.shape()) - 1))
# verify that the size of dimension dim is 3
if input.shape()[dim] != 3:
def sinh(tensor):
"""
Returns a new tensor holding element wise values of hyperbolic sine
function
Parameters
----------
tensor: TensorBase
input Tensor
Returns
-------
TensorBase:
Output Tensor;
"""
tensor = _ensure_tensorbase(tensor)
if tensor.encrypted:
return NotImplemented
return TensorBase(np.sinh(np.array(tensor.data)))
Returns the cumulative product of the elements along a given axis
Parameters
----------
tensor: TensorBase
input Tensor
dim:
Dimension on which the operation is done
Returns
-------
TensorBase:
Output Tensor; 1D Tensor
"""
tensor = _ensure_tensorbase(tensor)
if tensor.encrypted is True:
return NotImplemented
return TensorBase(np.cumprod(tensor.data, dim))
Floor of an input scalar is the largest integer such as:
for each floating point number x : a <= x
Behavior is independent of a tensor's shape
Parameters
----------
tensor: TensorBase
input Tensor
Returns
-------
TensorBase:
Output Tensor; floored values
"""
tensor = _ensure_tensorbase(tensor)
if tensor.encrypted is True:
return NotImplemented
return TensorBase(np.floor(tensor.data))
def cos(tensor):
"""
Returns a new tensor holding values of Trigonometric cosine
function
Parameters
----------
tensor: TensorBase
input Tensor
Returns
-------
TensorBase:
Output Tensor;
"""
tensor = _ensure_tensorbase(tensor)
if tensor.encrypted:
return NotImplemented
return TensorBase(np.cos(np.array(tensor.data)))
* Optional argument diagonal value is about which diagonal to consider,
zero is for main, positive for upper and negative for below diagonal
Parameters
----------
tensor : TensorBase
The first operand in the diag operation
diagonal : Integer
The second operand in the diag operation
Returns
-------
TensorBase
Computed tensor result for diag operation
"""
tensor = _ensure_tensorbase(tensor)
if tensor.encrypted is True:
return NotImplemented
dim = tensor.dim()
if dim == 1:
return TensorBase(np.diag(tensor.data, diagonal))
elif dim == 2:
return TensorBase(np.diagonal(tensor.data, diagonal))
else:
raise ValueError("Input must be 1- or 2-d tensor.")
tensor2: TensorBase
mat:
Matrix to the operation
beta: ,optional
alpha: ,optional
Returns
-------
TensorBase:
Output Tensor
"""
_ensure_tensorbase(tensor1)
_ensure_tensorbase(tensor2)
_ensure_tensorbase(mat)
if tensor2.data.ndim != 3:
print("dimension of tensor2 is not 3")
elif tensor1.data.ndim != 3:
print("dimension of tensor1 is not 3")
elif tensor1.encrypted or tensor2.encrypted or mat.encrypted:
return NotImplemented
else:
mmul = np.matmul(tensor1.data, tensor2.data)
sum_ = 0 # sum is a built in python function
for i, _ in enumerate(mmul):
sum_ += mmul[i]
out = (mat.data * beta) + (alpha * sum_)
return TensorBase(out)
but must be non-negative and have a non-zero sum.
Weights for the multinomial distribution
=======
num_samples: Int
Number of samples to be drawn. If replacement is false, this must be lower than the length of p.
replacement: bool, optional
Whether to draw with replacement or not
Returns
-------
Output Tensor
"""
if tensor.encrypted:
return NotImplemented
p = _ensure_tensorbase(tensor)
p = p / p.sum()
return TensorBase(np.random.choice(len(p), num_samples, replacement, p.data))