# RFQ: InplaceLinalg

**URL:** <https://discourse.julialang.org/t/rfq-inplacelinalg/23195>\
**Category:** Numerics\
**Tags:** proposal\
**Created:** [April 16, 2019, 9:40am UTC](https://discourse.julialang.org/t/rfq-inplacelinalg/23195 "2019-04-16T09:40:14Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![davidavdav](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/davidavdav/32/1065_2.png) [@davidavdav](https://discourse.julialang.org/u/davidavdav)\
**Post date:** [April 16, 2019, 9:40am UTC](https://discourse.julialang.org/t/rfq-inplacelinalg/23195/1 "2019-04-16T09:40:14Z")

</div>

Hello,

We’ve noticed that the broadcasting assignment operator `.=` does a good job in in-place assignment of the LHS in some cases, but not so in others. I suppose `.=` is really about broadcasting, and not about in-place updating.

We’re currently experimenting with a macro/julia package that tries to find the best in-place use of `LinearAlgebra.BLAS` `gemm!()`, `syrk!()` etc. using a syntax

```julia
@inplace C = A * B
@inplace C += A * B
@inplace C += alpha * A * B
@inplace C *= beta
@inplace (C *= beta) += alpha * A * B

```

to update a matrix/vector `C` in-place using the appropriate BLAS calls.

Perhaps someone already implemented such facility, or perhaps people have comments or ideas regarding this.

Cheers

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [April 16, 2019, 10:27am UTC](https://discourse.julialang.org/t/rfq-inplacelinalg/23195/2 "2019-04-16T10:27:31Z")

</div>

> [@davidavdav](#):
>
> perhaps people have comments or ideas

Perhaps you could provide a link to the package?

---

<div class="post-metadata">

**Author:** ![mohamed82008](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mohamed82008/32/18171_2.png) [@mohamed82008](https://discourse.julialang.org/u/mohamed82008)\
**Post date:** [April 16, 2019, 10:50am UTC](https://discourse.julialang.org/t/rfq-inplacelinalg/23195/3 "2019-04-16T10:50:13Z")

</div>

[https://github.com/simonbyrne/InplaceOps.jl](https://github.com/simonbyrne/InplaceOps.jl)

---

<div class="post-metadata">

**Author:** ![davidavdav](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/davidavdav/32/1065_2.png) [@davidavdav](https://discourse.julialang.org/u/davidavdav)\
**Post date:** [April 16, 2019, 11:17am UTC](https://discourse.julialang.org/t/rfq-inplacelinalg/23195/4 "2019-04-16T11:17:58Z")

</div>

Thanks!

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [April 16, 2019, 11:30am UTC](https://discourse.julialang.org/t/rfq-inplacelinalg/23195/5 "2019-04-16T11:30:02Z")

</div>

Also [https://github.com/lopezm94/SugarBLAS.jl](https://github.com/lopezm94/SugarBLAS.jl).

---

<div class="post-metadata">

**Author:** ![tkf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkf/32/17635_2.png) [@tkf](https://discourse.julialang.org/u/tkf)\
**Post date:** [April 16, 2019, 8:52pm UTC](https://discourse.julialang.org/t/rfq-inplacelinalg/23195/6 "2019-04-16T20:52:29Z")

</div>

Also

> **[GitHub - JuliaArrays/LazyArrays.jl: Lazy arrays and linear algebra in Julia](https://github.com/JuliaArrays/LazyArrays.jl)**
>
> Lazy arrays and linear algebra in Julia. Contribute to JuliaArrays/LazyArrays.jl development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![tkluck](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkluck/32/15769_2.png) [@tkluck](https://discourse.julialang.org/u/tkluck)\
**Post date:** [April 16, 2019, 9:07pm UTC](https://discourse.julialang.org/t/rfq-inplacelinalg/23195/7 "2019-04-16T21:07:46Z")

</div>

Also [GitHub - tkluck/InPlace.jl: InPlace.jl - in-place operations where possible](https://github.com/tkluck/InPlace.jl) .

---

<div class="post-metadata">

**Author:** ![davidavdav](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/davidavdav/32/1065_2.png) [@davidavdav](https://discourse.julialang.org/u/davidavdav)\
**Post date:** [April 17, 2019, 12:38pm UTC](https://discourse.julialang.org/t/rfq-inplacelinalg/23195/8 "2019-04-17T12:38:15Z")

</div>

Thanks, there are a lot of packages with support for inplace assignment. The closest to what we would want is SugarBLAS.jl, since we’re also targeting to exploit the full range of BLAS functionality, but we’re aiming for just a single macro, similar to InPlace.jl.

For now we’ll continue experimenting a little more.

---

<div class="post-metadata">

**Author:** ![tkluck](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkluck/32/15769_2.png) [@tkluck](https://discourse.julialang.org/u/tkluck)\
**Post date:** [April 17, 2019, 5:55pm UTC](https://discourse.julialang.org/t/rfq-inplacelinalg/23195/9 "2019-04-17T17:55:12Z")

</div>

If you’re evaluating this, do check `InPlace.jl`’s implementation details. There’s hardly any magic in the macro – it’s happening through multiple dispatch. I’d be super open to adding linear algebra functions as well, and also to sharing ownership (i.e. so you don’t have to wait for me to merge pull requests).

The one thing is that it doesn’t support nested operations at the moment. Maybe you have a good idea on how to do that?

---

<div class="post-metadata">

**Author:** ![davidavdav](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/davidavdav/32/1065_2.png) [@davidavdav](https://discourse.julialang.org/u/davidavdav)\
**Post date:** [April 18, 2019, 11:49am UTC](https://discourse.julialang.org/t/rfq-inplacelinalg/23195/10 "2019-04-18T11:49:01Z")

</div>

Hi,

I think for us, nested operations are outside the scope—rather than rebuilding a whole parser our aim for now is to have access to all of BLAS with an easier syntax—very much like SugarBLAS.jl.

We’ve discussed whether the macro should recognize things like `@inplace C += (A+B)' * (A+B)` and optimize out the `A+B` and code for `syrk!()` but decided against it—it is better if the user does that kind of optimization with an extra statement `D = A + B`.
