Re: Finding maximum of an array
- From: "John Herbster" <herb-sci1_AT_sbcglobal.net>
- Date: Sun, 20 Apr 2008 21:29:58 -0500
"Richard Lavoie" <somone@xxxxxxxxxxxxx> wrote
I am trying to optimize a procedure that tries to locate the maximum value in an array of single. I am working with huge arrays, so this is the bottleneck of my program.
for J := N to M do
if (ARow[J] >= RX) then begin
L := J;
RX := ARow^[J]; //Richard, I presume that this should be ARow[J]
end;
Richard, I can suggest many ideas that could help, depending on your situation:
(1) Changing the ">=" to ">" and "N to M" to "M downto N", might make a little difference depending on your data.
(2) Change the problem to an integer problem by making a lossless transformation of the data from type Single to type LongInt. For one way to do this, see how the function in http://qc.codegear.com/wc/qcmain.aspx?d=50577 does it.
(3) Append record numbers to the elements of the array and sort into order of the single values.
(4) Build an index of big blocks of the input array, listing the largest number in each block. Then use this to avoid scanning individual entries.
(5) And many more, if you will tell us more about your situation -- like where the numbers come from, their distribution, how often the scans are done, etc.
HTH, JohnH
.
- Follow-Ups:
- Re: Finding maximum of an array
- From: Richard Lavoie
- Re: Finding maximum of an array
- References:
- Finding maximum of an array
- From: Richard Lavoie
- Finding maximum of an array
- Prev by Date: Just installed Delphi 2007 April 08 patch...
- Next by Date: Re: Just installed Delphi 2007 April 08 patch...
- Previous by thread: Finding maximum of an array
- Next by thread: Re: Finding maximum of an array
- Index(es):