Speeding up combination of Funs

nilsbecker
Wed, 28 May 2025 08:09:49 +0000
Numerics

I’m building up an ApproxFun.Fun by successively multiplying a lot of individual factors along a graph. The individual factors are themselves also Funs. The situation is similar to this fake code

factors = []
for n in nodes
  factor :: Fun = make_factor(parameters(node))
  push!(factors, factor)
end
result::Fun = prod(factors)

I would like to speed this up as much as possible, possibly by reducing allocation.

I found out that make_factor allocates in the MB range and runs tens of ms. The return value factor has a modest number of coefficients below 100, and is just a few KB. make_factor involves arithmetic with Funs, including:

exp(make_fun(t2) - make_fun(t1)) where make_fun constructs a Fun from float parameters t1,t2 and

Fun(space) / (Fun(space) + make_fun(t3))

Basically, I’m wondering if I can fuse arithmetic operations on Fun to avoid constructing intermediate expansions, or use inplace transformation of expansions to make this faster. Also, is there a clever way to construct the product in the end?

The space in question is a Chebyshev(0..1)

16 posts - 4 participants