Open harrisonritz opened 7 months ago
Rather than special-casing particular BLAS functions, I think it would make more sense to define methods for the auxiliary functions used by the existing methods. For example, gemm!
works as-is with one or more PDMat
arguments by defining
Base.strides(X::PDMat) = strides(X.mat)
Base.unsafe_convert(::Type{Ptr{T}}, X::PDMat{T}) where {T} = Base.unsafe_convert(Ptr{T}, X.mat)
Agree that's much better!
If we use the AbstractPDMat
type, could add to generics.jl
?
I'm happy to file PR tomorrow.
At least as written, what I wrote before isn't generic because the mat
field access is specific to the PDMat
type; other AbstractPDMat
s such as PDiagMat
don't have such a field. There also isn't a way to generically retrieve a "conventional" AbstractMatrix
given an AbstractPDMat
without making a copy. The AbstractPDMat
subtypes defined in this package do all have Matrix
constructor methods, but that makes a copy.
So all that is to say, I think it would have to go in src/pdmat.jl
and remain specific to PDMat
, at least for now.
The product of two symmetric matrices is generally not symmetric
julia> A = randn(3,3) |> t -> t't
3×3 Matrix{Float64}:
0.276842 -0.0227288 0.31778
-0.0227288 1.82429 1.71879
0.31778 1.71879 2.08469
julia> B = randn(3,3) |> t -> t't
3×3 Matrix{Float64}:
1.17375 -1.0618 -2.01181
-1.0618 1.01923 1.72527
-2.01181 1.72527 5.20746
julia> A*B
3×3 Matrix{Float64}:
-0.290238 0.23114 1.05866
-5.4216 4.84889 12.1436
-5.64603 5.01109 13.182
and therefore cannot be a PDMat
so the proposed definition can't work.
Futhermore, the BLAS nomenclature "GE" means general as in "no structure" so I don't think it would make sense to overload gemm
for structured matrices like PDMat
even if the result matrix was unstructured such that the operation wasn't incorrect. Instead, we could maybe define some mul!
methods.
Ah right, math...
I think mul!
already works as-is though? At least judging by its use in the OP
love the package!
BLAS.gemm!
fails for anyPDMat
arguments unless you passa.mat
. Maybe something like could be more general:Benchmarks seem to run just as fast. minimal example: