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

Fix splatting #167

Merged

Conversation

alyst
Copy link
Contributor

@alyst alyst commented Mar 11, 2024

With my model I have hit the limit of the arguments that splatting supports (in particular, I was getting StackOverflowError in matrix derivative function).
So I've fixed the problematic spatting instances (op(data...)) with the faster alternative reduce(op, data).
In particular, it is much faster for special cases like hcat, because there is a specialized version of reduce(hcat, x) .

Copy link

codecov bot commented Mar 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 67.28%. Comparing base (51ca4a9) to head (d0b2fee).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #167   +/-   ##
=======================================
  Coverage   67.28%   67.28%           
=======================================
  Files          51       51           
  Lines        2494     2494           
=======================================
  Hits         1678     1678           
  Misses        816      816           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@Maximilian-Stefan-Ernst Maximilian-Stefan-Ernst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for these fixes. I have one small suggestion - when I benchmark the code, the mapreduce version takes quite long for some reason, so I swapped the order (transpose after concatenation).

using BenchmarkTools

a = [rand(10) for _ in 1:100]

transpose(reduce(hcat, a)) == mapreduce(transpose, vcat, a) # true

@benchmark transpose(reduce(hcat, $a))  # 923.459 ns

@benchmark mapreduce(transpose, vcat, $a) # 49.851 μs

src/additional_functions/helper.jl Outdated Show resolved Hide resolved
@Maximilian-Stefan-Ernst Maximilian-Stefan-Ernst merged commit 5a9ab2b into StructuralEquationModels:main Mar 17, 2024
10 checks passed
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 this pull request may close these issues.

2 participants