Faster than Fold in M9?
- To: mathgroup at smc.vnet.net
- Subject: [mg132290] Faster than Fold in M9?
- From: qbdoud at gmail.com
- Date: Sat, 1 Feb 2014 00:54:36 -0500 (EST)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
- Delivered-to: l-mathgroup@wolfram.com
- Delivered-to: mathgroup-outx@smc.vnet.net
- Delivered-to: mathgroup-newsendx@smc.vnet.net
I have a largish data set in a grid and want to evaluate a lengthy list of operations or functions against computer selected data rows.
Reckon[rows_, operations_] := Module[{tempdata = globaldatamatrix[[#]] & /@ rows},
ToExpression[
StringJoin[
ToString[tempdata[[#]] ] <> ToString[operations[[#]] ] & /@
Range[1, numberofoperationsisabouteight]]
<> "1.0"(*multiple by one point zero to keep symbolic computation in check, the <> symbols join strings*)]
];
This works, but is a tad slow- the messy string operations unaccountably seem faster than the following Fold implementation.
Fold[Consider[#1, #2] &, 0, onerowsandoperationscombo]
Each fold generates a nested function that in would look something like
Consider[row_and_function1, Consider[row_and_function2, Consider[row_and_function3, firstrow] ] ]
if translated for brevity and readability.
Is there a better way to do this kind of thing? I want to Compile but understand I can't work with lists.
Helpful ideas?