Also, if you haven't seen it yet, make sure to check out 
http://juliadiff.org

On Thursday, July 31, 2014 4:39:26 PM UTC-4, Iain Dunning wrote:
>
> 1. Yes, it would create an array of pointers.
> 2. Yes, it would worsen performance.
> 3. Try using a Tuple, e.g.
>
> julia> immutable Dual{T1,T2,N}
>          x::T1
>          dx::NTuple{N,T2}
>        end
>
> julia> Dual(1.0, (2.0, 3.0))
> Dual{Float64,Float64,2}(1.0,(2.0,3.0))
>
> I think this will be stored "flat" but I'm not 100% sure.
>
> On Thursday, July 31, 2014 2:45:27 AM UTC-4, Philippe Maincon wrote:
>>
>> Hi,
>>
>> Say I create a multidimensional array "a" and I have defined the type
>>
>>
>> immutable Dual{T1,T2} # immutable: fields are read only, except by 
>> constructor
>>
>>      x ::T1        # think of this as a Float for this discussion
>>
>>      dx::T2        # Vector{Float}
>>
>> end
>>
>>
>>  (yes, I am playing with automatic differentiation) Then I want to do the 
>> following allocation:
>>
>>
>> b = Array(Dual{Float64,  Array{Float64,ndims(a)}}  ,size(a)...)
>>
>>
>> So I want an array of "structures", each having as field a Float, and an 
>> Array.  This would be accessed as b[i].x and  b[i].dx[j]
>>
>> Now my intention is that all these  dx array *have the same size*, which 
>> opens for packed storage, without any use of pointers by the compiler.  
>> This, I understand is what "immutable" is for, and is exploited, implicitly, 
>> in Complex.jl.  However, in my declaration above, I do not spec the size of 
>> the dx's, and sothis will compile, I believe, into an array of x's and 
>> pointer to dx's, and I expect suboptimal performance.
>>
>>
>>    1. Am I right that this would compile into an array of pointers?
>>    2. If yes, am I right that this would cause poor performance? (think of 
>> Complex,jl, you really want things to go fast, there)
>>    3. If yes, is there a way to allocate b that ensures "packed storage"?
>>    
>>
>> Thank you beforehand for your answer, but most of all, thank you for Julia!
>>
>>
>> Philippe
>>
>>

Reply via email to