RFQ: InplaceLinalg

proposal
#1

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

@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

1 Like
#2

Perhaps you could provide a link to the package?

#3
2 Likes
#4

Thanks!

#5

Also https://github.com/lopezm94/SugarBLAS.jl.

1 Like
#6

Also

1 Like
#7

Also https://github.com/tkluck/InPlace.jl .

2 Likes
#8

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.

#9

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?

1 Like
#10

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.