How do i create a custom supertype?

hi everyone. i have a function that can return as output results of type Matrix{Categorical{Floaxx, Vector{Floatxx}}}
where xx stands for the usual 16,32 or 64.

i was trying to create a test for such function that check that the output has this generic kind of type but i don’t know how to do it. if i evaluate results<: AbstractArray it works but it’s too generic for what i want to do

1 Like
julia> struct Categorical{S, T} end

julia> upper_bound = Matrix{Categorical{T, Vector{T}}} where {T <: AbstractFloat}
Array{Categorical{T, Vector{T}}, 2} where T<:AbstractFloat

julia> Matrix{Categorical{Float64, Vector{Float64}}} <: upper_bound
true

(In the first line I defined a parametric struct named Categorical just so the code would run. Yours should behave the same with the Categorical type that you are getting from somewhere.)

1 Like

thanks. it was from Distributions.jl, i should have added this information.
when i try to test the function i get the error

Expression: typeof(predict(la, X; predict_proba = true, ret_distr = true)) == upper_bound
Evaluated: Matrix{Categorical{Float32, Vector{Float32}}} == Array{Distributions.DiscreteNonParametric{Int64, T, Base.OneTo{Int64}, Vector{T}}, 2} where T<:AbstractFloat

I think you mean <: instead. BTW, please use Markdown code blocks in the future to make your posts readable.

ahhh true, i missed it when i copy pasted hahahha thanks to both.
i will use markdown in the future.

1 Like