Apply the given function to all elements of self and tensor. The number of elements of both tensors must match, but sizes do not matter.

The function takes two numbers (the current element of self and tensor) and might return a number, in which case it will be stored in self.

Example:

> x = torch.Tensor(3,3)
> y = torch.Tensor(9)
> i = 0
> x:apply(function() i = i + 1; return i end) -- fill-up x
> i = 0
> y:apply(function() i = i + 1; return i end) -- fill-up y
> = x

 1  4  7
 2  5  8
 3  6  9
[torch.Tensor of dimension 3x3]

> = y

 1
 2
 3
 4
 5
 6
 7
 8
 9
[torch.Tensor of dimension 9]

> x:map(y, function(xx, yy) return xx*yy end) -- element-wise multiplication
> = x

  1  16  49
  4  25  64
  9  36  81
[torch.Tensor of dimension 3x3]