# How can I get the CS decomposition of a matrix?

**URL:** <https://discourse.julialang.org/t/how-can-i-get-the-cs-decomposition-of-a-matrix/34499>\
**Category:** Numerics\
**Tags:** linearalgebra\
**Created:** [February 12, 2020, 1:22am UTC](https://discourse.julialang.org/t/how-can-i-get-the-cs-decomposition-of-a-matrix/34499 "2020-02-12T01:22:39Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Deniz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/deniz/32/10151_2.png) [@Deniz](https://discourse.julialang.org/u/Deniz)\
**Post date:** [February 12, 2020, 1:22am UTC](https://discourse.julialang.org/t/how-can-i-get-the-cs-decomposition-of-a-matrix/34499/1 "2020-02-12T01:22:39Z")

</div>

There seems to be no function in any well-known Julia library to obtain the CS decomposition of a matrix. There is a function `CUNCSD ` in LAPACK, but it is not available in Julia by default. Maybe I can call that function from Julia?

---

<div class="post-metadata">

**Author:** ![longemen3000](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/longemen3000/32/7298_2.png) [@longemen3000](https://discourse.julialang.org/u/longemen3000)\
**Post date:** [February 12, 2020, 2:38am UTC](https://discourse.julialang.org/t/how-can-i-get-the-cs-decomposition-of-a-matrix/34499/2 "2020-02-12T02:38:19Z")

</div>

lapack comes with julia in the module `LinearAlgebra.LAPACK`, but i can’t find a julia interface to to `CUNCSD` in particular. in this file are the c calls to the lapack routines:

> <https://github.com/JuliaLang/julia/blob/master/stdlib/LinearAlgebra/src/lapack.jl>

if you know the conventions of calling directly a lapack routine, maybe you can a direct c call.

Also, this merits an issue on the Julia repo

---

<div class="post-metadata">

**Author:** ![Deniz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/deniz/32/10151_2.png) [@Deniz](https://discourse.julialang.org/u/Deniz)\
**Post date:** [February 12, 2020, 2:49am UTC](https://discourse.julialang.org/t/how-can-i-get-the-cs-decomposition-of-a-matrix/34499/3 "2020-02-12T02:49:48Z")

</div>

Why is it actually that Julia doesn’t have an interface for all of LAPACK? The wrappers must be automatically generated, right?

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [February 12, 2020, 2:51am UTC](https://discourse.julialang.org/t/how-can-i-get-the-cs-decomposition-of-a-matrix/34499/4 "2020-02-12T02:51:40Z")

</div>

> [@Deniz](#):
>
> The wrappers must be automatically generated, right?

No, they are hand-written. Writing high-level wrappers for a Fortran library like this is non-trivial to automate, especially since there are four variants of every subroutine (real/complex and single/double precision), sometimes with subtly different calling conventions (e.g. different workspace sizes).

Of course, nothing prevents you from adding a wrapper for any LAPACK routine you want using `ccall` in user code — there’s nothing special about the code in the Julia standard library.

---

<div class="post-metadata">

**Author:** ![Deniz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/deniz/32/10151_2.png) [@Deniz](https://discourse.julialang.org/u/Deniz)\
**Post date:** [February 12, 2020, 3:04am UTC](https://discourse.julialang.org/t/how-can-i-get-the-cs-decomposition-of-a-matrix/34499/5 "2020-02-12T03:04:41Z")

</div>

I see. How would a wrapper for `CUNCSD` look like?

The specification is here: [http://www.netlib.org/lapack/explore-html/d3/db9/group\_\_complex\_o\_t\_h\_e\_rcomputational\_ga55ab9c7b1a2bce552037cf519201e950.html](http://www.netlib.org/lapack/explore-html/d3/db9/group__complex_o_t_h_e_rcomputational_ga55ab9c7b1a2bce552037cf519201e950.html)

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [February 12, 2020, 3:06am UTC](https://discourse.julialang.org/t/how-can-i-get-the-cs-decomposition-of-a-matrix/34499/6 "2020-02-12T03:06:49Z")

</div>

> [@Deniz](#):
>
> I see. How would a wrapper for `CUNCSD` look like?

Look at the other wrappers in lapack.jl; adapting one for `*uncsd` shouldn’t be too hard.

---

<div class="post-metadata">

**Author:** ![dlfivefifty](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dlfivefifty/32/1959_2.png) [@dlfivefifty](https://discourse.julialang.org/u/dlfivefifty)\
**Post date:** [February 12, 2020, 10:16am UTC](https://discourse.julialang.org/t/how-can-i-get-the-cs-decomposition-of-a-matrix/34499/7 "2020-02-12T10:16:16Z")

</div>

> [@Deniz](#):
>
> Why is it actually that Julia doesn’t have an interface for all of LAPACK? The wrappers must be automatically generated, right?

There are a lot in LAPACK that are non-standard, for example, QL, LQ, RQ decompositions, that would be quite a bit of work to wrap.

I’ve set up [MatrixFactorizations.jl](https://github.com/JuliaMatrices/MatrixFactorizations.jl) as a home for other matrix factorizations. At the moment it just includes QL and a version of QR that allows more general types.
