Does anyone know an efficient way to add NTuples in Julia?

I can do it using recursive functions, but for various reasons this is not 
efficient in my context. I really miss something like tuple(a[i] + b[i] for 
i in 1:N) to create the resulting tuple all in one go (here a and b would 
be tuples).

The compiler doesn't do badly with recursive functions for handling tuples 
in very straightforward situations, but for example, if I want to create an 
immutable type based on a tuple the compiler doesn't seem to be able to 
handle the necessary optimisations. At least, that is what I infer from the 
timings. Consider

immutable bill{N}
   d::NTuple{N, Int}
end

and I want to add two bill's together. If I have to add the tuples 
themselves using recursive functions, then I no longer seem to be able to 
do something like:

A[i] = B[i] + C[i] efficiently, where A, B and C are arrays whose elements 
are of type bill.

I know how to handle tuples via arrays, but for efficiency reasons I 
certainly don't want to do that, e.g. tuple([a[i] + b[i] for i in 1:N]...).

Bill.

Reply via email to