Is it also true that `StateVec`, after defining the appropriate methods, is
probably faster for adding vectors and multiplying the vectors by 3-by-3
matrices since adding two Vector{Floats64} requires a check to see that the
two vectors have the same type, and a loop to iterate over the elements?
And this is the reason behind FixedArrays?

On Tue, Mar 3, 2015 at 6:30 PM, Kevin Squire <[email protected]> wrote:

> While all that is true, I think the sentiment of the question is whether
> we can have packed arrays of objects with complex types, where the
> individual fields of those objects are easily modified.  Right now, it's
> possible to do so with (packed) arrays of immutables using pointers to
> access the memory pointed to by the individual members, but that is neither
> easy nor condoned.
>
> Cheers,
>    Kevin
>
> On Tue, Mar 3, 2015 at 2:26 PM, Matt Bauman <[email protected]> wrote:
>
>> On Tuesday, March 3, 2015 at 4:42:05 PM UTC-5, Sean Marshallsay wrote:
>>>
>>> Sorry about that. Is there some work going into making `type` densely
>>> packed or am I way off base here?
>>>
>>
>> It's simply not possible to have `type` be densely packed because it is
>> mutable and has reference semantics. Unlike immutables, which are
>> identified purely by their contents, types can be thought of as containers
>> whose contents may change over time.  You can't densely pack these
>> containers, because densely packing requires *copying* the contents.
>> That's okay for immutables (since an immutable is its contents, and its
>> contents cannot change), but it's not okay for types.  Here's a simple
>> example for why this cannot work:
>>
>> julia> x = B(1,2)
>> B(1.0,2.0)
>>
>> # Lets put this container into an array
>> julia> a = [x]
>> 1-element Array{B,1}:
>>  B(1.0,2.0)
>>
>> # Now x and a[1] both refer to the *same* container
>> julia> x.x = 3; a
>> 1-element Array{B,1}:
>>  B(3.0,2.0)
>>
>> # We can even push the same container as the second element:
>> julia> push!(a, x)
>> 2-element Array{B,1}:
>>  B(3.0,2.0)
>>  B(3.0,2.0)
>>
>> # Now x, a[1] and a[2] all refer to the same container
>> # If the value 3.0 were stored inline, this wouldn't be possible:
>> julia> x.x = 4; a
>> 2-element Array{B,1}:
>>  B(4.0,2.0)
>>  B(4.0,2.0)
>>
>
>

Reply via email to