title: Dividing a DoubleTensor matrix by a DoubleTensor number in torch
body: <p>I'm trying to update a matrix of real valued numbers in a for loop using <code>torch.Tensor</code>.
  Here is what I'd like to do:</p>
  
  <pre><code>-- W and P are of size NxN, r is of size N
  delta_W = P * r:view(N, 1) * r:view(1, N) * P  -- this is an NxN
  denominator = 1 + r:view(1, N) * P * r:view(N, 1)  -- this is a number
  delta_W = delta_w / denominator  -- ## THIS ONE RAISES ERROR ##
  W = W + delta_W
  </code></pre>
  
  <p>Just to be clear:</p>
  
  <pre><code>denom             -&gt; [torch.DoubleTensor of size 1x1]
  P, delta_W, W     -&gt; [torch.DoubleTensor of size 200x200]
  </code></pre>
  
  <p>The error when I do the division is:</p>
  
  <pre><code>bad argument #2 to '?' (number expected at /usr/local/torch/pkg/torch/generic/TensorOperator.c:145)
  </code></pre>
  
  <p>I'm a heavy numpy users so I thought "broadcasting" was the issue, therefore I tried simulating it through <code>torch.repeatTensor(denom, N, N)</code>  with no luck. If denom is just a number (not a <code>DoubleTensor</code>) everything works fine anyway. Using the element doesn't work either, <code>delta_P / denom[1]</code> gives the same error.</p>
  
  <p>What am I doing wrong?</p>
  
  <p>Edit:
  I tried using</p>
  
  <pre><code>denominator = (1 + r:view(1, N) * P * r:view(N, 1)):apply(function(x) return x^(-1) end)
  delta_w = delta_w * torch.repeatTensor(denominator, N, N)
  </code></pre>
  
  <p>which doesn't throw an error but the results are wrong. To see this, try the following:</p>
  
  <pre><code>torch.linspace(0, 3, 4):view(2, 2) * torch.Tensor(2, 2):fill(0.5)
  </code></pre>