Skip to content

Commit

Permalink
Merge pull request #37 from modern-fortran/35-fix-mnist-relative-path
Browse files Browse the repository at this point in the history
Fix MNIST relative path and add instructions for running tests
  • Loading branch information
milancurcic authored Apr 1, 2022
2 parents 657b477 + fe134a9 commit 9e269ba
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,16 @@ in parallel, respectively:
fpm build --compiler caf --flag "-cpp -DCAF -O3 -ffast-math"
```

#### Testing with fpm

```
fpm test --flag "-cpp -O3 -ffast-math -fcoarray=single"
```

For the time being, you need to specify the same compiler flags to `fpm test`
as you did in `fpm build` so that fpm can figure out to use the same build
profile.

See [Fortran Package Manager](https://github.com/fortran-lang/fpm) for more info on fpm.

### Building with CMake
Expand Down Expand Up @@ -136,6 +146,25 @@ To build with debugging flags enabled, type:
cmake .. -DCMAKE_BUILD_TYPE=debug
```

#### Running tests with CMake

Before running the tests, link the the data/ directory to the current directory:

```
ln -s ../data
```

The MNIST dataset which comes with the code as a tarball must be unpacked first.
See [MNIST training example](#mnist-training-example) on how to do that.
Once the MNIST dataset is unpacked and the data/ directory is linked in your
CMake build/ directory, run

```
ctest
```

to run the tests.

## Examples

### Creating a network
Expand Down
12 changes: 6 additions & 6 deletions src/mod_mnist.f90
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,20 @@ subroutine load_mnist(tr_images, tr_labels, te_images,&
integer(ik), parameter :: te_nimages = 10000
integer(ik), parameter :: va_nimages = 10000

call read_binary_file('../data/mnist/mnist_training_images.dat',&
call read_binary_file('data/mnist/mnist_training_images.dat',&
dtype, image_size, tr_nimages, tr_images)
call read_binary_file('../data/mnist/mnist_training_labels.dat',&
call read_binary_file('data/mnist/mnist_training_labels.dat',&
dtype, tr_nimages, tr_labels)

call read_binary_file('../data/mnist/mnist_testing_images.dat',&
call read_binary_file('data/mnist/mnist_testing_images.dat',&
dtype, image_size, te_nimages, te_images)
call read_binary_file('../data/mnist/mnist_testing_labels.dat',&
call read_binary_file('data/mnist/mnist_testing_labels.dat',&
dtype, te_nimages, te_labels)

if (present(va_images) .and. present(va_labels)) then
call read_binary_file('../data/mnist/mnist_validation_images.dat',&
call read_binary_file('data/mnist/mnist_validation_images.dat',&
dtype, image_size, va_nimages, va_images)
call read_binary_file('../data/mnist/mnist_validation_labels.dat',&
call read_binary_file('data/mnist/mnist_validation_labels.dat',&
dtype, va_nimages, va_labels)
end if

Expand Down

0 comments on commit 9e269ba

Please sign in to comment.