Skip to content

Commit

Permalink
Remove some unused variables and a broadcast (#180)
Browse files Browse the repository at this point in the history
* Remove unused variables

* remove batch_end variable as unused

---------

Co-authored-by: Vandenplas, Jeremie <jeremie.vandenplas@wur.nl>
  • Loading branch information
jvdp1 and Vandenplas, Jeremie authored Jun 14, 2024
1 parent e82d565 commit a843c83
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 16 deletions.
3 changes: 0 additions & 3 deletions example/cnn_mnist.f90
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ program cnn_mnist
real, allocatable :: training_images(:,:), training_labels(:)
real, allocatable :: validation_images(:,:), validation_labels(:)
real, allocatable :: testing_images(:,:), testing_labels(:)
real, allocatable :: input_reshaped(:,:,:,:)
real :: acc
logical :: ok
integer :: n
integer, parameter :: num_epochs = 10

Expand Down
3 changes: 1 addition & 2 deletions example/get_set_network_params.f90
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ program get_set_network_params
integer, parameter :: test_size = 30
real :: xtest(test_size), ytest(test_size)
real :: ypred1(test_size), ypred2(test_size)
integer :: i, n, nparam
real, allocatable :: parameters(:)
integer :: i, n

print '("Getting and setting network parameters")'
print '(60("="))'
Expand Down
6 changes: 3 additions & 3 deletions example/quadratic.f90
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ program quadratic_fit
real, allocatable :: x(:), y(:) ! training data
real, allocatable :: xtest(:), ytest(:) ! testing data

integer :: i, n
integer :: i

print '("Fitting quadratic function")'
print '(60("="))'
Expand Down Expand Up @@ -277,7 +277,7 @@ subroutine rmsprop_optimizer( &
real, intent(in) :: xtest(:), ytest(:)
real, intent(in) :: learning_rate, decay_rate
integer, intent(in) :: num_epochs
integer :: i, j, n
integer :: i, n
real, allocatable :: ypred(:)

print '(a)', 'RMSProp optimizer'
Expand Down Expand Up @@ -446,4 +446,4 @@ subroutine shuffle(arr)
end do
end subroutine shuffle

end program quadratic_fit
end program quadratic_fit
6 changes: 1 addition & 5 deletions src/nf/nf_network_submodule.f90
Original file line number Diff line number Diff line change
Expand Up @@ -596,11 +596,10 @@ module subroutine train(self, input_data, output_data, batch_size, &
integer, intent(in) :: epochs
class(optimizer_base_type), intent(in), optional :: optimizer
class(loss_type), intent(in), optional :: loss
class(optimizer_base_type), allocatable :: optimizer_

real :: pos
integer :: dataset_size
integer :: batch_start, batch_end
integer :: batch_start
integer :: i, j, n
integer :: istart, iend, indices(2)

Expand Down Expand Up @@ -630,11 +629,9 @@ module subroutine train(self, input_data, output_data, batch_size, &
! Pull a random mini-batch from the dataset
call random_number(pos)
batch_start = int(pos * (dataset_size - batch_size + 1)) + 1
batch_end = batch_start + batch_size - 1

! FIXME shuffle in a way that doesn't require co_broadcast
call co_broadcast(batch_start, 1)
call co_broadcast(batch_end, 1)

! Distribute the batch in nearly equal pieces to all images
indices = tile_indices(batch_size)
Expand All @@ -658,7 +655,6 @@ module subroutine update(self, optimizer, batch_size)
class(network), intent(in out) :: self
class(optimizer_base_type), intent(in), optional :: optimizer
integer, intent(in), optional :: batch_size
class(optimizer_base_type), allocatable :: optimizer_
integer :: batch_size_
real, allocatable :: params(:)
integer :: n
Expand Down
2 changes: 1 addition & 1 deletion test/test_flatten_layer.f90
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ program test_flatten_layer

type(layer) :: test_layer, input_layer
type(network) :: net
real, allocatable :: input_data(:,:,:), gradient(:,:,:)
real, allocatable :: gradient(:,:,:)
real, allocatable :: output(:)
logical :: ok = .true.

Expand Down
1 change: 0 additions & 1 deletion test/test_get_set_network_params.f90
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ program test_get_set_network_params
use nf, only: conv2d, dense, flatten, input, maxpool2d, network
implicit none
type(network) :: net
integer :: n
logical :: ok = .true.
real :: test_params_dense(8) = [1, 2, 3, 4, 5, 6, 7, 8]
real :: test_params_conv2d(10) = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Expand Down
2 changes: 1 addition & 1 deletion test/test_optimizers.f90
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ program test_optimizers
real, allocatable :: x(:), y(:)
real, allocatable :: ypred(:)
integer, parameter :: num_iterations = 1000
integer :: n, i
integer :: n
logical :: ok = .true.
logical :: converged = .false.

Expand Down

0 comments on commit a843c83

Please sign in to comment.