Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Fortran: delete rows from matrix

dsmanoli
Beginner
2,455 Views
Hi,
Could you tell me how delete/drop some rows from a matrix in Fortran?

For example, suppose that I have
X =
1 2 3
2 4 6
3 6 9

and I want to drop rows where column 1 in X has even values to get

X=
1 2 3
3 6 9


I appreciate any suggestions. Thanks!
0 Kudos
2 Replies
ArturGuzik
Valued Contributor I
2,455 Views
Hi,

it very much depends what you really mean by drop? Do you want to remove (and resize) it or you want to "drop" from calculations? If the former, and, say, array was allocated with ALLOCATE statement, then ... well you need to count and find the rows, then allocate another (buffer) array to appropriate size and copy what's required (you cannot DEALLOCATE portion of the array). If the resizing and copying to larger array would be required, then efficient way is to use MOVE_ALLOC. If the latter, that is, skipp some rows in calculations only, you can use WHERE or FORALL statements.
Others will probably come up with some more efficient and clever ways of doing this.

A.
0 Kudos
jimdempseyatthecove
Honored Contributor III
2,455 Views

Such as using an array of pointers to 1D arrays. Where you delete the 1D array at the row position then copy the pointers (squish the pointer list).

Reference as: Array%RowTable%Data(c)

Or

Such as using an array of integer indexes to an array of pointers to 1D arrays. Where you delete the 1D array in the row position of the pointer of the index (making the pointer free for later use) then squish the list of integer indexes.

Reference as: Using1DArray(Array%RowTableIndex)%Data(c)

In both cases it is easier to program when using either a function returning a reference or pointer to row or use an FPP macro to build the syntax for you.

Jim Dempsey





0 Kudos
Reply