What would be the fastest way to detect and clear trivial values from variables

We have a model that can get extremely large and sometimes we don’t do the basis crossover after the interior point solve.

This can leave us with tiny trivial (and invalid) values in some variables, and we need to clean them up because they are causing us problems when we use these values later.

What we need to do is loop over the variables and find examples of these trivial values and set them to zero. The concern is some of our variables are a very large domain space, for example one of them has 5 indexes with thousands upon thousands of elements in each index.

Is there a better way of writing the code to do this than just brute force looping over the indexes for each variable and testing if it is trivial?

eg something like

loop(i,j,k,l,m)$(abs(myVariable(i,j,k,l,m)) < 0.00000001) do

myVariable.l(i,j,k,l,m)=0;

endloop

For better performance I am using for such purpose bulk assignments instead of a loop, e.g.:

myVariable.l(i,j,k,l,m)$(abs(myVariable.l(i,j,k,l,m)) < 0.000001) = 0;

However, as to the fastest way to detect and clear tiny values, I would also hope some true GAMS expert could respond and give an answer to that question. :melting_face: