tpapp / TransformVariables.jl

Transformations to contrained variables from ℝⁿ.
Other
66 stars 14 forks source link

Transformations involving `StaticArray` is not type stable #112

Closed junyuan-chen closed 1 year ago

junyuan-chen commented 1 year ago

One important benefit of using StaticArray is to avoid the memory allocation required for an Array. For now, there is type instability somewhere that results in allocations for type inference, which largely undermines the advantages of using StaticArray over Array.

using TransformVariables, StaticArrays, BenchmarkTools

tr = as(SVector{3, Float64})
a = rand(3)
julia> @btime transform($tr, $a)
  39.816 ns (2 allocations: 32 bytes)
3-element SVector{3, Float64} with indices SOneTo(3):
 0.8664582577624973
 0.27172807097850415
 0.5758008759582858

From @code_warntype, I see that there is type stability issue with transform_with.

tpapp commented 1 year ago

Thanks for the bug report and the MWE. Sorry for the delay, the fix was a bit tricky, will release a new version with it as soon as CI tests finish.