Apply the given function to all elements of self, tensor1
and tensor2
. The number of elements of all tensors
must match, but sizes do not matter.
The function takes three numbers (the current element of self, tensor1
and tensor2
) and might return
a number, in which case it will be stored in self.
Example:
> x = torch.Tensor(3,3) > y = torch.Tensor(9) > z = torch.Tensor(3,3) > > i = 0; x:apply(function() i = i + 1; return math.cos(i)*math.cos(i) end) > i = 0; y:apply(function() i = i + 1; return i end) > i = 0; z:apply(function() i = i + 1; return i end) > > print(x) 0.2919 0.4272 0.5684 0.1732 0.0805 0.0212 0.9801 0.9219 0.8302 [torch.Tensor of dimension 3x3] > print(y) 1 2 3 4 5 6 7 8 9 [torch.Tensor of dimension 9] > print(z) 1 4 7 2 5 8 3 6 9 [torch.Tensor of dimension 3x3] > > x:map2(y, z, function(xx, yy, zz) return xx+yy*zz end) > > print(x) 1.2919 16.4272 49.5684 4.1732 25.0805 64.0212 9.9801 36.9219 81.8302 [torch.Tensor of dimension 3x3]