>
> (Don't be misled by the printout after the line, its the right hand side
> of the assignment, not a)
>
yes, you're right, i was not aware of that. it seems julia will implicitly
convert Array{DataType, 1} to Array{Type{T}, 1} without checking further
type information.
i don't know whether this is the right behavior or a bug as @Yichao Yu
mentioned. i'm wondering what's the relationship between the type of an
element of the array and the eltype of the array.
julia> a = Array{Int64, 1}(1)
1-element Array{Int64,1}:
4635899120
julia> a[1] = 1.0
1.0
jjulia> typeof(a[1]) <: eltype(a)
true
`typeof(a[1]) <: eltype(a)` this rule is not true in the case of
`Array{Type{T}}`, this is because there is no clear relationship between
`DataType` and `Type{S}`, where S is a TypeVar with its `ub != Any`.
在 2015年10月10日星期六 UTC+8上午6:03:42,[email protected]写道:
>
> The line:
>
> a[:] = [Int64, Float32]
>
> Sets the values of the elements of a[] but does not change its type.
>
> (Don't be misled by the printout after the line, its the right hand side
> of the assignment, not a)
>
> Cheers
> Lex
>
> On Saturday, October 10, 2015 at 3:32:56 AM UTC+10, Yichao Yu wrote:
>>
>> On Fri, Oct 9, 2015 at 1:24 PM, Gnimuc Key <[email protected]> wrote:
>> > so there are no difference between Array{DataType, 1} and
>> Array{Type{Int64},
>> > 1} just as the example showed? what about `foo(x::Array{DataType,1})
>> =
>> x`
>> > and `foo(x::Array{Type{Int64}, 1})`?
>>
>> I think this is a bug in codegen. The intrinsic itself looks fine
>>
>> julia> Base.arrayset(Vector{Type{Int}}(2), Float32, 1)
>> ERROR: TypeError: arrayset: expected Type{Int64}, got Type{Float32}
>>
>>
>> >
>> > 在 2015年10月10日星期六 UTC+8上午1:17:25,Cedric St-Jean写道:
>> >>
>> >> Array{Int64, 1} is an array of Ints. Type{Int64} is the type of a
>> type, so
>> >> Array{Type{Int64}} is an array of types.
>> >>
>> >> On Friday, October 9, 2015 at 1:11:25 PM UTC-4, Gnimuc Key wrote:
>> >>>
>> >>> i think `Array{Type{Int64},1}` is a vector whose element type is
>> >>> constrained to `Int64`, but i'm confused by the outputs of the code
>> below:
>> >>>
>> >>>
>> >>> julia> a = Array{Type{Int64}}(2)
>> >>> 2-element Array{Type{Int64},1}:
>> >>> #undef
>> >>> #undef
>> >>>
>> >>> julia> a[:] = [Int64, Float32]
>> >>> 2-element Array{DataType,1}:
>> >>> Int64
>> >>> Float32
>> >>>
>> >>> julia> isa(a[2], eltype(a))
>> >>> false
>> >>>
>> >>>
>> >>> julia> a
>> >>> 2-element Array{Type{Int64},1}:
>> >>> Int64
>> >>> Float32
>> >>>
>> >>>
>> >>> the last line is so wired.
>>
>