title: Riemann matrix function optimization in Julia
body: <p>I have implemented a function in Julia for creating a Riemann matrix of size N. It is a N-by-N matrix associated with the Riemann hypothesis, which is true if and only if:</p>
  
  <p><code>DET(A) = O( N! N^(-1/2+epsilon))</code> for every <code>epsilon &gt; 0</code>, <code>DET()</code> denotes determinant, <code>!</code> denotes factorial.</p>
  
  <p>Where, A = Riemann matrix, with</p>
  
  <p><code>A = B(2:N+1, 2:N+1)</code>, where</p>
  
  <pre><code>B(i,j) = i-1 if i divides j, and
            -1 otherwise.
  </code></pre>
  
  <p>Here is my code which works fine, but needs optimization:</p>
  
  <pre><code>function riemann(x::Int32)
      R = zeros(Int32,x+1,x+1)
      for i=1:x+1, j=1:x+1
          if j%i == 0
             R[i,j] = i-1
          else
             R[i,j] = -1
          end
      end
      return R[2:x+1,2:x+1]
  end
  </code></pre>
  
  <p>Hopefully, I need to write it in a more efficient form like:</p>
  
  <pre><code>function riemann!{T}(R::AbstractMatrix{T}, x::T)
  .
  .
  .
  </code></pre>
  
  <p>Any suggestions are appreciated.</p>
  
  <p>EDIT:</p>
  
  <p>Well, this is the other form I suggested above. I timed it against the original code and found no speed gain.</p>
  
  <pre><code>function calc_riemann!{T}(R::AbstractMatrix{T}, x::T)
      for i=1:x+1, j=1:x+1
          if j%i == 0
             R[i,j] = i-1
          else
             R[i,j] = -1
          end
      end
  end
  function riemann(x::Int)
      R = Array(Int, x+1,x+1)
      calc_riemann!(R, x)
      y = R[2:x+1,2:x+1]
  end
  </code></pre>