How to speed up spline calculation (using cscvn)

8 views (last 30 days)
Hello dear MATLAB community,
I have a problem by using the 'cscvn' function to calculate spline coefficients. I have an optimization problem and during this optimization problem the spline interpolation with cscvn is done to evaluate the function. Actually the calculation of the spline coefficients takes around 30% of the total calculation time.
Do you have an idea why this takes so long and is there a possibility to speed up this calculation? I read something about 'JIT acceleration' and that this acceleration does not work in 'loops that call non builtin functions'. Actually I don´t really understand what this exactly tells me and if there probably IS a way to speed up the spline calculation.
Thank you for your help.
David

Accepted Answer

Stephen23
Stephen23 on 13 Oct 2014
Edited: Stephen23 on 13 Oct 2014
There will always be some part of your scripts that requires some amount of running time (ie the most computation), and maybe even a significant proportion of the total running time. The other lines of code in your screenshot are array allocations and calls to zeros, both of which are many times simpler than spline fitting. Do you expect spline fitting to also take <0.01 seconds? Fitting a spline 976 times in 1.61 seconds, complete with error checking and other input handling... is that so slow?
How big are your data arrays?
Possibilities to speed up the script:
  • If WayPoints does not change between some iterations, then you can calculate it once and use the same values for several/all iterations.
  • Open the cscvn Mfile (if it has one), remove all the error-checking and array-wrangling at the start, use profile to check which parts you actually use, and save a local copy with only the parts that you need (use a different function name, and do not save over the original Mfile).
  1 Comment
David
David on 13 Oct 2014
I know that some part takes longer and some part is faster in the calculation. I was just wondering that the calculation of the spline coefficients takes the most time in the optimization problem (more than calculating derivatives for the optimization e.g.). At the moment I have a pretty small data set with 7 data points. I will check your possibilites to speed up my code.
Thanks a lot.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!