Skip to content

Commit

Permalink
stable/20240000: base_complex.cpp: copy fix from master (without chan…
Browse files Browse the repository at this point in the history
…ge to specifications).
  • Loading branch information
bradbell committed May 31, 2024
1 parent 6db6ac1 commit ef2e21c
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 7 deletions.
27 changes: 22 additions & 5 deletions include/cppad/core/base_complex.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# define CPPAD_CORE_BASE_COMPLEX_HPP
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
// SPDX-FileCopyrightText: Bradley M. Bell <[email protected]>
// SPDX-FileContributor: 2003-23 Bradley M. Bell
// SPDX-FileContributor: 2003-24 Bradley M. Bell
// ----------------------------------------------------------------------------
# include <cppad/configure.hpp>
# include <limits>
Expand All @@ -12,7 +12,7 @@
{xrst_begin base_complex.hpp}
{xrst_spell
complier
invocations
ge
isnan
}
Expand Down Expand Up @@ -44,13 +44,28 @@ in addition to including
CondExpOp
*********
The type ``std::complex<double>`` does not supports the
``<`` , ``<=`` , ``==`` , ``>=`` , and ``>`` operators; see
The type ``std::complex<double>`` does not support the
``<`` , ``<=`` , ``>=`` , and ``>`` operators; see
:ref:`base_cond_exp@CondExpTemplate@Not Ordered` .
Hence its ``CondExpOp`` function is defined by
Hence these operators and ``CondExpOp`` function are defined by
{xrst_spell_off}
{xrst_code cpp} */
# define CPPAD_TEMP(op) \
inline bool operator op( \
const std::complex<double>& left , \
const std::complex<double>& right ) \
{ CppAD::ErrorHandler::Call( \
true , __LINE__ , __FILE__ , \
"std::complex<double> " #op " std::complex<double>" , \
"Error: std::complex is not an ordered type" \
); \
return false; \
}
namespace CppAD {
CPPAD_TEMP(<)
CPPAD_TEMP(<=)
CPPAD_TEMP(>=)
CPPAD_TEMP(>)
inline std::complex<double> CondExpOp(
enum CppAD::CompareOp cop ,
const std::complex<double> &left ,
Expand All @@ -65,9 +80,11 @@ namespace CppAD {
return std::complex<double>(0);
}
}
# undef CPPAD_TEMP
/* {xrst_code}
{xrst_spell_on}
CondExpRel
**********
The :ref:`CPPAD_COND_EXP_REL<base_cond_exp@CondExpRel>` macro invocation
Expand Down
3 changes: 2 additions & 1 deletion test_more/general/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
# SPDX-FileCopyrightText: Bradley M. Bell <[email protected]>
# SPDX-FileContributor: 2003-23 Bradley M. Bell
# SPDX-FileContributor: 2003-24 Bradley M. Bell
# ----------------------------------------------------------------------------
# Build the test_more/general tests
#
Expand Down Expand Up @@ -48,6 +48,7 @@ SET(source_list
azmul.cpp
base2ad.cpp
base_alloc.cpp
base_complex.cpp
bool_sparsity.cpp
check_simple_vector.cpp
chkpoint_one.cpp
Expand Down
37 changes: 37 additions & 0 deletions test_more/general/base_complex.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
// SPDX-FileCopyrightText: Bradley M. Bell <[email protected]>
// SPDX-FileContributor: 2003-24 Bradley M. Bell
// ----------------------------------------------------------------------------

#include <cppad/cppad.hpp>

bool base_complex(void)
{ // ok
bool ok = true;
//
// base, ad_base
typedef std::complex<double> base;
typedef CppAD::AD<base> ad_base;
//
// f
CPPAD_TESTVECTOR(ad_base) ax(1), ay(1);
ax[0] = 0.0;
CppAD::Independent(ax);
ay[0] = ax[0] * ax[0];
CppAD::ADFun<base> f(ax, ay);
//
// f
f.optimize();
//
// dy
std::vector<base> x(1), dx(1), dy(1);
x[0] = 5;
f.Forward(0, x);
dx[0] = 1;
dy = f.Forward(1, dx);
//
// ok
ok &= dy[0] == 2.0 * x[0];
//
return ok;
}
4 changes: 3 additions & 1 deletion test_more/general/general.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
// SPDX-FileCopyrightText: Bradley M. Bell <[email protected]>
// SPDX-FileContributor: 2003-22 Bradley M. Bell
// SPDX-FileContributor: 2003-24 Bradley M. Bell
// ----------------------------------------------------------------------------

// CPPAD_HAS_* defines
Expand Down Expand Up @@ -71,6 +71,7 @@ extern bool azmul(void);
extern bool base2ad(void);
extern bool base_adolc(void);
extern bool base_alloc_test(void);
extern bool base_complex(void);
extern bool bool_sparsity(void);
extern bool check_simple_vector(void);
extern bool chkpoint_one(void);
Expand Down Expand Up @@ -193,6 +194,7 @@ int main(void)
Run( atomic_three, "atomic_three" );
Run( azmul, "azmul" );
Run( base2ad, "base2ad" );
Run( base_complex, "base_complex" );
Run( bool_sparsity, "bool_sparsity" );
Run( check_simple_vector, "check_simple_vector" );
Run( chkpoint_one, "chkpoint_one" );
Expand Down

0 comments on commit ef2e21c

Please sign in to comment.