Without knowing much about the data, it seems likely that it consists of numbers, and the the times and efficiencies are positive real numbers. Further I have to guess that
Select[EquipParams, #[[colEquipID]] == CurrentEquipID &][[;; , colOperatingDelayTime]]
returns a list consisting of a single number; otherwise, I cannot see how one would get predictable results picking the i-th element in the flattened array.
Here is some made-up data, on which your function works (i.e. runs without error and returns a list of real numbers):
nEquip = 10000;
numEquipmentStats = 100;
colEquipID = 1; (* index *)
colOperatingDelayTime = 3; (* random index *)
CurrentEquipID = 40;
HTimeModelSelection[CurrentEquipID] = RandomInteger[{0, 2}, nEquip];
HOperatingEfficiency[CurrentEquipID] = RandomReal[1, nEquip];
HUtilizedTime[CurrentEquipID] = RandomReal[1, nEquip];
EquipParams = Transpose @ Join[{Range[nEquip]}, RandomReal[1, {numEquipmentStats, nEquip}]];
Your function takes 0.136795 sec. (Perhaps the slowness your function has to do with the functions HTimeModelSelection, HOperatingEfficiency, or HUtilizedTime -- your code calls them repeatedly on the same input -- something to avoid if your functions take an appreciable amount of time to evaluate.)
If the data in this calculation, except HTimeModelSelection, are positive numbers, then the following will be fast.
AbsoluteTiming[
Unitize[HTimeModelSelection[CurrentEquipID]] (1. -
HOperatingEfficiency[CurrentEquipID]) HUtilizedTime[
CurrentEquipID] /.
0 -> Select[EquipParams,
#[[colEquipID]] == CurrentEquipID &, 1][[1, colOperatingDelayTime]];]
{0.002531, Null}
If the data is not all positive numbers, then here is a variation that works:
Transpose[{
N@Unitize[HTimeModelSelection[CurrentEquipID]],
(1. - HOperatingEfficiency[CurrentEquipID]) HUtilizedTime[CurrentEquipID]
}] /.
{{0., _} -> Select[EquipParams,
#[[colEquipID]] == CurrentEquipID &, 1][[1, colOperatingDelayTime]],
{1., x_} :> x}; // AbsoluteTiming
{0.006147, Null}
If that's not fast enough, then perhaps compiling will help:
cf = Compile[{{model, _Real, 1}, {eff, _Real, 1}, {time, _Real, 1}, {delay, _Real}},
If[#[[1]] == 0., #[[2]], delay] & /@ Transpose[{model, (1. - eff) time}]];
cf[Unitize[HTimeModelSelection[CurrentEquipID]],
HOperatingEfficiency[CurrentEquipID],
HUtilizedTime[CurrentEquipID],
Select[EquipParams,
#[[colEquipID]] == CurrentEquipID &, 1][[1, colOperatingDelayTime]]]; // AbsoluteTiming
{0.001194, Null}
Selectinside a loop may be slow. Consider creating a hash table for each value (or position) rather than finding it withSelect. – Mr.Wizard Jun 11 '13 at 13:05