Skip to content

Commit a526a39

Browse files
committed
Test reading 1-d and 2-d HDF5 datasets
1 parent ed3e6d6 commit a526a39

File tree

2 files changed

+32
-31
lines changed

2 files changed

+32
-31
lines changed

test/test_io_hdf5.f90

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
program test_io_hdf5
22

3-
use iso_fortran_env, only: stderr => error_unit
3+
use iso_fortran_env, only: int64, stderr => error_unit
44
use nf_datasets, only: download_and_unpack, keras_model_dense_mnist_url
55
use nf_io_hdf5, only: get_hdf5_attribute_string
6+
use h5fortran, only: hdf5_file
67

78
implicit none
89

910
character(:), allocatable :: attr
1011
character(*), parameter :: test_data_path = 'keras_dense_mnist.h5'
12+
type(hdf5_file) :: f
13+
real, allocatable :: bias(:), weights(:,:)
14+
integer(int64), allocatable :: dims(:)
15+
1116
logical :: file_exists
1217
logical :: ok = .true.
1318

@@ -19,9 +24,34 @@ program test_io_hdf5
1924
if (.not. attr == 'tensorflow') then
2025
ok = .false.
2126
write(stderr, '(a)') &
22-
'HDF5 variable length string attribute not read correctly.. failed'
27+
'HDF5 variable length string attribute was read correctly.. failed'
28+
end if
29+
30+
call f % open(test_data_path, 'r')
31+
32+
call f % shape('/model_weights/dense/dense/bias:0', dims)
33+
allocate(bias(dims(1)))
34+
bias = 0
35+
call f % read('/model_weights/dense/dense/bias:0', bias)
36+
37+
if (.not. all(dims == [30])) then
38+
ok = .false.
39+
write(stderr, '(a)') 'HDF5 1-d dataset dims inquiry is correct.. failed'
2340
end if
2441

42+
call f % shape('/model_weights/dense/dense/kernel:0', dims)
43+
allocate(weights(dims(1), dims(2)))
44+
weights = 0
45+
call f % read('/model_weights/dense/dense/kernel:0', weights)
46+
47+
if (.not. all(dims == [30, 784])) then
48+
ok = .false.
49+
print *, dims
50+
write(stderr, '(a)') 'HDF5 2-d dataset dims inquiry is correct.. failed'
51+
end if
52+
53+
call f % close()
54+
2555
if (ok) then
2656
print '(a)', 'test_io_hdf5: All tests passed.'
2757
else

test/test_read_hdf5_dataset.f90

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)