I'm puzzled that a type  consisting  only of 2 integers doesn't qualify as 
"bitstype".  Further experiment shows that the array seems to be an array of 
references, I don't know how to implement zero, and generally that I'm a bit 
lost :)  My goal is to get a densely packed array of data.  I assume that will 
use less memory and generate faster code; if not, maybe I should change my goal.

BTW, my real use has a type more heterogeneous than 2 Int's, so a solution that 
uses a 2D array doesn't really generalize appropriately for me.

module TT
import Base.zero

type Stuff
    a::Int
    b::Int
end

function zero(x::Stuff)
    Stuff(0, 0)
end

end

julia> v=Array(TT.Stuff, 3)  #as before
 3-element Array{TT.Stuff,1}:
  #undef
  #undef
  #undef

 julia> s=TT.Stuff(3, 5)
 TT.Stuff(3,5)

 julia> v=fill(s, 2)
 2-element Array{TT.Stuff,1}:
  TT.Stuff(3,5)
  TT.Stuff(3,5)

 julia> s.a=900
 900

 julia> v  ###OOPS: every array element points to the same instance
 2-element Array{TT.Stuff,1}:
  TT.Stuff(900,5)
  TT.Stuff(900,5)

 julia> zero(TT.Stuff)  # This is probably what needs to work for zeros() to 
work
 ERROR: MethodError: `zero` has no method matching zero(::Type{TT.Stuff})

!julia> zero(TT.Stuff(1, 1))  # this at least calls the right c'tor
 TT.Stuff(0,0)


Ross
________________________________________
From: julia-users@googlegroups.com [julia-users@googlegroups.com] on behalf of 
Lutfullah Tomak [tomaklu...@gmail.com]
Sent: Tuesday, May 10, 2016 12:04 AM
To: julia-users
Subject: [julia-users] undefined reference error

You need to initialize array entries if you don't have eltype as bitstype. 
Here, undefined reference means you had not initialize the entry. And, full 
type assignment works because it initializes the entry.

Reply via email to