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

@b Produces Infs in matrix #106

Closed
mipals opened this issue Jun 11, 2024 · 2 comments
Closed

@b Produces Infs in matrix #106

mipals opened this issue Jun 11, 2024 · 2 comments

Comments

@mipals
Copy link

mipals commented Jun 11, 2024

Hi there,

I might just be using the @b macro wrongly. But i was confused that in the following code

# This is on v. 1.2.1
using LinearAlgebra, Chairmarks
M = rand(3,3)
D = Diagonal(2ones(3))
@b lmul!(D,M) # M is not filled with Infs

the M gets filled with Infs.

@LilithHafner
Copy link
Owner

@b may execute the expression being benchmarked many times to get more reliable timings. In this case, when you call lmul!(D,M), all the elements of M are doubled. When @b does this repeatedly, eventually they overflow to Inf.

You can see a similar behavior with this

using LinearAlgebra
M = rand(3,3)
D = Diagonal(2ones(3))
for _ in 1:2000
    lmul!(D,M)
end
M # M is filled with Infs

And you can avoid that behavior by resetting the contents of M each iteration

using LinearAlgebra, Chairmarks
M = rand(3,3)
M0 = copy(M)
D = Diagonal(2ones(3))
@b lmul!(D,copyto!(M, M0))
M # M is not filled with Infs

@mipals
Copy link
Author

mipals commented Jun 11, 2024

Ahh, that makes sense. Thanks 👍

@mipals mipals closed this as completed Jun 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants