Community Tip - Your Friends List is a way to easily have access to the community members that you interact with the most! X
Following @DJNewman 's message on the topic of implicit vectorization of range variable being removed from Mathcad Prime 10, I looked at the referenced support article CS416474. The resolution to the "problem" was to use a range-to-vector conversion program.
Note that I use the term "vectorize" in the mathematical sense of "convert a matrix to a vector" rather than the programming sense of carrying out operations in parallel (e.g., Mathcad's vectorize operator).
The suggested function Range2Vec is similar to one I usually use (vec) except that instead of stack it uses indexing to add new elements to the constructed vector. I vaguely recall that stacking is inefficient time-wise compared to indexing, so I thought it would be interesting to see how the two variants compared.
Then I thought, "Hey, why stop at two mousetraps? Let's build some more to see if anything hits paydirt".
So, I played with a few variants and concluded yet again that stacking is probably slower than indexing. However, there isn't much objectively in it even for a few million elements, even in nested arrays.
Note that most of the variants tested fully convert nested arrays to vectors, whilst Range2Vec and vec` do not - they're only targeted at vectorizing the first level of an array.
Take the results with several pinches of salt. The times depend upon what else your computer is doing. In the example below Range2Vec is shown to perform worse than the rest. This is very unusual. Range2Vec holds Gold or Silver during most runs, as it should, given it doesn't have to have code to deal with nesting. . Besides, the worksheet's probably full of bugs, anyway. 🙂
Having said that, the times are reasonably consistent in showing "bands" of times. The slowest two functions are usually vec (uses stack to add elements) and vec3 (uses trim rather than submatrix to remove the dummy empty array values).
Stuart
References:
https://community.ptc.com/t5/Mathcad/Exclude-some-values/m-p/980366/highlight/true#M214627
Something to (possibly, no promises) think about for Mathcad Prime 11: We're strongly pushing R&D to put in a built-in vec() function that should also do this. So you may wish to repeat your testing once that's out. (If it happens.)
That sounds great, Dave. I certainly look forward to doing that round of tests again.
If it is implemented, please consider my comments about naming the function. The naming style for other functions that create and manipulate arrays tends to be short, lowercase, and meaningful. Thank you.
As an aside, will the function be limited in scope or capable of vectorizing any type of array (including arbitrarily-deeply nested ones)? As you (PTC) can write functions that take optional arguments, perhaps a depth limit could be incorporated - there are occasions when it's only required to go so far down a data structure. Here's a quick and brutal version of vec that takes a (non-optional) depth argument.
vec7 definition:
vec7 applied to a slightly nested data structure
Oh, as it's a closely related issue, could you please ask the development team to include an IsRange function (that doesn't evaluate a range if evaluated rather than used in a definition!).
Stuart
@DJNewman wrote:
Something to (possibly, no promises) think about for Mathcad Prime 11: We're strongly pushing R&D to put in a built-in vec() function that should also do this. So you may wish to repeat your testing once that's out. (If it happens.)
Please keep on pushing .... 😉
I also just used my powers of email sending to direct attention to Stuart's technical implementation suggestion above.
@DJNewman wrote:
I also just used my powers of email sending to direct attention to Stuart's technical implementation suggestion above.
Thanks, Dave. I'll keep my fingers and other digits crossed that the email falls on fertile ground.
Stuart