Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Support array checking for the check subroutine #19

Open
zoziha opened this issue Jun 18, 2022 · 2 comments · May be fixed by #20
Open

Support array checking for the check subroutine #19

zoziha opened this issue Jun 18, 2022 · 2 comments · May be fixed by #20
Labels
enhancement New feature or request

Comments

@zoziha
Copy link

zoziha commented Jun 18, 2022

At present, test-drive can check scalars of Fortran built-in types, such as logical scalars, integer scalars, and real scalars; however, it does not support arrays, so users need to write loops to check the contents of arrays:

do i = 1, size(array)
    call check(error, array(i), expected(i), ...)
    if (allocated(error)) return
end do

It would be a good feature to support array checking. Since the check subroutine usually only needs to read the array without changing the contents of the array, I think using reshape to convert it into a rank-1 array for checking would be an acceptable solution.

subroutine check_array(error, actual, expected, ...)
    type(error_type), allocatable, intent(out) :: error
    class(*), intent(in) :: actual(:)
    class(*), intent(in) :: expected(:)
    ...
end subroutine

! The `array` can be of any shape, and is finally determined to be a rank-1 array by `reshape`
call check(error, reshape(array, shape=[size(array)], expected, ...)
if (allocated(error)) return
@zoziha zoziha added the enhancement New feature or request label Jun 18, 2022
@zoziha zoziha linked a pull request Jun 18, 2022 that will close this issue
3 tasks
@ivan-pi
Copy link
Member

ivan-pi commented Jun 28, 2022

One can also use an array expression like

call check(error, all(array == expected))

@zoziha
Copy link
Author

zoziha commented Jul 3, 2022

Using all, for real numbers, we need to construct the following judgments,

call check(error, all((abs(array - expected) < abs_tol)), ...)

And when dealing with relative differences, it becomes more complicated.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants