TimSiebert1 / ADOLC.jl

MIT License
12 stars 2 forks source link

Add some methods for CxxMatrix #14

Closed j-fu closed 3 months ago

j-fu commented 3 months ago

Regarding Regarding https://github.com/TimSiebert1/ADOLC.jl/pull/13#issuecomment-2182419666: Why not just keep CxxMatrix as is and add the missing methods to make it a full fledged AbstractMatrix ?

TimSiebert1 commented 3 months ago

We could. I just wanted to copy the values from the C++ matrix (or vector, or tensor) to the Julia matrix automatically and thought a combined struct would be a "smooth" way to handle this. However, we could also accept pre-allocated C++ and Julia data as input for the derivative! driver and do data transfer inside. What do you think?

j-fu commented 3 months ago

For me it is not clear why the copy is needed. The finalize already works, What would be a situation where a CxxMatrix would not work in place of a Matrix? It is an AbstractMatrix and inherits all the methods of AbstractMatrix, e.g:

A=ADOLC.array_types.CxxMatrix{Cdouble}(rand(2,2))
2×2 ADOLC.array_types.CxxMatrix{Float64}:
0.825202  0.343862
0.855653  0.639062

julia> A\rand(2)
2-element Vector{Float64}:
0.6624650987529754
-0.1567069631504887
j-fu commented 3 months ago

https://github.com/JuliaArrays/ArrayInterface.jl seems to allow a more precise specification of what can be done with a specific array type.

TimSiebert1 commented 3 months ago

Ooooh. Didn't know that it is enough to have an AbstractMatrix.

I will add the support of the CxxMatrix (and the other types) over the weekend.