This is nice. This (unsafe) method could be used to implement array-like access 
functionality (getindex, setindex!, length, etc.) in a safe manner.

-erik

> On Mar 17, 2015, at 11:25 , René Donner <[email protected]> wrote:
> 
> I believe this might help: 
> https://groups.google.com/d/msg/julia-users/K1BlJW8k2o0/FRfANpsB_XIJ
> 
> Am Dienstag, 17. März 2015 16:08:09 UTC+1 schrieb Kristoffer Carlsson:
> Say I have an immutable with only one type.
> 
> immutable Strain
>     exx::Float64
>     eyy::Float64
>     ezz::Float64
>     gyz::Float64
>     gxz::Float64
>     gxy::Float64
> end
> 
> Is there anyway I can reinterpret this as a Vector{Float64} in a fast way 
> without copying data. The memory of the Strain type should be exactly like 
> the vector.
> 
> The reason I want to do this is because I want to i.e. be able to multiply a 
> strain and a general matrix but I also want to be able to write my own 
> functions for Strain.
> 
> Naively, I tried this:
> 
> julia> reinterpret(Vector{Float64}, strain)
> ERROR: reinterpret: expected bits type as first argument
>  in reinterpret at base.jl:65
> 
> I saw this comment in one of the issues here 
> https://github.com/JuliaLang/julia/issues/5857:
> 
> "ImmutableArrays has the advantage that Array(Vector4{Int}, 10) it can be 
> reinterpreted as a 4x10 matrix with reinterpret and reshape without memory 
> movement (e.g. when calling a c function on the data)."
> 
> 
> Best regards,
> Kristoffer Carlsson

--
Erik Schnetter <[email protected]>
http://www.perimeterinstitute.ca/personal/eschnetter/

My email is as private as my paper mail. I therefore support encrypting
and signing email messages. Get my PGP key from https://sks-keyservers.net.

Attachment: signature.asc
Description: Message signed with OpenPGP using GPGMail

Reply via email to