Example for the type T3 [see its definition in the message]?

I’m really new to Julia, sorry about it.

After following the docs regarding Types, I was wondering how to build an explicit example, if possible, for the following type:

const T3 = Array{Array{T, 1} where T <: Real, 1}

T3 is “derived” from the type T1 given in Types · The Julia Language

Sure I can define:
a = T3() # returns the empty vector
but I’m not able to find/build up a more non-trivial example.

In a previous similar topic
(Correct argument type for ::Array{Array{<:Real,1},1}))
I could see that:
Array{Array{<:Real,1}, 1} === Array{Array{T,1} where T<:Real, 1} # returns true
but
Array{<:Real,1} === Array{T,1} where T<:Real # returns false
and
Array{Float64, 1} <: Array{<:Real, 1} # returns true
Array{Float64,1} <: Array{T,1} where T<:Real # returns true

I’m still a bit confused, sorry!

Thanks a lot for your help.

This page is a good starting point: Vector{Int} <: Vector{Real} is false??? · JuliaNotes.jl

Once you have read it, perhaps the following code will make sense to you. I think T4 (and not T3) is what you want to use here:

julia> const T3 = Vector{Vector{<:Real}}
Vector{Vector{T} where T<:Real} (alias for Array{Array{T, 1} where T<:Real, 1})

julia> const T4 = Vector{<:Vector{<:Real}}
Vector{<:Vector{<:Real}} (alias for Array{<:Array{<:Real, 1}, 1})

julia> v = [1, 2]
2-element Vector{Int64}:
 1
 2

julia> a = [v]
1-element Vector{Vector{Int64}}:
 [1, 2]

julia> a isa T3
false

julia> a isa T4
true

Thanks a lot for the page in “github.” It was very nice.

As for T3, then it seems T3 is almost an empty set, isn’t it?

As for T4, I see. I need another <: operator.

Just as a matter of curiosity, on defining T5 as follows:

const T5 = Array{Array{T, 1}, 1} where T<:Real

we find that

T4 === T5 # returns false

However, in many examples I tried, the same vectors belong at the same time to both T4 and T5. In the following code, one can freely replace T4 with T5, obtaining exactly the same outputs (either true or false).

[[1,2], [“hi”, “ciao”, “viv”]] isa T4, # false
[[“hi”, “ciao”], [1//2, 2.0]] isa T4, #false
[[“hi”, “ciao”], [1//2, 2.0], [[1,2], [2,3]]] isa T4, # false
[[1,2], [4.5, 6.7]] isa T4, # true
[[1,2], [4.5, 6.7, 6.1]] isa T4, # true
[[11,4], [-1+2im, 3+4im]] isa T4, # false
[[1.6, 2.0], [2, 3]] isa T4, # true
[[1.5,2], [2,3.6]] isa T4, # true
[[1; 2], [2; 3]] isa T4, # true
[[11,4], [-1+2im, 3+4im]] isa T4, # false
[[1, 2, 3, 4], [1.0, 4.0]] isa T4, # true
[[1; 2]; [2; 3]] isa T4, # false
[[1 2] [2 3]] isa T4, # false
[[1,2], [“hi”, “ciao”]] isa T4 # false

Thanks again a lot for the nice reply.

Yes I think T3 is basically useless.
As for T5, for some weird reason it is different from T3 due to the placement of the where:

julia> T3 = Vector{Vector{T} where T<:Real}
Vector{Vector{T} where T<:Real} (alias for Array{Array{T, 1} where T<:Real, 1})

julia> T5 = Vector{Vector{T}} where T<:Real
Array{Vector{T}, 1} where T<:Real

Very nice indeed [although it is indeed a bit weird].

In a mathematical sense, (I think that) if two sets have [exactly] the same elements, I would say they are equivalent, the same. So I also find it weird that T4 === T5 returns false (although I have not really shown that they share all the possible elements).

Thanks a lot for the answers I have learned a lot. Have a nice day.

I have found something which looks at least weird or just a simple mistake of mine.

All right, following your example, let me define

julia> const S1 = Vector{<:Vector{<:Number}}

This is very close to what you defined T4, but it should also contain say complex numbers. All right the following line returns something I do not understand:

julia> [[2.8, 3.8]] isa S1, [[3+1im, 2+5im]] isa S1, [[2.8, 3.8], [3+1im, 2+5im]] isa S1
(true, true, false)

but, as already said, I do not understand why. Some ideas about it?

To make it work I need, for example, to promote at least one of the Complex{Int} into a Complex{Float64}… but why?

Good remark! Let’s see what the type of this strange third object is (btw, don’t forget to enclose your code in triple backticks to make it easier to read, like I do):

julia> typeof([[2.8, 3.8], [3+1im, 2+5im]])
Vector{Vector} (alias for Array{Array{T, 1} where T, 1})

Since the two inner vectors have different element types, apparently Julia doesn’t bother to remember that they are both subtypes of Number, and instead recognizes the outer vector as containing Vector{Any} items. But we can force Julia to admit that these are indeed numbers:

julia> typeof(Vector{Number}[[2.8, 3.8], [3+1im, 2+5im]])
Vector{Vector{Number}} (alias for Array{Array{Number, 1}, 1})

Thanks a lot for your prompt answer. Also interesting.

By the way, adding another ComplexF64 vector fixes the bug. For example

julia> [[2.8, 3.8], [3+1im, 2+5im], [3, 5.0im]] isa S1
true

Also on considering the other type you have mentioned

julia> const S2 = Array{Array{Number, 1}, 1};
julia> [[2.8, 3.8]] isa S2
false

Ok, I will have to explore Julia more. In any case, it was very helpful. Thanks a lot for your time.