Re: My first program: sublime (reverse of "extract" function)

new topic     » goto parent     » topic index » view thread      » older message » newer message
SocIoDim said...
jimcbrown said...

Why can't you keep a copy of the original list? What type of processing are you doing that makes this solution unsuitable?

That's slightly less trivial code:

sequence InputData = {0.01, 0.05, 0.08, 0.03, 0.02} 
sequence OutputData = sort(InputData) 
sequence OriginalOrder = sublime(InputData, OutputData) 
for i = 2 to length(OutputData) do 
    OutputData[i] *= 1 - OutputData[i-1] 
end for 
OutputData = extract(OutputData, OriginalOrder) 

I think I get it. Your example can still be implemented as:

sequence InputData = {0.01, 0.05, 0.08, 0.03, 0.02} 
sequence OutputData = 1 - InputData[2..$] 

But I think your point is clear - you don't want to merely use your sorted input data for a task and then reuse the unsorted version later. You don't want to just sort the output data either. You need to sort the input data for a task, then "unsort" the output data such that the each element of the output data is in the same position as the corresponding element in the original unsorted input data.

If every element is unique in the input data, and every element is unique in the output data, then you could just use mapping(). But that probably isn't true.

SocIoDim said...

P.S. I've been thinking how best to implement this feature: simple or optimal. This is the easiest and most non-optimal option. There have been other attempts.

I'd go with optimal.

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu