I have defined two structs in Julia: RankOneMatrix
and FirstRankOneMatrix
.
struct RankOneMatrix{T} <: AbstractMatrix{T}
v::AbstractVector{T}
w::AbstractVector{T}
end
RankOneMatrix(v) = RankOneMatrix(v, v)
struct FirstRankOneMatrix
v::Vector{Float64}
w::Vector{Float64}
end
FirstRankOneMatrix(v) = FirstRankOneMatrix(v, v)
When I initialize FirstRankOneMatrix
with a vector, it outputs the values stored in a 1-D array as expected. However, when I initialize RankOneMatrix
, it outputs a 2-D array of the outer products.
I’m new to Julia and I’m struggling to understand this behavior. Could this be related to the fact that RankOneMatrix
is a subtype of AbstractMatrix
? Any insights would be appreciated.
New contributor
Anwesh Saha is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.