# Writing custom LAPACK bindings

**URL:** https://discourse.julialang.org/t/writing-custom-lapack-bindings/60338
**Category:** New to Julia
**Created:** [April 30, 2021, 7:01pm UTC](https://discourse.julialang.org/t/writing-custom-lapack-bindings/60338 "2021-04-30T19:01:03Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![PatrickS](https://avatars.discourse-cdn.com/v4/letter/p/ac91a4/32.png) [@PatrickS](https://discourse.julialang.org/u/PatrickS)
#### Post date: [April 30, 2021, 7:01pm UTC](https://discourse.julialang.org/t/writing-custom-lapack-bindings/60338/1 "2021-04-30T19:01:03Z")

</div>

Hi,  
I’m relatively new to Julia. I’ve been using it to prototype some linear algebra methods. I now have need for some LAPACK methods which are not included in `LinearAlgebra.LAPACK`, (specifically `dtpqrt` and `dtpmqrt`). I think I must be missing something basic, because even just copying an existing binding isn’t working.

Here is a minimal example, which I’ve tried in both 1.6 and 1.7:

```julia
using LinearAlgebra
using LinearAlgebra: BlasInt, require_one_based_indexing
using LinearAlgebra.LAPACK: liblapack, chkstride1, chklapackerror
using LinearAlgebra.BLAS: @blasfunc

function geqrt!(A::AbstractMatrix{Float64}, T::AbstractMatrix{Float64})
    require_one_based_indexing(A, T)
    chkstride1(A)
    m, n = size(A)
    minmn = min(m, n)
    nb = size(T, 1)
    if nb > minmn
        throw(ArgumentError("block size $nb > $minmn too large"))
    end
    lda = max(1, stride(A,2))
    work = Vector{Float64}(undef, nb*n)
    if n > 0
        info = Ref{BlasInt}()
        ccall((@blasfunc(:dgeqrt_), liblapack), Cvoid,
            (Ref{BlasInt}, Ref{BlasInt}, Ref{BlasInt}, Ptr{Float64},
                Ref{BlasInt}, Ptr{Float64}, Ref{BlasInt}, Ptr{Float64},
                Ptr{BlasInt}),
                m, n, nb, A,
                lda, T, max(1,stride(T,2)), work,
                info)
        chklapackerror(info[])
    end
    A, T
end

```

Calling this gives

```julia
ERROR: could not load symbol ":dgeqrt_64_":
dlsym(0x7fb7a1d04d50, :dgeqrt_64_): symbol not found

```

Thanks in advance for any assistance.

---

<div class="post-metadata">

### Author: ![Seif\_Shebl](https://avatars.discourse-cdn.com/v4/letter/s/eada6e/32.png) [@Seif\_Shebl](https://discourse.julialang.org/u/Seif_Shebl)
#### Post date: [April 30, 2021, 11:19pm UTC](https://discourse.julialang.org/t/writing-custom-lapack-bindings/60338/2 "2021-04-30T23:19:16Z")

</div>

I’m not sure if I fully understand what you want, but what is the problem with just ` LinearAlgebra.LAPACK.geqrt!(A, T)`?

---

<div class="post-metadata">

### Author: ![Ralph\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ralph_smith/32/10344_2.png) [@Ralph\_Smith](https://discourse.julialang.org/u/Ralph_Smith)
#### Post date: [May 1, 2021, 2:45am UTC](https://discourse.julialang.org/t/writing-custom-lapack-bindings/60338/3 "2021-05-01T02:45:58Z")

</div>

You’ve stumbled on a subtlety of the way symbols are treated in macro expressions. Instead of `@blasfunc(:dgeqrt_)` you want `@blasfunc(dgeqrt_)`.

---

<div class="post-metadata">

### Author: ![PatrickS](https://avatars.discourse-cdn.com/v4/letter/p/ac91a4/32.png) [@PatrickS](https://discourse.julialang.org/u/PatrickS)
#### Post date: [May 3, 2021, 12:58pm UTC](https://discourse.julialang.org/t/writing-custom-lapack-bindings/60338/4 "2021-05-03T12:58:03Z")

</div>

> [@Ralph\_Smith](#):
>
> You’ve stumbled on a subtlety of the way symbols are treated in macro expressions. Instead of `@blasfunc(:dgeqrt_)` you want `@blasfunc(dgeqrt_)` .

Ah, that was it. Thank you!

> [@Seif\_Shebl](#):
>
> I’m not sure if I fully understand what you want, but what is the problem with just ` LinearAlgebra.LAPACK.geqrt!(A, T)` ?

For a bit more context, I’m implementing a method where I need to update an existing QR factorization by either removing a few columns, or permuting a block of columns on the left to the right, so update `Q R = [A1, A2]` to `Q' R' = [A2, A1]` (`'` isn’t transpose here, just denotes the modified factorization). `tpqrt` can be used to do this more cheaply than computing the new factorization from scratch.
