Given this definition of a custom number type:
struct Node <: Number
end
export Node
Base.:*(a::Node, b::Node) = Node()
Base.:+(a::Node, b::Node) = Node()
why does this
julia> a = Node();b=Node();
julia> A = [a b;a b]
2×2 Matrix{Node}:
Node() Node()
Node() Node()
julia> bvec = [a,b]
2-element Vector{Node}:
Node()
Node()
julia> A*b
2×2 Matrix{Node}:
Node() Node()
Node() Node()
give a different result than this:
julia> [a b;a b]*[a,b]
ERROR: MethodError: no method matching Node(::Int64)
Closest candidates are:
(::Type{T})(::T) where T<:Number
@ Core boot.jl:792
Node()
@ MatrixX C:\tmp\Matrix\src\MatrixX.jl:4
(::Type{T})(::AbstractChar) where T<:Union{AbstractChar, Number}
@ Base char.jl:50
...
Stacktrace:
[1-6] ⋮ internal
@ Base, LinearAlgebra, Unknown
[7] *(A::Matrix{Node}, x::Vector{Node})
@ LinearAlgebra C:\Users\seatt\.julia\juliaup\julia-1.9.1+0.x64.w64.mingw32\share\julia\stdlib\v1.9\LinearAlgebra\src\matmul.jl:56
[8] top-level scope
@ REPL[12]:1
Use `err` to retrieve the full stack trace.
Is there some other Base method that has to be defined on Node to make this work?