mul¶
Documentation¶
-
treetensor.torch.
mul
(input, other, *args, **kwargs)[source]¶ Multiplies each element of the input
input
with the scalarother
and returns a new resulting tensor.Examples:
>>> import torch >>> import treetensor.torch as ttorch >>> ttorch.mul( ... ttorch.tensor([1, 2, 3]), ... ttorch.tensor([3, 5, 11]), ... ) tensor([ 3, 10, 33]) >>> ttorch.mul( ... ttorch.tensor({ ... 'a': [1, 2, 3], ... 'b': {'x': [[3, 5], [9, 12]]}, ... }), ... ttorch.tensor({ ... 'a': [3, 5, 11], ... 'b': {'x': [[31, -15], [13, 23]]}, ... }) ... ) <Tensor 0x7f11b139ca58> ├── a --> tensor([ 3, 10, 33]) └── b --> <Tensor 0x7f11b139cb00> └── x --> tensor([[ 93, -75], [117, 276]])
Torch Version Related
This documentation is based on torch.mul in torch v1.9.0+cu102. Its arguments’ arrangements depend on the version of pytorch you installed.
If some arguments listed here are not working properly, please check your pytorch’s version with the following command and find its documentation.
1 | python -c 'import torch;print(torch.__version__)'
|
The arguments and keyword arguments supported in torch v1.9.0+cu102 is listed below.
Description From Torch v1.9.0+cu102¶
-
torch.
mul
(input, other, *, out=None) → Tensor¶ Multiplies each element of the input
input
with the scalarother
and returns a new resulting tensor.\[\text{out}_i = \text{other} \times \text{input}_i\]If
input
is of type FloatTensor or DoubleTensor,other
should be a real number, otherwise it should be an integer- Args:
input (Tensor): the input tensor. other (Number): the number to be multiplied to each element of
input
- Keyword args:
out (Tensor, optional): the output tensor.
Example:
>>> a = torch.randn(3) >>> a tensor([ 0.2015, -0.4255, 2.6087]) >>> torch.mul(a, 100) tensor([ 20.1494, -42.5491, 260.8663])
Each element of the tensor
input
is multiplied by the corresponding element of the Tensorother
. The resulting tensor is returned.The shapes of
input
andother
must be broadcastable.\[\text{out}_i = \text{input}_i \times \text{other}_i\]- Args:
input (Tensor): the first multiplicand tensor other (Tensor): the second multiplicand tensor
- Keyword args:
out (Tensor, optional): the output tensor.
Example:
>>> a = torch.randn(4, 1) >>> a tensor([[ 1.1207], [-0.3137], [ 0.0700], [ 0.8378]]) >>> b = torch.randn(1, 4) >>> b tensor([[ 0.5146, 0.1216, -0.5244, 2.2382]]) >>> torch.mul(a, b) tensor([[ 0.5767, 0.1363, -0.5877, 2.5083], [-0.1614, -0.0382, 0.1645, -0.7021], [ 0.0360, 0.0085, -0.0367, 0.1567], [ 0.4312, 0.1019, -0.4394, 1.8753]])