Modify a Package, and load it

Hello :slight_smile:
I am using a SemiDefiniteProgram to solve a Quantum problem. I give to the SDP some constraints, and it makes a QR factorization which lasts a very long time, and then it makes some iterations. During the long computation, I would like to know the dimensions of the matrix which is given to the function … So I have identified which function is called (it’s a QR decomposition), and I have added to the function a line which displays the dimensions of the Matrix :

println("size of A : $(size(A))")

But the compilation doesn’t load the modified file. The compilation loads some files in the " /cache/build/builder-amdci4-0 " directory.

So, here is the question : how to make Julia compile the LinearAlgebra Package, by reading the modified julia file lapack.jl ? I could remove the .julia/compiled directory, but it would download it again, and my modifications would never change anything …

Thanks a lots, for any answer !

PS : here is the modified file, and the modified function :
~/.julia/juliaup/julia-1.10.4/share/julia/stdlib/v1.10/LinearAlgebra/src/lapack.jl
function geqp3! line 395

You might be interested in this old thread:

If you’re just adding ad-hoc debug statements like these, it can be easier and more straightforward to just interactively define your changes. Just copy and paste the function you changed into an @eval block to define it in the appropriate module:

@eval LinearAlgebra.LAPACK function geqp3!(#= ... =#)
    # ...
end
5 Likes

Thanks mbauman, this is interesting to me. The function was defined inside a for-loop, that loops over some Type, so that, I’ve recopied a part of the loop. It gives something like this :

for (elty,relty) in ((:Float64,:Float64) , (:Float32,:Float32) , (:ComplexF64,:Float64) , (:ComplexF32,:Float32))

@eval LinearAlgebra.LAPACK function geqp3!(A::AbstractMatrix{$elty}, jpvt::AbstractVector{BlasInt}, tau::AbstractVector{$elty})
… … … some modified code here
end

I wrote it inside a file, then I included the file. But it gives out an error :

include(“modified lapack.jl”)
ERROR: LoadError: UndefVarError: geqp3 not defined

I’ve tried too to name the function under Main.LAPACK too but it doesn’t work. Do you know what is happening ? What is going on ? Thanks a lot !
bye :slight_smile:

Ah, yeah, that’s a tricky one, because the function is already being programmatically constructed with @eval in the original source. I think you can still do it, though, you want to wrap everything in the original source file in that outer @eval LinearAlgebra.LAPACK:

@eval LinearAlgebra.LAPACK begin
for (gebrd, gelqf, geqlf, geqrf, geqp3, geqrt, geqrt3, gerqf, getrf, elty, relty) in
    ((:dgebrd_,:dgelqf_,:dgeqlf_,:dgeqrf_,:dgeqp3_,:dgeqrt_,:dgeqrt3_,:dgerqf_,:dgetrf_,:Float64,:Float64),
     (:sgebrd_,:sgelqf_,:sgeqlf_,:sgeqrf_,:sgeqp3_,:sgeqrt_,:sgeqrt3_,:sgerqf_,:sgetrf_,:Float32,:Float32),
     (:zgebrd_,:zgelqf_,:zgeqlf_,:zgeqrf_,:zgeqp3_,:zgeqrt_,:zgeqrt3_,:zgerqf_,:zgetrf_,:ComplexF64,:Float64),
     (:cgebrd_,:cgelqf_,:cgeqlf_,:cgeqrf_,:cgeqp3_,:cgeqrt_,:cgeqrt3_,:cgerqf_,:cgetrf_,:ComplexF32,:Float32))
    @eval begin
        function geqp3!(A::AbstractMatrix{$elty}, jpvt::AbstractVector{BlasInt}, tau::AbstractVector{$elty})
            # ...
        end
    end
end
end

OK, I understand better why it doesn’t work.

Well, I’ve tried what you told me, and now I’ve got the following error :

ERROR: LoadError: UndefVarError: elty not defined

I don’t know why, this is too subtle for me ^^ Thanks a lot