Well, I manged to implement the composite type, but using vectors turned 
out to be simpler. Unfortunately, when translating the remainder of the 
MATLAB algorithm, I immediately ran into another MATLAB-Julia difference: 
Julia's composite types are copied by reference and apparently there is no 
automatic copy() function - at least that's what I learned from the user 
forum 
(https://groups.google.com/forum/#!msg/julia-users/e1tEqqdc-5s/NBjIKO5pajcJ). 
The lack of a copy function sure explains some strange output that I've 
been getting! 

For a solution, is there a place (e.g. in the manual) where it is explained 
(in detail!) how to write a required copy function? My composite type is 
pretty large (see below).. and the examples I found where -for me- 
insufficient to be able to write such a required copy function. Again, 
hopefully someone can provide some additional information!

# 1
type Subdesign
 efficiency     :: Float64
 V                :: Vector{Float64}
 expV           :: Vector{Float64}
 sumExpV    :: Vector{Float64}
 P                :: Vector{Float64}
 PdX            :: Matrix{Float64}
 sumPdX      :: Matrix{Float64}
 Z                :: Matrix{Float64}
 ZZ              :: Matrix{Float64}

 Subdesign(nrTasks,nrParameters)= new( 99,
                                                     zeros(14*nrTasks),
                                                     zeros(14*nrTasks),
                                                     zeros(14*nrTasks),
                                                     zeros(14*nrTasks),
                                                     zeros(14*nrTasks, 
nrParameters),
                                                     zeros(14*nrTasks, 
nrParameters),
                                                     zeros(14*nrTasks, 
nrParameters),
                                                     zeros(nrParameters, 
nrParameters))
end

# 2
type Draw
 efficiency    :: Float64
 beta           :: Array{Float64}
 ZZ              :: Matrix{Float64}
 subdesign   :: Array{Subdesign}
 
 Draw(nrTasks, nrParameters, nrSubdesigns) = new( 99,
                                                                     
zeros(1,nrParameters),
                                                                     
zeros(nrParameters, nrParameters),
                                                                     
[Subdesign(nrTasks,nrParameters) for i in 1:nrSubdesigns])    
end


# 3
type Design
 efficiency           :: Float64
 design               :: Array{Float64}
 X                       :: Array{Float64}
 dX                     :: Array{Float64}
 draw                  :: Array{Draw}
 
 Design(nrTasks, nrSubdesigns, nrParameters, nrDraws) = new( 99,
                                                                            
          99,
                                                                           
           99,
                                                                           
           zeros(nrTasks,12,nrSubdesigns),
                                                                           
           zeros(14*nrTasks,nrParameters,nrSubdesigns),
                                                                           
           zeros(14*nrTasks,nrParameters,nrSubdesigns),
                                                                           
           [Draw(nrTasks,nrParameters, nrSubdesigns) for i in 1:nrDraws])
end

# create container for 3 designs
design = [Design(nrTasks, nrSubdesigns, nrParameters, nrDraws) for i in 
1:3];
# copy designs -> does not work:
design[1] = copy(design[3])



Reply via email to