File: arrays_op_23.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 (34 lines) | stat: -rw-r--r-- 668 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
34
program arrays_op_23
implicit none

real :: array(10, 10), output(10, 10)
array = 3.0

output = attention(10, 10, 10, array)
print *, output
if( any(output - 8.52982235 > 1e-6) ) error stop

contains

function attention(l, n, m, mask) result(y)
integer, intent(in) :: l, n, m
real, intent(in) :: mask(n, m)
real :: y(l, m)
real :: tmp(n, m)
tmp = 4.0
call copy_array(twice(tmp / sqrt(real(l, 4)) + mask), y)
end function

function twice(x) result(y)
real, intent(in) :: x(:, :)
real :: y(size(x, 1), size(x, 2))
y = 2*x
end function

subroutine copy_array(src, dest)
real, intent(in) :: src(:, :)
real, intent(out) :: dest(:, :)
dest = src
end subroutine

end program