Skip to content

Commit

Permalink
Restructure ifdefs for bug workarounds to remove repeated code
Browse files Browse the repository at this point in the history
  • Loading branch information
ktras committed Mar 12, 2024
1 parent c4ea84b commit e30e8e8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
12 changes: 4 additions & 8 deletions src/inference_engine/inference_engine_s.F90
Original file line number Diff line number Diff line change
Expand Up @@ -202,25 +202,21 @@ function get_key_value(line) result(value_)
#ifdef __INTEL_COMPILER
character(len=:), allocatable :: text_after_colon
integer :: opening_value_quotes, closing_value_quotes

text_after_colon = line(index(line, ':')+1:)
opening_value_quotes = index(text_after_colon, '"')
closing_value_quotes = opening_value_quotes + index(text_after_colon(opening_value_quotes+1:), '"')

if (any([opening_value_quotes, closing_value_quotes] == 0)) then
value_ = string_t(trim(adjustl((text_after_colon))))
else
value_ = string_t(text_after_colon(opening_value_quotes+1:closing_value_quotes-1))
end if
#else
#endif
#ifndef __INTEL_COMPILER
associate(text_after_colon => line(index(line, ':')+1:))
associate(opening_value_quotes => index(text_after_colon, '"'))
associate(closing_value_quotes => opening_value_quotes + index(text_after_colon(opening_value_quotes+1:), '"'))
#endif
if (any([opening_value_quotes, closing_value_quotes] == 0)) then
value_ = string_t(trim(adjustl((text_after_colon))))
else
value_ = string_t(text_after_colon(opening_value_quotes+1:closing_value_quotes-1))
end if
#ifndef __INTEL_COMPILER
end associate
end associate
end associate
Expand Down
13 changes: 6 additions & 7 deletions src/inference_engine/training_configuration_s.F90
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,25 @@
integer, parameter :: hyperparameters_start=2, hyperparameters_end=6, separator_line=7 ! line numbers
integer, parameter :: net_config_start=8, net_config_end=12 ! line numbers
integer, parameter :: file_start=hyperparameters_start-1, file_end=net_config_end+1 ! line numbers
#ifdef __INTEL_COMPILER
type(string_t), allocatable :: lines(:)
#endif

training_configuration%file_t = file_object

#ifdef __INTEL_COMPILER
lines = training_configuration%file_t%lines()
call assert(trim(adjustl(lines(file_start)%string()))==header,"training_configuration_s(from_file): header",lines(file_start))
training_configuration%hyperparameters_ = hyperparameters_t(lines(hyperparameters_start:hyperparameters_end))
call assert(trim(adjustl(lines(separator_line)%string()))==separator,"training_configuration_s(from_file): separator", &
lines(file_start))
training_configuration%network_configuration_= network_configuration_t(lines(net_config_start:net_config_end))
call assert(trim(adjustl(lines(file_end)%string()))==footer, "training_configuration_s(from_file): footer", lines(file_end))
#else
#endif
#ifndef __INTEL_COMPILER
associate(lines => training_configuration%file_t%lines())
#endif
call assert(trim(adjustl(lines(file_start)%string()))==header,"training_configuration_s(from_file): header",lines(file_start))
training_configuration%hyperparameters_ = hyperparameters_t(lines(hyperparameters_start:hyperparameters_end))
call assert(trim(adjustl(lines(separator_line)%string()))==separator,"training_configuration_s(from_file): separator", &
lines(file_start))
training_configuration%network_configuration_= network_configuration_t(lines(net_config_start:net_config_end))
call assert(trim(adjustl(lines(file_end)%string()))==footer, "training_configuration_s(from_file): footer", lines(file_end))
#ifndef __INTEL_COMPILER
end associate
#endif

Expand Down

0 comments on commit e30e8e8

Please sign in to comment.