On Friday, September 12, 2014 12:41:49 AM UTC-5, Christoph Ortner wrote:
>
> That did work - thank you, see code below.  To explain: this came from a 
> bottleneck in a bigger code, so my problem there must be a different one.
>   -- Christoph
>
> function testtime()
>     a1 = rand(10, 10, 100, 100)
>     b1 = rand(10, 100, 100)
>     c1 = rand(10, 100, 100)
>     d1 = []
>     const a2 = rand(10,10,100,100)
>     const b2 = rand(10,100,100)
>     const c2 = rand(10,100,100)
>     d2 = []
>     @time(begin
>         for n = 1:10
>             d1 = [ a1[a,b,i,j] .* b1[a,i,j] .* c1[b,i,j] for a = 1:10, b = 
> 1:10, i=1:100,j=1:100 ]
>         end
>     end)
>     println(typeof(d1))
>     @time(begin
>         for n = 1:10
>             d2 = [ a2[a,b,i,j] .* b2[a,i,j] .* c2[b,i,j] for a = 1:10, b = 
> 1:10, i=1:100,j=1:100 ]
>         end
>     end)
>     println(typeof(d2))
> end
>

A small point about the code. The initialization 

    d1 = []

is unnecessary.  In fact, this assignment initializes d1 to a 1-dimensional 
array with 0 elements.

The comprehension creates the array of the correct dimension and populates 
it so that initial 1-dimensional array is discarded.
 

>
> testtime()
>
>
>
>

Reply via email to