cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Did you get called away in the middle of writing a post? Don't worry you can find your unfinished post later in the Drafts section of your profile page. X

Translate the entire conversation x

Mathcad Express - speeding up vec

StuartBruff
23-Emerald IV

Mathcad Express - speeding up vec

My Mathcad Prime 11 trial period has recently ended, so I've been reviewing how some of my older Mathcad Express (E7 & E10, mostly) worksheets and functions perform under Mathcad Express 11.

 

While updating an array reshape function, I noticed that the performance was deteriorating as the array size increased.  This in itself wasn't too surprising, but it was a lot slower than I'd have expected from an O(log(n)) algorithm.  A mere 50,000 elements were taking 3 to 4 seconds to vectorize (confusing terminology in Mathcad terms, I know, but it is common in mathematics - see links at the bottom of this post)

 

reshape, however, used a vec variant to flatten the target array into a vector, before creating a suitably dimensioned array from the resulting vector, and vec proved to be the reason for the performance problem.

 

vec uses fold to apply a bespoke stacking function to its input argument.  I wondered if there was a means of speeding it up and tried another undocumented function, update1, to directly insert elements rather than stacking them.  This produced a remarkable increase in speed.

 

Note that in the definitions below vec` functions only flatten the first level of a nested array, whilst vec variants completely flatten an array, including expanding any nested range variables.

 

vec` and vec definitions:

2025 10 03 A.png

 

vec` and vec examples:

2025 10 03 B.png

 

vec performance comparisons:

2025 10 03 C.png

 

vec` performance comparisons:

2025 10 03 D.png

 

I was wondering if there is something intrinsically wrong with my standard fold approach or if I've made a mistake in implementing it?

 

Are there any other techniques Express could use to speed up (recursive) algorithms?

 

Stuart

 

Mathcad Express 10 worksheet attached.

 

(I've got 60 knot winds blowing at the moment.  Surprisingly, they seem to be blowing the microwaves my way, as my internet performance is almost a matter of positive note compared to its usual languor)

 

https://en.wikipedia.org/wiki/Vectorization_(mathematics)

 

https://link.springer.com/chapter/10.1007/978-1-4757-3238-2_4

0 REPLIES 0
Announcements

Top Tags