Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

WIP: Better matrix support #426

Open
wants to merge 32 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
ac0c9a4
WIP: Interface for matrix calls
porteri Aug 14, 2018
a94db82
WIP: matrix test
porteri Aug 14, 2018
0b570b5
Can get 2d matrix and array of matrices
porteri Aug 14, 2018
2e6c559
Removed write statement
porteri Aug 14, 2018
2d81c1b
Added ability to determine supplied array lengths
porteri Aug 14, 2018
8ac9898
Print test output on failure with check target
zbeekman Aug 14, 2018
80a1d1d
WIP: Found issue with new logic
porteri Aug 14, 2018
1b60c8d
Write format issue fix
porteri Aug 31, 2018
5e9cebb
Fix bad JSON in test
zbeekman Sep 3, 2018
c1e5bd3
Merge branch 'master' into add_matrix_support
zbeekman Sep 27, 2018
2760dfb
Merge branch 'master' into add_matrix_support
zbeekman Nov 16, 2018
f4d7edc
Fix for undefined variable in test#26
Feb 16, 2019
d0a9718
Merge pull request #2 from nrc-fuels/fix_failing_test
porteri Feb 16, 2019
d99c2ae
Merge branch 'master' into add_matrix_support
Feb 16, 2019
20f7059
Merge fix
Feb 16, 2019
34a446e
Merge branch 'master' of github.com:jacobwilliams/json-fortran into a…
zbeekman Mar 29, 2019
0bf4831
Only install module files, not config dir with IDE
zbeekman Mar 29, 2019
ce9c43b
Merge branch 'module_install_w_IDEs' of github.com:zbeekman/json-fort…
zbeekman Mar 30, 2019
f582c41
Revert "Merge branch 'module_install_w_IDEs' of github.com:zbeekman/j…
zbeekman Apr 5, 2019
cb0838d
Merge branch 'module_install_w_IDEs' into add_matrix_support
zbeekman Apr 5, 2019
d3de9dd
Add option to build and link against OpenCoarrays
zbeekman Jun 20, 2019
1a478b7
Merge tag '7.1.0' of github.com:jacobwilliams/json-fortran into add_m…
zbeekman Jul 22, 2019
414003e
Move matrix test (40.f90) to 41.F90
zbeekman Jul 22, 2019
acf4659
Testing: Use CTest fixtures to manipulate files
zbeekman Jul 22, 2019
64f1fea
Merge branch 'master' of github.com:jacobwilliams/json-fortran into a…
zbeekman Jul 25, 2019
2f4354b
Fix matrix test name clashes
zbeekman Jul 25, 2019
c80d070
CMake: Remove extra instance of OC linking option
zbeekman Jul 25, 2019
1c46747
Allow ragged edge matrices in `matrix_info`s
zbeekman Aug 1, 2019
0a12758
WIP: Transfering from laptop to work machine
zbeekman Aug 5, 2019
c3bdf40
WIP: Commit unsaved changes to move from laptop
zbeekman Aug 5, 2019
ede35d2
Remove errant string matrix overloads/interfaces
zbeekman Aug 6, 2019
7ee642b
Updating to remove json tests for Windows as a temporary workaround b…
dcolameco Nov 2, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ set ( JF_LIB_SRCS src/json_kinds.F90
src/json_value_module.F90
src/json_file_module.F90
src/json_module.F90 )
file ( GLOB JF_TEST_SRCS "src/tests/jf_test_*.F90" )
#file ( GLOB JF_TEST_SRCS "src/tests/jf_test_*.F90" ) Commented out to remove json test cases for Windows issues with parallel processing
file ( GLOB JF_TEST_SRCS "src/tests/jf_test2_*.F90" )
set ( JF_TEST_UCS4_SUPPORT_SRC "${CMAKE_SOURCE_DIR}/src/tests/introspection/test_iso_10646_support.f90")

#-----------------------------------------
Expand Down Expand Up @@ -360,9 +361,9 @@ if ( ENABLE_TESTS )
endif()
endforeach ( UNIT_TEST )

set_property ( TEST jf_test_03
APPEND
PROPERTY DEPENDS jf_test_02 )
#set_property ( TEST jf_test_03
# APPEND
# PROPERTY DEPENDS jf_test_02 )

# Validate output
file( GLOB EXPECTED_OUTPUTS "${DATA_DIR}/expected-outputs/*.json")
Expand Down
28 changes: 28 additions & 0 deletions files/inputs/test43.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"ragged_matrix": [
[ 0.2 ,0.01 ,0.02, 0.04],
[ 0.2 ,0.01 ,0.02],
[ 50.1 ,30.2],
[ 50.1 ,30.2 ,0.01 ,0.02 ,0.04],
[ 0.2 ,0.01 ,0.02],
[ 0.2 ,0.01 ,0.02 ,0.04]
],

"integer_matrix": [
[ 2, 0, 0, 4],
[ 0, 0, 2],
[ 50, 30],
[ 50, 30, 0, 0 , 4],
[ 0, 0, 2],
[ 2, 1, 0, 4]
],

"logical_matrix": [
[ true, false, false, false],
[ false, true, true],
[ true, true],
[ true, true, false, false, false],
[ true, false, false],
[ true, false, false, false]
]
}
119 changes: 103 additions & 16 deletions src/json_file_module.F90
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ module json_file_module
MAYBEWRAP(json_file_get_logical_vec), &
MAYBEWRAP(json_file_get_string_vec), &
MAYBEWRAP(json_file_get_alloc_string_vec), &
! MAYBEWRAP(json_file_get_matrix), &
! MAYBEWRAP(json_file_get_matrix_vector), &
json_file_get_root

!>
Expand Down Expand Up @@ -297,6 +299,8 @@ module json_file_module
procedure :: MAYBEWRAP(json_file_get_logical_vec)
procedure :: MAYBEWRAP(json_file_get_string_vec)
procedure :: MAYBEWRAP(json_file_get_alloc_string_vec)
! procedure :: MAYBEWRAP(json_file_get_matrix)
! procedure :: MAYBEWRAP(json_file_get_matrix_vector)
procedure :: json_file_get_root

!add:
Expand Down Expand Up @@ -1052,24 +1056,25 @@ end subroutine wrap_json_file_variable_info
! variable is not found.

subroutine json_file_variable_matrix_info(me,path,is_matrix,found,&
var_type,n_sets,set_size,name)
var_type,n_sets,mx_set_size,is_uniform,name)

implicit none

class(json_file),intent(inout) :: me
character(kind=CK,len=*),intent(in) :: path !! path to the variable
logical(LK),intent(out) :: is_matrix !! true if it is a valid matrix
logical(LK),intent(out),optional :: found !! true if it was found
integer(IK),intent(out),optional :: var_type !! variable type of data in
!! the matrix (if all elements have
!! the same type)
integer(IK),intent(out),optional :: n_sets !! number of data sets (i.e., matrix
!! rows if using row-major order)
integer(IK),intent(out),optional :: set_size !! size of each data set (i.e., matrix
!! cols if using row-major order)
character(kind=CK,len=*),intent(in) :: path !! path to the variable
logical(LK),intent(out) :: is_matrix !! true if it is a valid matrix
logical(LK),intent(out),optional :: found !! true if it was found
integer(IK),intent(out),optional :: var_type !! variable type of data in
!! the matrix (if all elements have
!! the same type)
integer(IK),intent(out),optional :: n_sets !! number of data sets (i.e., matrix
!! rows if using row-major order)
integer(IK),intent(out),optional :: mx_set_size !! size of each data set (i.e., matrix
!! cols if using row-major order)
logical(LK),intent(out) :: is_uniform !! true if it is dense/uniform matrix
character(kind=CK,len=:),allocatable,intent(out),optional :: name !! variable name

call me%core%matrix_info(me%p,path,is_matrix,found,var_type,n_sets,set_size,name)
call me%core%matrix_info(me%p,path,is_matrix,found,var_type,n_sets,mx_set_size,is_uniform,name)

end subroutine json_file_variable_matrix_info
!*****************************************************************************************
Expand All @@ -1083,7 +1088,7 @@ end subroutine json_file_variable_matrix_info
! variable is not found.

subroutine wrap_json_file_variable_matrix_info(me,path,is_matrix,found,&
var_type,n_sets,set_size,name)
var_type,n_sets,mx_set_size,is_uniform,name)

implicit none

Expand All @@ -1096,11 +1101,12 @@ subroutine wrap_json_file_variable_matrix_info(me,path,is_matrix,found,&
!! the same type)
integer(IK),intent(out),optional :: n_sets !! number of data sets (i.e., matrix
!! rows if using row-major order)
integer(IK),intent(out),optional :: set_size !! size of each data set (i.e., matrix
!! cols if using row-major order)
integer(IK),intent(out),optional :: mx_set_size !! size of each data set (i.e., matrix
!! cols if using row-major order)
logical(LK),intent(out) :: is_uniform !! true if it is dense/uniform matrix
character(kind=CK,len=:),allocatable,intent(out),optional :: name !! variable name

call me%matrix_info(to_unicode(path),is_matrix,found,var_type,n_sets,set_size,name)
call me%matrix_info(to_unicode(path),is_matrix,found,var_type,n_sets,mx_set_size,is_uniform,name)

end subroutine wrap_json_file_variable_matrix_info
!*****************************************************************************************
Expand Down Expand Up @@ -1518,6 +1524,87 @@ subroutine json_file_get_real_vec(me, path, vec, found)
end subroutine json_file_get_real_vec
!*****************************************************************************************

! !*****************************************************************************************
! !> author: Ian Porter
! ! date: 8/14/2018
! !
! ! Get a real(RK) matrix of vectors from a JSON file.

! subroutine json_file_get_matrix(me, path, vec, found, vec_size)

! implicit none

! class(json_file),intent(inout) :: me
! character(kind=CK,len=*),intent(in) :: path !! the path to the variable
! real(RK),dimension(:,:),allocatable,intent(out) :: vec !! the value vector
! logical(LK),intent(out),optional :: found !! if it was really found
! integer(IK),dimension(:),allocatable,intent(out),optional :: vec_size !! the # of values provided in each vec(x,:)
! integer(IK) :: var_type !! var type
! integer(IK) :: n_sets !! # of sets of matrices
! integer(IK) :: mx_set_size !! # of rows in each matrix
! integer(IK) :: i !! counter
! logical(LK) :: is_matrix !! flag for whether it is a matrix
! integer(IK),dimension(:,:),allocatable :: matrix_column_size
! real(RK),dimension(:,:,:),allocatable :: matrix_vec

! call me%core%matrix_info(me%p,path,is_matrix,found,var_type,n_sets,mx_set_size, &
! & matrix_column_size=matrix_column_size,matrix_vec=matrix_vec)

! if (is_matrix) then
! associate (max_vec_size => maxval(matrix_column_size(1,:)))
! allocate(vec(mx_set_size,max_vec_size),source=0.0_RK)
! if (present(vec_size)) vec_size = matrix_column_size(1,:)
! do i = 1, mx_set_size
! vec(i,1:matrix_column_size(1,i)) = matrix_vec(1,i,1:matrix_column_size(1,i))
! end do
! end associate
! end if

! end subroutine json_file_get_matrix
! !*****************************************************************************************

! !*****************************************************************************************
! !> author: Ian Porter
! ! date: 8/14/2018
! !
! ! Get a real(RK) matrix of vectors from a JSON file.

! subroutine json_file_get_matrix_vector(me, path, vec, found, vec_size)

! implicit none

! class(json_file),intent(inout) :: me
! character(kind=CK,len=*),intent(in) :: path !! the path to the variable
! real(RK),dimension(:,:,:),allocatable,intent(out) :: vec !! the value vector
! logical(LK),intent(out),optional :: found !! if it was really found
! integer(IK),dimension(:,:),allocatable,intent(out),optional :: vec_size !! the # of values provided in each vec(x,x,:)
! integer(IK) :: var_type !! var type
! integer(IK) :: n_sets !! # of sets of matrices
! integer(IK) :: mx_set_size !! # of rows in each matrix
! integer(IK) :: i !! counter
! integer(IK) :: j !! counter
! logical(LK) :: is_matrix !! flag for whether it is a matrix
! integer(IK),dimension(:,:),allocatable :: matrix_column_size
! real(RK),dimension(:,:,:),allocatable :: matrix_vec

! call me%core%matrix_info(me%p,path,is_matrix,found,var_type,n_sets,mx_set_size, &
! & matrix_column_size=matrix_column_size,matrix_vec=matrix_vec)

! if (is_matrix) then
! associate (max_vec_size => maxval(matrix_column_size(:,:)))
! allocate(vec(n_sets,mx_set_size,max_vec_size),source=0.0_RK)
! if (present(vec_size)) vec_size = matrix_column_size
! do j = 1, n_sets
! do i = 1, mx_set_size
! vec(j,i,1:matrix_column_size(j,i)) = matrix_vec(j,i,1:matrix_column_size(j,i))
! end do
! end do
! end associate
! end if

! end subroutine json_file_get_matrix_vector
! !*****************************************************************************************

!*****************************************************************************************
!>
! Alternate version of [[json_file_get_real_vec]], where "path" is kind=CDK.
Expand Down
Loading