*Memos:
- My post explains square().
- My post explains pow().
- My post explains float_power().
- My post explains abs() and sqrt().
- My post explains trace(), reciprocal() and rsqrt().
gcd() can get the 0D or more D tensor of zero or more greatest common divisors from two of the 0D or more D tensors of zero or more elements as shown below:
*Memos:
-
gcd()
can be used with torch or a tensor. - The 1st argument(
input
) withtorch
or using a tensor(Required-Type:tensor
ofint
). - The 2nd argument with
torch
or the 1st argument isother
(Required-Type:tensor
ofint
). - There is
out
argument withtorch
(Optional-Default:None
-Type:tensor
): *Memos:-
out=
must be used. - My post explains
out
argument.
-
import torch tensor1 = torch.tensor(16) tensor2 = torch.tensor([-40, -30, -20, -10, 0, 10, 20, 30]) torch.gcd(input=tensor1, other=tensor2) tensor1.gcd(other=tensor2) torch.gcd(input=tensor2, other=tensor1) # tensor([8, 2, 4, 2, 16, 2, 4, 2]) tensor1 = torch.tensor([16, -12, -15, 1, 9, -25, 0, -18]) tensor2 = torch.tensor([-40, -30, -20, -10, 0, 10, 20, 30]) torch.gcd(input=tensor1, other=tensor2) torch.gcd(input=tensor2, other=tensor1) # tensor([8, 6, 5, 1, 9, 5, 20, 6]) tensor1 = torch.tensor([[16, -12, -15, 1], [9, -25, 0, -18]]) tensor2 = torch.tensor([0, 10, 20, 30]) torch.gcd(input=tensor1, other=tensor2) torch.gcd(input=tensor2, other=tensor1) # tensor([[16, 2, 5, 1], [9, 5, 20, 6]]) tensor1 = torch.tensor([[[16, -12], [-15, 1]], [[9, -25], [0, -18]]]) tensor2 = torch.tensor([0, 10]) torch.gcd(input=tensor1, other=tensor2) torch.gcd(input=tensor2, other=tensor1) # tensor([[[16, 2], [15, 1]], # [[9, 5], [0, 2]]])
lcm() can get the 0D or more D tensor of zero or more least common multiples from two of the 0D or more D tensors of zero or more elements as shown below:
*Memos:
-
lcm()
can be used withtorch
or a tensor. - The 1st argument(
input
) withtorch
or using a tensor(Required-Type:tensor
ofint
). - The 2nd argument with
torch
or the 1st argument isother
(Required-Type:tensor
ofint
). - There is
out
argument withtorch
(Optional-Default:None
-Type:tensor
): *Memos:-
out=
must be used. - My post explains
out
argument.
-
import torch tensor1 = torch.tensor(10) tensor2 = torch.tensor([-4, -3, -2, -1, 0, 1, 2, 3]) torch.lcm(input=tensor1, other=tensor2) tensor1.lcm(other=tensor2) torch.lcm(input=tensor2, other=tensor1) # tensor([20, 30, 10, 10, 0, 10, 10, 30]) tensor1 = torch.tensor([10, 1, -15, 4, 9, -6, 0, -5]) tensor2 = torch.tensor([-4, -3, -2, -1, 0, 1, 2, 3]) torch.lcm(input=tensor1, other=tensor2) torch.lcm(input=tensor2, other=tensor1) # tensor([20, 3, 30, 4, 0, 6, 0, 15]) tensor1 = torch.tensor([[10, 1, -15, 4], [9, -6, 0, -5]]) tensor2 = torch.tensor([0, 1, 2, 3]) torch.lcm(input=tensor1, other=tensor2) torch.lcm(input=tensor2, other=tensor1) # tensor([[0, 1, 30, 12], [0, 6, 0, 15]]) tensor1 = torch.tensor([[[10, 1], [-15, 4]], [[9, -6], [0, -5]]]) tensor2 = torch.tensor([0, 1]) torch.lcm(input=tensor1, other=tensor2) torch.lcm(input=tensor2, other=tensor1) # tensor([[[0, 1], [0, 4]], # [[0, 6], [0, 5]]])
Top comments (0)