- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
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.
Link Copied
5 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I suspected this would be the way.
Thank you.
Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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!
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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!
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
![](/skins/images/872293744008A34B36F8ABF94A46CC66/responsive_peak/images/icon_anonymous_message.png)
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page