Apply the given function to all elements of self.

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

Examples:

> i = 0
> z = torch.Tensor(3,3)
> z:apply(function(x)
>> i = i + 1
>> return i
>> end) -- fill up the tensor
> = z

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

> z:apply(math.sin) -- apply the sin function
> = z

 0.8415 -0.7568  0.6570
 0.9093 -0.9589  0.9894
 0.1411 -0.2794  0.4121
[torch.Tensor of dimension 3x3]

> sum = 0
> z:apply(function(x)
>> sum = sum + x
>> end) -- compute the sum of the elements
> = sum
1.9552094821074
> = z:sum() -- it is indeed correct!
1.9552094821074