[julia-users] Re: Allocate a Vector

2015-02-04 Thread colintbowers
I think the issue has already come up 
[here](https://github.com/JuliaLang/julia/issues/3427) and the discussion 
[here](https://github.com/JuliaLang/julia/issues/1470) is also related. As 
others have mentioned, this should be possible in v0.4 but isn't possible 
in v0.3.x. Personally, on v0.3 at the moment, if I want to use a type alias 
as a constructor, I just add a "C" to the end, e.g. given type alias 
"MyTypeAlias", I define the outer constructor "MyTypeAliasC". I'll be 
ditching the "C" once v0.4 stable is released...

On Wednesday, 4 February 2015 21:00:51 UTC+11, Kristoffer Carlsson wrote:
>
> If you want to allocate an Array you can simply write:
>
> julia> Array(Int, 5, 1)
> 10x1 Array{Int64,2}:
>  2187293504
>  2151034912
>  2195818528
>  2147516504
>
> Now, Vector is a short form for Array{T, 1}. I would then expect to be 
> able to allocate a vector using something like this:
>
> julia> Vector(Int, 5)
> ERROR: MethodError: `convert` has no method matching convert(::Type{Array{
> T,1}},
>  ::Type{Int64}, ::Int64)
> This may have arisen from a call to the constructor Array{T,1}(...), 
> since type
> constructors fall back to convert methods in julia v0.4.
> Closest candidates are:
>   convert{T}(::Type{Nullable{T}}, ::T)
>   convert{T}(::Type{T}, ::T)
>   convert{T}(::Type{FloatRange{T}}, ::FloatRange{T<:FloatingPoint})
>   ...
>
> Could someone help me with the syntax? Do you have to use the Array form 
> every time you want to initiate a Arrat{T,1} with a certain length?
>
> Best regards,
> Kristoffer Carlsson
>


[julia-users] Re: Allocate a Vector

2015-02-04 Thread julia . elison . 2

This doesn't directly address your issue (which seems valid and simple to 
me) but you can use fill(0, 5) or fill( int64(0), 5) to create a vector 
with initialized values.  


On Wednesday, February 4, 2015 at 4:00:51 AM UTC-6, Kristoffer Carlsson 
wrote:
>
> If you want to allocate an Array you can simply write:
>
> julia> Array(Int, 5, 1)
> 10x1 Array{Int64,2}:
>  2187293504
>  2151034912
>  2195818528
>  2147516504
>
> Now, Vector is a short form for Array{T, 1}. I would then expect to be 
> able to allocate a vector using something like this:
>
> julia> Vector(Int, 5)
> ERROR: MethodError: `convert` has no method matching convert(::Type{Array{
> T,1}},
>  ::Type{Int64}, ::Int64)
> This may have arisen from a call to the constructor Array{T,1}(...), 
> since type
> constructors fall back to convert methods in julia v0.4.
> Closest candidates are:
>   convert{T}(::Type{Nullable{T}}, ::T)
>   convert{T}(::Type{T}, ::T)
>   convert{T}(::Type{FloatRange{T}}, ::FloatRange{T<:FloatingPoint})
>   ...
>
> Could someone help me with the syntax? Do you have to use the Array form 
> every time you want to initiate a Arrat{T,1} with a certain length?
>
> Best regards,
> Kristoffer Carlsson
>