Re: Finding maximum of an array



Richard Lavoie wrote:

The procedure below delete for a M x M matrix the value in a single
column L by shifting to the left every value to the right of this
column.

procedure SMatrix.ShiftAll(L, M : LongInt);
var
I, Ms: LongInt;
begin
Ms := (M-L)*4; // compute the size of the data to move
for I := 0 to M - 1 do begin // for every row in the matrix
PtRow := Matrix.Items[I]; // get the pointer of the
array of single values
Move(PtRow^[L+1],PtRow^[L],Ms); // move left all values
after L end;
end;

I do use the FastMove unit, so I wonder whether there is anything I
can do to speed ut the above procedure.

If you address your matrix indirectly through a Row vector and a Col vector
the 'deletion' will take almost no time at all. Just remove the row index
from the Row vector and the col index from the Col vector. No need to
actually move all the matrix data around.

The drawback (as I said in my previous post) is that all computational
references to the matrix gets a little extra time added, but as you've
gotten that part down to almost nothing, I think you can bear it :-)

The values in the Row vector is initialized to 0..3199, the Col vector the
same. Then when you want to delete a row R you just do

for i := R to CurrentMaxRow-1 do Row[i] := Row[i+1];

or use Move() and forget the loop!

Just remember: Every reference, Matrix[r, k], is replaced by Matrix[Row[r],
Col[k]] and that's it. As your Matrix is already a class, you don't even
have to change anything outside the class!

--
Anders Isaksson, Sweden
BlockCAD: http://web.telia.com/~u16122508/proglego.htm
Gallery: http://web.telia.com/~u16122508/gallery/index.htm


.



Relevant Pages

  • Re: deleting 0s from an array
    ... information of the nonzeros in the array. ... Then if you want the location information, ... Note, however, that if you want to subreference this array, ... make sure that d is a row vector. ...
    (comp.soft-sys.matlab)
  • Re: cellfun stuff
    ... it called abc ... i would like to convert to double array value ... vector to a row vector of length 5, ... Then use cell2mat. ...
    (comp.soft-sys.matlab)
  • Vector index into vector
    ... In general, if A is an array, and V is a vector used to index into A ... (via linear indexing), ... However, if A is a row vector, then Awill be a row vector ... is a column vector, then Awill be a column vector. ...
    (comp.soft-sys.matlab)
  • Re: Finding maximum of an array
    ... | If you address your matrix indirectly through a Row vector and a Col ... | vector the 'deletion' will take almost no time at all. ... | the row index from the Row vector and the col index from the Col ... XanaNews Version 1.17.5.7 [Q's Salutation mod] ...
    (borland.public.delphi.language.basm)