# Modify a Package, and load it

**URL:** <https://discourse.julialang.org/t/modify-a-package-and-load-it/117105>\
**Category:** General Usage\
**Created:** [July 16, 2024, 3:24pm UTC](https://discourse.julialang.org/t/modify-a-package-and-load-it/117105 "2024-07-16T15:24:57Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![gustave\_Robichon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gustave_robichon/32/207522_2.png) [@gustave\_Robichon](https://discourse.julialang.org/u/gustave_Robichon)\
**Post date:** [July 16, 2024, 3:24pm UTC](https://discourse.julialang.org/t/modify-a-package-and-load-it/117105/1 "2024-07-16T15:24:57Z")

</div>

Hello 🙂  
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

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [July 16, 2024, 3:40pm UTC](https://discourse.julialang.org/t/modify-a-package-and-load-it/117105/2 "2024-07-16T15:40:02Z")

</div>

You might be interested in this old thread:

> [@Testing changes to stdlib without remaking the whole of Julia](https://discourse.julialang.org/t/testing-changes-to-stdlib-without-remaking-the-whole-of-julia/11998):
>
> If I make a change in stdlib/, should I make the whole Julia, or is it possible to run the unit tests for the particular library without remaking everything? I could not figure out how.

---

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [July 16, 2024, 3:42pm UTC](https://discourse.julialang.org/t/modify-a-package-and-load-it/117105/3 "2024-07-16T15:42:09Z")

</div>

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:

```julia
@eval LinearAlgebra.LAPACK function geqp3!(#= ... =#)
    # ...
end

```

---

<div class="post-metadata">

**Author:** ![gustave\_Robichon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gustave_robichon/32/207522_2.png) [@gustave\_Robichon](https://discourse.julialang.org/u/gustave_Robichon)\
**Post date:** [July 17, 2024, 12:38pm UTC](https://discourse.julialang.org/t/modify-a-package-and-load-it/117105/4 "2024-07-17T12:38:33Z")

</div>

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 🙂

---

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [July 17, 2024, 1:26pm UTC](https://discourse.julialang.org/t/modify-a-package-and-load-it/117105/5 "2024-07-17T13:26:52Z")

</div>

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`:

```Julia
@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
```

---

<div class="post-metadata">

**Author:** ![gustave\_Robichon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gustave_robichon/32/207522_2.png) [@gustave\_Robichon](https://discourse.julialang.org/u/gustave_Robichon)\
**Post date:** [July 17, 2024, 1:50pm UTC](https://discourse.julialang.org/t/modify-a-package-and-load-it/117105/6 "2024-07-17T13:50:26Z")

</div>

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
