File: array_indices_array_section.f90

package info (click to toggle)
lfortran 0.45.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 46,332 kB
  • sloc: cpp: 137,068; f90: 51,260; python: 6,444; ansic: 4,277; yacc: 2,285; fortran: 806; sh: 524; makefile: 30; javascript: 15
file content (33 lines) | stat: -rw-r--r-- 1,151 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
program array_indices_array_section

    implicit none

    integer :: arr_idx(2)
    real ::  arr_1(2, 2), arr_2(2, 2), arr_3(2, 2, 2), arr_4(2, 2, 2)
    real :: arr_2_reshape(2, 2), arr_4_reshape(2, 2, 2)

    ! Initialize the matrices and arrays
    arr_1 = reshape([1.0, 2.0, 3.0, 4.0], shape(arr_1))
    arr_3 = reshape([1.0, 2.0, 3.0, 4.0, 1.0, 2.0, 3.0, 4.0, 5.0], shape(arr_3))
    arr_idx = [2, 1]

    ! Slicing
    arr_2 = arr_1(arr_idx, :)
    arr_2_reshape = reshape([2.0, 1.0, 4.0, 3.0], shape(arr_2_reshape));
    print *, rank(arr_2)
    if (rank(arr_2) /= 2) error stop
    if (any(arr_2 /= arr_2_reshape)) error stop

    arr_4 = arr_3(:, :, arr_idx)
    arr_4_reshape = reshape([1.0, 2.0, 3.0, 4.0, 1.0, 2.0, 3.0, 4.0], shape(arr_4_reshape));
    print *, rank(arr_4)
    if (rank(arr_4) /= 3) error stop
    if (any(arr_4 /= arr_4_reshape)) error stop

    arr_4 = arr_3(:, arr_idx, :)
    arr_4_reshape = reshape([3.0, 4.0, 1.0, 2.0, 3.0, 4.0, 1.0, 2.0], shape(arr_4_reshape));
    print *, rank(arr_4)
    if (rank(arr_4) /= 3) error stop
    if (any(arr_4 /= arr_4_reshape)) error stop

end program array_indices_array_section