rjhogan / Adept-2

Combined array and automatic differentiation library in C++
http://www.met.reading.ac.uk/clouds/adept/
Apache License 2.0
163 stars 29 forks source link

differentiator.h:383:17: error: 'aReal' was not declared in this scope; did you mean 'adept::aReal'? #25

Closed barracuda156 closed 1 year ago

barracuda156 commented 1 year ago

Tests also fail to build with gcc12:

In file included from autodiff_benchmark.cpp:17:
differentiator.h: In member function 'virtual bool AdolcDifferentiator::adjoint(TestAlgorithm, const std::vector<double>&, std::vector<double>&, const std::vector<double>&, std::vector<double>&)':
differentiator.h:383:17: error: 'aReal' was not declared in this scope; did you mean 'adept::aReal'?
  383 |     std::vector<aReal> q_init(NX);
      |                 ^~~~~
      |                 adept::aReal
In file included from ../include/adept.h:18,
                 from differentiator.h:23:
../include/adept/scalar_shortcuts.h:22:24: note: 'adept::aReal' declared here
   22 |   typedef Active<Real> aReal;
      |                        ^~~~~
differentiator.h:383:22: error: template argument 1 is invalid
  383 |     std::vector<aReal> q_init(NX);
      |                      ^
differentiator.h:383:22: error: template argument 2 is invalid
differentiator.h:384:22: error: template argument 2 is invalid
  384 |     std::vector<aReal> q(NX);
      |                      ^
differentiator.h:389:13: error: invalid types 'int[int]' for array subscript
  389 |       q_init[i] <<= x[i];
      |             ^
differentiator.h:392:9: error: no matching function for call to 'AdolcDifferentiator::func(TestAlgorithm&, int&, int&)'
  392 |     func(test_algorithm, q_init, q);
      |     ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
differentiator.h:96:8: note: candidate: 'template<class ActiveRealType> void Differentiator::func(TestAlgorithm, const std::vector<T>&, std::vector<T>&)'
   96 |   void func(TestAlgorithm test_algorithm,
      |        ^~~~
differentiator.h:96:8: note:   template argument deduction/substitution failed:
differentiator.h:392:9: note:   mismatched types 'const std::vector<T>' and 'int'
  392 |     func(test_algorithm, q_init, q);
      |     ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
differentiator.h:395:8: error: invalid types 'int[int]' for array subscript
  395 |       q[i] >>= y[i];
      |        ^
differentiator.h: In member function 'virtual bool AdolcDifferentiator::jacobian(TestAlgorithm, const std::vector<double>&, std::vector<double>&, std::vector<double>&, int)':
differentiator.h:420:17: error: 'aReal' was not declared in this scope; did you mean 'adept::aReal'?
  420 |     std::vector<aReal> q_init(NX);
      |                 ^~~~~
      |                 adept::aReal
../include/adept/scalar_shortcuts.h:22:24: note: 'adept::aReal' declared here
   22 |   typedef Active<Real> aReal;
      |                        ^~~~~
differentiator.h:420:22: error: template argument 1 is invalid
  420 |     std::vector<aReal> q_init(NX);
      |                      ^
differentiator.h:420:22: error: template argument 2 is invalid
differentiator.h:421:22: error: template argument 2 is invalid
  421 |     std::vector<aReal> q(NX);
      |                      ^
differentiator.h:426:13: error: invalid types 'int[int]' for array subscript
  426 |       q_init[i] <<= x[i];
      |             ^
differentiator.h:429:9: error: no matching function for call to 'AdolcDifferentiator::func(TestAlgorithm&, int&, int&)'
  429 |     func(test_algorithm, q_init, q);
      |     ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
differentiator.h:96:8: note: candidate: 'template<class ActiveRealType> void Differentiator::func(TestAlgorithm, const std::vector<T>&, std::vector<T>&)'
   96 |   void func(TestAlgorithm test_algorithm,
      |        ^~~~
differentiator.h:96:8: note:   template argument deduction/substitution failed:
differentiator.h:429:9: note:   mismatched types 'const std::vector<T>' and 'int'
  429 |     func(test_algorithm, q_init, q);
      |     ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
differentiator.h:432:8: error: invalid types 'int[int]' for array subscript
  432 |       q[i] >>= y[i];
      |        ^
make[2]: *** [autodiff_benchmark-autodiff_benchmark.o] Error 1
make[1]: *** [check-am] Error 2
make: *** [check-recursive] Error 1
barracuda156 commented 1 year ago

Also same error from 2.1.1 and master branch.

rjhogan commented 1 year ago

I hadn't tested ADOL-C for a long time, and an earlier change broke the ability to use its "adouble" type. Now fixed - please try the latest version.

barracuda156 commented 1 year ago

Let me try.

barracuda156 commented 1 year ago

@rjhogan So the error reported above is fixed. gcc12 fails, however, with familiar linking errors (known bug in gcc12):

libtool: link: /opt/local/bin/g++-mp-12 -fopenmp -pipe -Os -arch ppc -Wl,-headerpad_max_install_names -Wl,-rpath -Wl,/opt/local/lib/libgcc -arch ppc -o autodiff_benchmark autodiff_benchmark-autodiff_benchmark.o  -L../adept/.libs -L/opt/local/lib /opt/local/var/macports/build/_opt_PPCRosettaPorts_math_adept2/adept2-devel/work/Adept-2-d9e83012618049bba8d1b9bd0954f60f1bc170a8/adept/.libs/libadept.a /opt/local/lib/libadolc.dylib -lopenblas -fopenmp
Undefined symbols:
  "__ZTHN5adept21_stack_current_threadE", referenced from:
      __ZN5adept6ActiveIdEaSIdNS_15ActiveReferenceIdEEEENS_8internal9enable_ifIXaasrT0_9is_activeeqsrS7_4rankLi0EERS1_E4typeERKNS_10ExpressionIT_S7_EE.isra.0 in autodiff_benchmark-autodiff_benchmark.o
      __ZN5adept6ActiveIdEaSIdNS_15ActiveReferenceIdEEEENS_8internal9enable_ifIXaasrT0_9is_activeeqsrS7_4rankLi0EERS1_E4typeERKNS_10ExpressionIT_S7_EE.isra.0 in autodiff_benchmark-autodiff_benchmark.o
      __ZN5adept6ActiveIdEaSIdNS_15ActiveReferenceIdEEEENS_8internal9enable_ifIXaasrT0_9is_activeeqsrS7_4rankLi0EERS1_E4typeERKNS_10ExpressionIT_S7_EE.isra.0 in autodiff_benchmark-autodiff_benchmark.o
      __ZN5adept6ActiveIdEpLIdNS_8internal15BinaryOperationIdS1_NS3_8SubtractES1_EEEENS3_9enable_ifIXeqsrT0_4rankLi0EERS1_E4typeERKNS_10ExpressionIT_S8_EE.isra.0 in autodiff_benchmark-autodiff_benchmark.o
      __ZN5adept6ActiveIdEpLIdNS_8internal15BinaryOperationIdS1_NS3_8SubtractES1_EEEENS3_9enable_ifIXeqsrT0_4rankLi0EERS1_E4typeERKNS_10ExpressionIT_S8_EE.isra.0 in autodiff_benchmark-autodiff_benchmark.o
      __ZN5adept6ActiveIdEpLIdNS_8internal15BinaryOperationIdS1_NS3_8SubtractES1_EEEENS3_9enable_ifIXeqsrT0_4rankLi0EERS1_E4typeERKNS_10ExpressionIT_S8_EE.isra.0 in autodiff_benchmark-autodiff_benchmark.o
      __ZN5adept15ActiveReferenceIdEaSERKS1_.isra.0 in autodiff_benchmark-autodiff_benchmark.o
      __ZN5adept15ActiveReferenceIdEaSERKS1_.isra.0 in autodiff_benchmark-autodiff_benchmark.o
      __ZN5adept15ActiveReferenceIdEaSERKS1_.isra.0 in autodiff_benchmark-autodiff_benchmark.o
      __ZN5adept15ActiveReferenceIdEaSIdEERS1_RKNS_6ActiveIT_EE.isra.0 in autodiff_benchmark-autodiff_benchmark.o
      __ZN5adept15ActiveReferenceIdEaSIdEERS1_RKNS_6ActiveIT_EE.isra.0 in autodiff_benchmark-autodiff_benchmark.o
      __ZN5adept15ActiveReferenceIdEaSIdEERS1_RKNS_6ActiveIT_EE.isra.0 in autodiff_benchmark-autodiff_benchmark.o
      __ZN5adept6ActiveIdEaSERKS1_.isra.0 in autodiff_benchmark-autodiff_benchmark.o
      __ZN5adept6ActiveIdEaSERKS1_.isra.0 in autodiff_benchmark-autodiff_benchmark.o
      __ZN5adept6ActiveIdEaSERKS1_.isra.0 in autodiff_benchmark-autodiff_benchmark.o
      __ZN5adept6ActiveIdED1Ev in autodiff_benchmark-autodiff_benchmark.o
      __ZN5adept6ActiveIdEC4Ev in autodiff_benchmark-autodiff_benchmark.o
      __Z12lax_wendroffIN5adept6ActiveIdEEdEviT0_PKT_PS4_ in autodiff_benchmark-autodiff_benchmark.o
      __Z12lax_wendroffIN5adept6ActiveIdEEdEviT0_PKT_PS4_ in autodiff_benchmark-autodiff_benchmark.o
      __Z12lax_wendroffIN5adept6ActiveIdEEdEviT0_PKT_PS4_ in autodiff_benchmark-autodiff_benchmark.o
      __Z4toonIN5adept6ActiveIdEEdEviT0_PKT_PS4_ in autodiff_benchmark-autodiff_benchmark.o
      __Z4toonIN5adept6ActiveIdEEdEviT0_PKT_PS4_ in autodiff_benchmark-autodiff_benchmark.o
      __Z4toonIN5adept6ActiveIdEEdEviT0_PKT_PS4_ in autodiff_benchmark-autodiff_benchmark.o
      __ZN5adept7StorageIdE11remove_linkEv in autodiff_benchmark-autodiff_benchmark.o
      __ZN5adept5ArrayILi1EdLb1EE6resizeEPKib in autodiff_benchmark-autodiff_benchmark.o
      __ZN5adept5ArrayILi1EdLb1EE18assign_expression_ILi1ELb1ELb1ES1_EENS_8internal9enable_ifIXaaT0_T1_EvE4typeET2_ in autodiff_benchmark-autodiff_benchmark.o
      __ZN5adept5ArrayILi1EdLb1EE18assign_expression_ILi1ELb1ELb1ES1_EENS_8internal9enable_ifIXaaT0_T1_EvE4typeET2_ in autodiff_benchmark-autodiff_benchmark.o
      __ZN5adept5ArrayILi1EdLb1EE18assign_expression_ILi1ELb1ELb1ES1_EENS_8internal9enable_ifIXaaT0_T1_EvE4typeET2_ in autodiff_benchmark-autodiff_benchmark.o
      __ZN5adept5ArrayILi1EdLb1EE18assign_expression_ILi1ELb1ELb1ENS_8internal18BinaryOpScalarLeftIddNS3_8MultiplyENS3_15BinaryOperationIdNS6_IdS1_NS3_3AddES1_EES7_NS4_IddS5_NS6_IdS1_NS3_8SubtractES1_EEEEEEEEEENS3_9enable_ifIXaaT0_T1_EvE4typeET2_ in autodiff_benchmark-autodiff_benchmark.o
      __ZN5adept5ArrayILi1EdLb1EE18assign_expression_ILi1ELb1ELb1ENS_8internal18BinaryOpScalarLeftIddNS3_8MultiplyENS3_15BinaryOperationIdNS6_IdS1_NS3_3AddES1_EES7_NS4_IddS5_NS6_IdS1_NS3_8SubtractES1_EEEEEEEEEENS3_9enable_ifIXaaT0_T1_EvE4typeET2_ in autodiff_benchmark-autodiff_benchmark.o
      __ZN5adept5ArrayILi1EdLb1EE18assign_expression_ILi1ELb1ELb1ENS_8internal18BinaryOpScalarLeftIddNS3_8MultiplyENS3_15BinaryOperationIdNS6_IdS1_NS3_3AddES1_EES7_NS4_IddS5_NS6_IdS1_NS3_8SubtractES1_EEEEEEEEEENS3_9enable_ifIXaaT0_T1_EvE4typeET2_ in autodiff_benchmark-autodiff_benchmark.o
      __ZN5adept5ArrayILi1EdLb1EE18assign_expression_ILi1ELb1ELb1ENS_8internal7NoAliasIdNS3_15BinaryOperationIdS1_NS3_3AddENS5_IdS1_NS3_8SubtractES1_EEEEEEEENS3_9enable_ifIXaaT0_T1_EvE4typeET2_ in autodiff_benchmark-autodiff_benchmark.o
      __ZN5adept5ArrayILi1EdLb1EE18assign_expression_ILi1ELb1ELb1ENS_8internal7NoAliasIdNS3_15BinaryOperationIdS1_NS3_3AddENS5_IdS1_NS3_8SubtractES1_EEEEEEEENS3_9enable_ifIXaaT0_T1_EvE4typeET2_ in autodiff_benchmark-autodiff_benchmark.o
      __ZN5adept5ArrayILi1EdLb1EE18assign_expression_ILi1ELb1ELb1ENS_8internal7NoAliasIdNS3_15BinaryOperationIdS1_NS3_3AddENS5_IdS1_NS3_8SubtractES1_EEEEEEEENS3_9enable_ifIXaaT0_T1_EvE4typeET2_ in autodiff_benchmark-autodiff_benchmark.o
      __ZN5adept5ArrayILi1EdLb1EE18assign_expression_ILi1ELb1ELb1ENS_8internal15BinaryOperationIdNS4_IdNS4_IdNS3_19BinaryOpScalarRightIdNS3_14UnaryOperationIdNS3_3ExpENS3_18BinaryOpScalarLeftIddNS3_8MultiplyENS6_IdNS3_3LogENS4_IdS1_NS3_6DivideES1_EEEEEEEENS3_8SubtractEdEES9_S1_EES9_S1_EESB_NS4_IdS1_SG_S1_EEEEEENS3_9enable_ifIXaaT0_T1_EvE4typeET2_ in autodiff_benchmark-autodiff_benchmark.o
      __ZN5adept5ArrayILi1EdLb1EE18assign_expression_ILi1ELb1ELb1ENS_8internal15BinaryOperationIdNS4_IdNS4_IdNS3_19BinaryOpScalarRightIdNS3_14UnaryOperationIdNS3_3ExpENS3_18BinaryOpScalarLeftIddNS3_8MultiplyENS6_IdNS3_3LogENS4_IdS1_NS3_6DivideES1_EEEEEEEENS3_8SubtractEdEES9_S1_EES9_S1_EESB_NS4_IdS1_SG_S1_EEEEEENS3_9enable_ifIXaaT0_T1_EvE4typeET2_ in autodiff_benchmark-autodiff_benchmark.o
      __ZN5adept5ArrayILi1EdLb1EE18assign_expression_ILi1ELb1ELb1ENS_8internal15BinaryOperationIdNS4_IdNS4_IdNS3_19BinaryOpScalarRightIdNS3_14UnaryOperationIdNS3_3ExpENS3_18BinaryOpScalarLeftIddNS3_8MultiplyENS6_IdNS3_3LogENS4_IdS1_NS3_6DivideES1_EEEEEEEENS3_8SubtractEdEES9_S1_EES9_S1_EESB_NS4_IdS1_SG_S1_EEEEEENS3_9enable_ifIXaaT0_T1_EvE4typeET2_ in autodiff_benchmark-autodiff_benchmark.o
      __ZN19AdeptDifferentiator7adjointE13TestAlgorithmRKSt6vectorIdSaIdEERS3_S5_S6_ in autodiff_benchmark-autodiff_benchmark.o
      __ZN19AdeptDifferentiator7adjointE13TestAlgorithmRKSt6vectorIdSaIdEERS3_S5_S6_ in autodiff_benchmark-autodiff_benchmark.o
      __ZTHN5adept21_stack_current_threadE$non_lazy_ptr in autodiff_benchmark-autodiff_benchmark.o
      __ZN5adept7StorageIdE11remove_linkEv in libadept.a(libadept_la-jacobian.o)
      __ZTHN5adept21_stack_current_threadE$non_lazy_ptr in libadept.a(libadept_la-jacobian.o)
     (maybe you meant: __ZTHN5adept21_stack_current_threadE$non_lazy_ptr)
ld: symbol(s) not found
collect2: error: ld returned 1 exit status

These have nothing to do with adept, and should be fixed in next version, hopefully: https://github.com/iains/darwin-toolchains-start-here/discussions/41

Using gcc11, that is gone, but <cstddef> header missing:

In file included from test_no_lib.cpp:18:
../include/adept_source.h: In function 'int adept::internal::cpplapack_getri(int, float*, int, const int*)':
../include/adept_source.h:178:43: error: 'size_t' does not name a type
  178 |       std::vector<float> work(static_cast<size_t>(lwork));
      |                                           ^~~~~~
../include/adept_source.h:115:1: note: 'size_t' is defined in header '<cstddef>'; did you forget to '#include <cstddef>'?
  114 | #include <vector>
  +++ |+#include <cstddef>
  115 | 
../include/adept_source.h: In function 'int adept::internal::cpplapack_getri(int, double*, int, const int*)':
../include/adept_source.h:191:44: error: 'size_t' does not name a type
  191 |       std::vector<double> work(static_cast<size_t>(lwork));
      |                                            ^~~~~~
../include/adept_source.h:191:44: note: 'size_t' is defined in header '<cstddef>'; did you forget to '#include <cstddef>'?
../include/adept_source.h: In function 'int adept::internal::cpplapack_sytrf(char, int, float*, int, int*)':
../include/adept_source.h:206:43: error: 'size_t' does not name a type
  206 |       std::vector<float> work(static_cast<size_t>(lwork));
      |                                           ^~~~~~
../include/adept_source.h:206:43: note: 'size_t' is defined in header '<cstddef>'; did you forget to '#include <cstddef>'?
../include/adept_source.h: In function 'int adept::internal::cpplapack_sytrf(char, int, double*, int, int*)':
../include/adept_source.h:219:44: error: 'size_t' does not name a type
  219 |       std::vector<double> work(static_cast<size_t>(lwork));
      |                                            ^~~~~~
../include/adept_source.h:219:44: note: 'size_t' is defined in header '<cstddef>'; did you forget to '#include <cstddef>'?
../include/adept_source.h: In function 'int adept::internal::cpplapack_sysv(char, int, int, float*, int, int*, float*, int)':
../include/adept_source.h:267:43: error: 'size_t' does not name a type
  267 |       std::vector<float> work(static_cast<size_t>(lwork));
      |                                           ^~~~~~
../include/adept_source.h:267:43: note: 'size_t' is defined in header '<cstddef>'; did you forget to '#include <cstddef>'?
../include/adept_source.h: In function 'int adept::internal::cpplapack_sysv(char, int, int, double*, int, int*, double*, int)':
../include/adept_source.h:281:44: error: 'size_t' does not name a type
  281 |       std::vector<double> work(static_cast<size_t>(lwork));
      |                                            ^~~~~~
../include/adept_source.h:281:44: note: 'size_t' is defined in header '<cstddef>'; did you forget to '#include <cstddef>'?
make[1]: *** [test_no_lib.o] Error 1
make: *** [check-recursive] Error 1
barracuda156 commented 1 year ago

@rjhogan Perhaps rather <stddef.h> needed and not <cstddef>? Old compilers may not support the latter, I guess. But one of these.

barracuda156 commented 1 year ago

With <cstddef> added to suggested spot in adept_source.h and using gcc11 to build, 100% of tests pass on 10.6.8 ppc32:

test_adept... PASSED
test_adept_with_and_without_ad... PASSED
test_radiances... PASSED
test_gsl_interface... PASSED
test_misc... PASSED
test_checkpoint... PASSED
test_thread_safe... PASSED
test_array_speed... PASSED
test_no_lib... PASSED
test_radiances_array... PASSED
test_constructors... PASSED
test_arrays... PASSED
test_arrays_active... PASSED
test_arrays_active_pausable... PASSED
test_fixed_arrays... PASSED
test_fixed_arrays_active... PASSED
test_derivatives... PASSED
test_array_derivatives... PASSED
test_thread_safe_arrays... PASSED
test_complex_arrays... PASSED
test_packet_operations... PASSED
test_fastexp... PASSED
test_reduce_active... PASSED
test_minimizer... PASSED

All test programs ran successfully
barracuda156 commented 1 year ago

@rjhogan So the only remaining issue is missing header in adept_source.h: should be somehow added into create_adept_source_header.

rjhogan commented 1 year ago

Issue more that size_t in cpplapack.h was not prefixed by std:: - try the latest push

barracuda156 commented 1 year ago

All good now, thanks again!