Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiplication involving transpose of a Matrix{<:SMatrix} #966

Closed
maltezfaria opened this issue Oct 14, 2021 · 6 comments
Closed

Multiplication involving transpose of a Matrix{<:SMatrix} #966

maltezfaria opened this issue Oct 14, 2021 · 6 comments
Labels
fix-in-base Fix needs some work in Base

Comments

@maltezfaria
Copy link

Hi,

I ran into the following (wrong?) behaviour when trying to multiply the following matrices of SMatrix:

using StaticArrays

A = @SMatrix rand(3, 3)
B = @SMatrix rand(3, 3)

blockA = fill(A, 3, 2)
blockB = fill(B, 3, 2)

val1 = blockA * transpose(blockB)
val2 = blockA * collect(transpose(blockB))

val1  val2 # false, by a lot

On my machine, the difference goes away if either A or B is changed to an MMatrix, which I found a bit puzzling. Here is some info on my version:

Julia Version 1.6.2
Commit 1b93d53fc4 (2021-07-14 15:36 UTC)
Platform Info:
  OS: macOS (x86_64-apple-darwin18.7.0)
  CPU: Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-11.0.1 (ORCJIT, skylake)
Environment:
  JULIA_EDITOR = code
  JULIA_NUM_THREADS = 8

Thanks!

@mateuszbaran
Copy link
Collaborator

I think this may be an issue with Julia matmul code here: https://github.com/JuliaLang/julia/blob/1b93d53fc4bb59350ada898038ed4de2994cce33/stdlib/LinearAlgebra/src/matmul.jl#L831 . SMatrix is an isbits type so it tries to do that tiled thing and fails.

Ref JuliaLang/julia#26008 .

@thchr
Copy link
Collaborator

thchr commented Oct 15, 2021

I guess this could be closed cf. the discussion in JuliaLang/julia#26008.

@maltezfaria
Copy link
Author

Thanks for tracking this. Should the problem be fixed with JuliaLang/julia#42309? I tried running the example above on the nightly build, and I still get the same behaviour.

@maltezfaria
Copy link
Author

I ran into another strange behaviour as well when trying to rely on the generic matmul for some operations on matrices of static matrices which I think should make sense. The example below illustrates the issue:

using StaticArrays
using LinearAlgebra

smat = @SMatrix [1 2; 3 4]

# mul! with matrices works fine
A = fill(smat, 1, 1)
B = fill(smat, 1, 1)
C = fill(smat, 1, 1)

mul!(copy(C),A,B,1,0)  A*B # ok
mul!(copy(C),A,B,1,1)  A*B + C # ok

# mul! with `matvecmul` throws an error
A = fill(smat, 1, 1)
B = fill(smat, 1)
C = fill(smat, 1)

mul!(copy(C),A,B,1,0)  A*B # ok
mul!(copy(C),A,B,1,1)  A*B + C # error with MulAddAmul

Thanks for the help!

@thchr
Copy link
Collaborator

thchr commented Oct 18, 2021

Thanks for tracking this. Should the problem be fixed with JuliaLang/julia#42309? I tried running the example above on the nightly build, and I still get the same behaviour.

Huh, yeah, I confirm that this is indeed not fixed after all. Testing on 1.8.0-DEV.763, the previous test case still fails.
I suppose this should be reopened then :(

@maltezfaria
Copy link
Author

Fixed in JuliaLang/julia#51804

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix-in-base Fix needs some work in Base
Projects
None yet
Development

No branches or pull requests

3 participants