quick question: How do I define a type most effective so that I can give it
both single values, vectors and Arrays as variables?
I now have:
type x
value::Array{Float64}
end
I can do x(rand(3)) as well as x(rand(3,3)) but not x(0.1)
the answer is probably in the forums but I couldn't const
On Mon, Sep 21, 2015 at 8:37 AM, Jon Norberg wrote:
> quick question: How do I define a type most effective so that I can give it
> both single values, vectors and Arrays as variables?
>
> I now have:
>
> type x
> value::Array{Float64}
> end
>
> I can do x(rand(3)) as well as x(rand(3,3)) but
leaftype?
On Monday, September 21, 2015 at 2:41:02 PM UTC+2, Yichao Yu wrote:
>
> On Mon, Sep 21, 2015 at 8:37 AM, Jon Norberg > wrote:
> > quick question: How do I define a type most effective so that I can give
> it both single values, vectors and Arrays as variables?
> >
> > I now have:
>
not sure what leaf type is?
I actually need more fields in the type so I do need it as some field
type x
value::Array{Float64}
otherfield...
end
On Mon, Sep 21, 2015 at 8:53 AM, Jon Norberg wrote:
> leaftype?
http://julia.readthedocs.org/en/latest/stdlib/base/?highlight=leaftype#Base.isleaftype
http://julia.readthedocs.org/en/latest/manual/performance-tips/#code-warntype
>
> On Monday, September 21, 2015 at 2:41:02 PM UTC+2, Yichao Yu w
On Mon, Sep 21, 2015 at 8:55 AM, Jon Norberg wrote:
> not sure what leaf type is?
>
> I actually need more fields in the type so I do need it as some field
>
> type x
> value::Array{Float64}
>otherfield...
> end
What I meant is that if you don't need `.value` to be type stable,
just `::Un
type x
value::Union{Array{Float64},Float64}
end
gives me error:
type: instantiate_type: expected TypeConstructor, got function
On Mon, Sep 21, 2015 at 9:06 AM, Jon Norberg wrote:
> type x
> value::Union{Array{Float64},Float64}
> end
Replace Union{} with Union() on 0.3 (or use Compat)
>
> gives me error:
>
> type: instantiate_type: expected TypeConstructor, got function
>
Many thanks! works