I am trying to create an abstract subtype:
abstract type StructuredMatrix{T} <: AbstractMatrix{T}
However when i run this line code i get: “invalid redefinition of constant”
edit: i am using juno and entering command + enter to run the lines of code
You likely defined StructuredMatrix
previously in the same session. Redefining structs
requires that Julia be restarted.
(There also needs to be an end
at the end of the definition, but I assume this is just missing from the quoted code).
Thank that seems to fix things. Still getting comforable with things.
Now that we on the topic. May I also ask why the folllowing gives me an error:
abstract type StructuredMatrix{T} <: AbstractMatrix{T} end
struct HSS{T} <: StructuredMatrix{T}
A :: Array{T,2}
end
A = HSS{Int64}([2 2;
4 4])
When you created a subtype of AbstractMatrix
you implicitly promised that your type would support the interface of an AbstractArray
.
When you try to show
your HSS
object, that promise fails and show
tries to call a method (size
) which is not defined for HSS
.
1 Like