lfortran / lfortran

Official main repository for LFortran
https://lfortran.org/
Other
942 stars 152 forks source link

Compiling stdlib stats #3052

Open HarshitaKalani opened 9 months ago

HarshitaKalani commented 9 months ago

Using https://github.com/HarshitaKalani/stdlib-fortran-lang/tree/lf_stats branch. GFortran script:

FC=gfortran cmake .
make fortran_stdlib
make example_gamma
./example/specialfunctions_gamma/example_gamma

git clean -dfx

LFortran script:

FC=lfortran cmake .
make fortran_stdlib
cp src/*.mod example/stats
make

./example/stats/example_corr
./example/stats/example_cov
./example/stats/example_mean
./example/stats/example_median
./example/stats/example_moment
./example/stats/example_var

I'm getting the following issue when I run make fortran_stdlib, I get

semantic error: No matching signature found for intrinsic merge
   --> /home/harshita/Desktop/stdlib/src/stdlib_stats.f90:146:25
    |
146 |         real(sp) :: res(merge(size(x, 1), size(x, 2), mask = 1<dim)&
    |                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 

Note: Please report unclear or confusing messages as bugs at
https://github.com/lfortran/lfortran/issues.

To fix:

HarshitaKalani commented 9 months ago

The file stdlib_stats.f90 contains 750 entries of merge, I feel it is difficult to comment those out. So will implement that first. Or is there any other way to go about this?

certik commented 9 months ago

Yes, implement merge.

HarshitaKalani commented 8 months ago

file src/stdlib_linalg.f90 throws Internal Compiler error on building (make fortran_stdlib)

function diag_rdp_mat_k(A,k) result(res)
    real(selected_real_kind(15)), intent(in) :: A(:,:)
    integer, intent(in) :: k
    real(selected_real_kind(15)) :: res(minval(shape(A))-abs(k))
end function diag_rdp_mat_k
$ gfortran a.f90
$ lfortran a.f90
ASR verify pass error: ASR verify: Function diag_rdp_mat_k doesn't depend on _lcompilers_shape1 but is found in its dependency list.
Internal Compiler Error: Unhandled exception
^C
HarshitaKalani commented 8 months ago

Here is another issue in stdlib_linalg.f90 file

PROGRAM main
    complex(8), parameter :: zero = 0 
END PROGRAM
$ gfortran b.f90 && ./a.out
$ lfortran b.f90
^C
HarshitaKalani commented 8 months ago

Issue in src/stdlib_random.f90 file:

semantic error: Function 'ishftc' not found or not implemented yet (if it is intrinsic)
   --> /home/harshita/Desktop/stdlib/src/stdlib_random.f90:128:15
    |
128 |         res = ishftc(st(2) * 5, 7) * 9
    |               ^^^^^^^^^^^^^^^^^^^^ 
HarshitaKalani commented 8 months ago

In the stdlib_stats_corr.f90 file

[  2%] Building Fortran object src/CMakeFiles/fortran_stdlib.dir/stdlib_stats_corr.f90.o
semantic error: transpose accepts arrays of rank 2 only, provided an array with rank, 0
   --> /home/harshita/Desktop/stdlib/src/stdlib_stats_corr.f90:441:37
    |
441 |             res = matmul( transpose(conjg(center)), center)
    |                                     ^^^^^^^^^^^^^ 

Note: Please report unclear or confusing messages as bugs at
https://github.com/lfortran/lfortran/issues.
make[3]: *** [src/CMakeFiles/fortran_stdlib.dir/build.make:225: src/CMakeFiles/fortran_stdlib.dir/stdlib_stats_corr.f90.o] Error 1
make[2]: *** [CMakeFiles/Makefile2:933: src/CMakeFiles/fortran_stdlib.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:940: src/CMakeFiles/fortran_stdlib.dir/rule] Error 2
make: *** [Makefile:543: fortran_stdlib] Error 2
HarshitaKalani commented 8 months ago

With all the workarounds mentioned here: https://github.com/HarshitaKalani/stdlib-fortran-lang/commits/lf_stats/, we're able to build stdlib-stats now.

Pranavchiku commented 7 months ago

Branch: https://github.com/czgdp1807/stdlib/tree/lf-stats-test With #3519 and #3532, we get

ASR verify pass error: Input to Sum intrinsic must always be an array
    --> /Users/pranavchiku/repos/stdlib/src/stdlib_stats.f90:4527:17
     |
4527 |           res = sum(abs(x - mean)**2) / (n - merge(1, 0, optval(corrected, .true.)))
     |                 ^^^^^^^^^^^^^^^^^^^^^ failed here