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 v2.4.1+cu121. 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 v2.4.1+cu121 is listed below.
Description From Torch v2.4.1+cu121¶
-
torch.
mul
(input, other, *, out=None) → Tensor¶ Multiplies
input
byother
.\[\text{out}_i = \text{input}_i \times \text{other}_i\]Supports broadcasting to a common shape, type promotion, and integer, float, and complex inputs.
- Args:
input (Tensor): the input tensor. other (Tensor or Number) - the tensor or number to multiply input by.
- Keyword args:
out (Tensor, optional): the output tensor.
Examples:
>>> a = torch.randn(3) >>> a tensor([ 0.2015, -0.4255, 2.6087]) >>> torch.mul(a, 100) tensor([ 20.1494, -42.5491, 260.8663]) >>> b = torch.randn(4, 1) >>> b tensor([[ 1.1207], [-0.3137], [ 0.0700], [ 0.8378]]) >>> c = torch.randn(1, 4) >>> c tensor([[ 0.5146, 0.1216, -0.5244, 2.2382]]) >>> torch.mul(b, c) 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]])