[julia-users] Re: Constant attributes of Composite Type

2014-11-26 Thread Robert Gates
OK thanks John, I ended up doing a bit differently but it works fine. Sorry 
to keep asking, but now I have another problem I can't seem to wrap my head 
around: consider

my_type_collection = Vector{MyType}
my_type_collection[1] = MyType(a,b,c)

returns: `setindex!` has no method matching 
setindex!(::Type{Array{MyType,1}}, ::MyType, ::Int64)

Seems a bit weird to me, since

my_type_collection = [MyType(a,b,c); MyType(d,e,f)]
my_type_collection[1] = my_type_collection[2]

works just fine.





On Tuesday, November 25, 2014 10:00:59 PM UTC+1, Robert Gates wrote:

 Hi Julians:

 I'm still new to Julia and am having a little trouble correctly 
 understanding composite types. I would like to create a composite type with 
 a mixture of constant attributes, i.e. class attributes, and mutable 
 attributes. In practice, the problem is that I need to instantiate many, 
 e.g. 10e8, type instances and would like to avoid having to allocate memory 
 for values which are constant over a large subset of these instances. Is 
 there any way to do this correctly?

 Thanks for your help!

 Robert



Re: [julia-users] Re: Constant attributes of Composite Type

2014-11-26 Thread John Myles White
Vector{MyType} is a type, not a value. Did you mean Array(MyType, 1)?

 — John

On Nov 26, 2014, at 8:38 AM, Robert Gates robert.ga...@gmail.com wrote:

 OK thanks John, I ended up doing a bit differently but it works fine. Sorry 
 to keep asking, but now I have another problem I can't seem to wrap my head 
 around: consider
 
 my_type_collection = Vector{MyType}
 my_type_collection[1] = MyType(a,b,c)
 
 returns: `setindex!` has no method matching 
 setindex!(::Type{Array{MyType,1}}, ::MyType, ::Int64)
 
 Seems a bit weird to me, since
 
 my_type_collection = [MyType(a,b,c); MyType(d,e,f)]
 my_type_collection[1] = my_type_collection[2]
 
 works just fine.
 
 
 
 
 
 On Tuesday, November 25, 2014 10:00:59 PM UTC+1, Robert Gates wrote:
 Hi Julians:
 
 I'm still new to Julia and am having a little trouble correctly understanding 
 composite types. I would like to create a composite type with a mixture of 
 constant attributes, i.e. class attributes, and mutable attributes. In 
 practice, the problem is that I need to instantiate many, e.g. 10e8, type 
 instances and would like to avoid having to allocate memory for values which 
 are constant over a large subset of these instances. Is there any way to do 
 this correctly?
 
 Thanks for your help!
 
 Robert



[julia-users] Re: Constant attributes of Composite Type

2014-11-25 Thread Robert Gates
Hi John,

Thanks for your quick reply. Yes, I have though of this, however, it 
sounded a bit like a clumsy workaround. That would mean I would have:
function (a, b, c) = constantAttributes{T:MyAbstractType}(::Type{T})
   a = 3
   b = 2
   c = 5
end

instance = MyType(someAttributes)
(att1, att2, att3) = constantAttribute(typeof(instance))

Right? BTW, a little OT, I know, but is there an overhead if I pass the 
instance itself, instead of only its type, i.e. 
constantAttributes{T:MyAbstractType}(instance::T)?

On Tuesday, November 25, 2014 10:00:59 PM UTC+1, Robert Gates wrote:

 Hi Julians:

 I'm still new to Julia and am having a little trouble correctly 
 understanding composite types. I would like to create a composite type with 
 a mixture of constant attributes, i.e. class attributes, and mutable 
 attributes. In practice, the problem is that I need to instantiate many, 
 e.g. 10e8, type instances and would like to avoid having to allocate memory 
 for values which are constant over a large subset of these instances. Is 
 there any way to do this correctly?

 Thanks for your help!

 Robert