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

'v_a_vT' is slow and named wrong #343

Closed
bvdmitri opened this issue Aug 28, 2023 · 0 comments · Fixed by #347
Closed

'v_a_vT' is slow and named wrong #343

bvdmitri opened this issue Aug 28, 2023 · 0 comments · Fixed by #347
Assignees

Comments

@bvdmitri
Copy link
Member

bvdmitri commented Aug 28, 2023

The function v_a_vT does not do what the name suggests, instead of v * a * v' it does v * v' * a. It works OK, because in the only context we use this function a is a number, so it commutes, but the name is misleading.

Moreover, a naive implementation of v * v' * a outperforms our version by a factor of 4:

v = ones(3)

@btime RxInfer.ReactiveMP.v_a_vT($v, 1)
102.908 ns (1 allocation: 128 bytes)
3×3 Matrix{Float64}:
 1.0  1.0  1.0
 1.0  1.0  1.0
 1.0  1.0  1.0
foo(v, a) = v * v' * a

@btime foo($v, 1)
26.674 ns (1 allocation: 128 bytes)
3×3 Matrix{Float64}:
 1.0  1.0  1.0
 1.0  1.0  1.0
 1.0  1.0  1.0
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

Successfully merging a pull request may close this issue.

2 participants