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

multi-rank array literals

martymike
Novice
519 Views

This appears to work in initalization expression but not in assignment. Why is that? For example:

 

integer,dimension(2,3) :: x=[[1,2,3],[4,5,6]],y
y = [[1,2,3],[4,5,6]]
print *,x
print *,y
end

 

ifort mat.f90
Intel(R) Fortran Intel(R) 64 Compiler Classic for applications running on Intel(R) 64, Version 2021.10.0 Build 20230609_000000
Copyright (C) 1985-2023 Intel Corporation. All rights reserved.

mat.f90(2): error #6366: The shapes of the array expressions do not conform. [Y]
y = [[1,2,3],[4,5,6]]
^
compilation aborted for mat.f90 (code 1)

I do realize I can use a rank 1 literal and the reshape function to get around this.

1 Solution
Steve_Lionel
Honored Contributor III
478 Views

The initialization is also an error, one that the Intel compiler does not detect, even with standards warnings on, so that's a bug. The standard says:

If initialization appears for a nonpointer entity,
 • its type and type parameters shall conform as specified for intrinsic assignment (10.2.1.2)
 • if the entity has implied shape, the rank of initialization shall be the same as the rank of the entity;
 • if the entity does not have implied shape, initialization shall either be scalar or have the same shape as the entity.

View solution in original post

4 Replies
andrew_4619
Honored Contributor II
493 Views

Array constructors are always rank 1, reshape is what you have to do. 

Steve_Lionel
Honored Contributor III
479 Views

The initialization is also an error, one that the Intel compiler does not detect, even with standards warnings on, so that's a bug. The standard says:

If initialization appears for a nonpointer entity,
 • its type and type parameters shall conform as specified for intrinsic assignment (10.2.1.2)
 • if the entity has implied shape, the rank of initialization shall be the same as the rank of the entity;
 • if the entity does not have implied shape, initialization shall either be scalar or have the same shape as the entity.

Barbara_P_Intel
Moderator
443 Views

I filed a bug report on missing error message for the initialization based on what Steve cited from the Fortran Standard. Bug report is CMPLRLLVM-57399.


Barbara_P_Intel
Moderator
293 Views

HA! This turned out to be a duplicate bug report and the fix is ready for release with 2024.2.0. Look for that version in mid-2024!



0 Kudos
Reply