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

A map to specific rank-n array elements

Gustavo_Colvero
Beginner
403 Views
Hi.

Suppose I have a rank-3 array D3 of doubles (or whatever) and a rank-2 array M of integers.

Is there any "smart" way of using M as a map for elements in D3?

For example, if I have

M(1,:) = (/1,1,2/)
M(2,:) = (/2,2,3/)

Is there a way of saying D3(M(1,:)) for D3(1,1,2) and D3(M(2,:)) for D3(2,2,3), or, even better, D3(M)
for both, In a way in which I can simply say

D2 = D3(M)

being D2 a rank-1 array of doubles with size 2?

I already know of vector substripts for rank-1 arrays. Are there matrix (or array) subscripts
for rank-n arrays?

Thanks.

Gustavo.

0 Kudos
5 Replies
mecej4
Honored Contributor III
403 Views
In the expression D3(1,1,2), the subscript list 1,1,2 is an ordered triplet of integers. Similarly, for a 2-D array, the subscript list is an ordered pair of integers.

On the other hand, in a constructor such as (/ 1, 1, 2 /), the three integers are elements of a 1-D integer array. The characteristics of 1-D arrays are quite different from those of ordered triplets.

Using the OO features of Fortran 2xxx, it may be possible to attempt to define a new derived type, namely, the subscript type, and to define operations on the type.
0 Kudos
Gustavo_Colvero
Beginner
403 Views
I suspected this would be the way.
Thank you.
0 Kudos
jimdempseyatthecove
Honored Contributor III
403 Views
mecej4,

In Fortran 20xx do the OO features permit a function to return an LVALUE? (er... LREFERENCE)?

If so, then the array can be pseudonymed to a generic interfaced function that would take variously expressed arguments (e.g. individula elements as arrgs or 1D array of elements, etc...).

Jim
0 Kudos
mecej4
Honored Contributor III
403 Views
Jim, some syntactic sugar would be needed to disambiguate subscript lists from array constructors.

Given the current level of support available in Fortran compilers for abstract types and OOP, an implementation of a subscript type would constitute a torture test for the compiler, perhaps!
0 Kudos
jimdempseyatthecove
Honored Contributor III
403 Views
Quoting mecej4
Jim, some syntactic sugar would be needed to disambiguate subscript lists from array constructors.

Given the current level of support available in Fortran compilers for abstract types and OOP, an implementation of a subscript type would constitute a torture test for the compiler, perhaps!

Disambiguating is not the problem as I see it. The problem becomes should subscript lists be implemented then what would have been reported as a programming error might pass as intended programming

integer :: i(:),j(:)
real :: A(:)
...
i = (/1,5,2,6,9/)
...
X = A(i)
...

In the current syntax i in A(i) would produce an error
If subscript lists were implemented then the statement might be interpreted as i being a subscript list.
However, in doing so A(j) where j is a typeographical error would not be caught as an error in programming.

I suggest using RESHAPE to perform the translation.
But this will not provide arbitrary indexing such as array(-100:100).
So you may have tocombine RESHAPE and FOR_DESCRIPTOR_ASSIGN

Jim Dempsey

0 Kudos
Reply