p-gw / FactorRotations.jl

Rotation methods for factor analysis and principal component analysis in Julia
https://p-gw.github.io/FactorRotations.jl/
MIT License
7 stars 2 forks source link

Switch to in-place `criterion_and_gradient!` #57

Closed p-gw closed 6 months ago

p-gw commented 6 months ago

As noted in #54, a switch to an in-place gradient calculation could speed up performance by avoiding array allocations:

But if in the long run you consider switching to a unified in-place _criterion_andgradient!(grad::Union{AbstractVector, Nothing}, ...), which would skip gradient calculation if grad === nothing, this PR would be irrelevant. Right now the profiling shows that for a 62x24 matrix rotation ~10% is spent in the array allocation (both gradient calculation and projection).

alyst commented 6 months ago

This is a profiling of a varimax rotation of 782x32 matrix: image

Looks like in gradient calculation 33% of the time is spent in array allocation, 33% in copying.