# Specifying argument types: Array{Float64, Integer}

I want to pass a `test` function an array of which can be either `Float64` or `Float32` data and have `1,2, ...` dimensions. I tried specifying the input argument as an array of type `Array{Float64, Integer}` but this didn’t work. What am I missing? Thanks!

``````x = Array{Float64, 1}([1, 2])
X = Array{Float64, 2}([1.0 1.0; 2.0 2.0])

isa(x, Array{Float64, Integer})  # false
isa(X, Array{Float64, Integer})  # false
isa(x, Array{Float64, 1})        # true
isa(X, Array{Float64, 2})        # true

const FloatData = Union{Float32, Float64}
function test(A :: Array{T, Ti}) where {T <: FloatData, Ti <: Integer}
println(typeof(A))
end

test(x)
test(X)
``````

`1` and `2` are values, not types, and `1 <: Integer` is not true, nor is `2 <: Integer`, so your `where {..., Ti <: Integer}` isn’t doing what you want.

What you are trying to specify is something like `where {T <: FloatData, Ti::Integer}`. That’s not possible in the language currently. Fortunately, it’s also completely unnecessary in this case, as you can just leave that parameter free with no performance impact. All of the following will work:

``````julia> function test1(A::Array{T, N}) where {T <: FloatData, N}
typeof(A)
end
test1 (generic function with 1 method)

julia> function test2(A::Array{T}) where {T <: FloatData}
typeof(A)
end
test2 (generic function with 1 method)

julia> function test3(A::Array{<:FloatData})
typeof(A)
end
``````
2 Likes