-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
stable/20240000: base_complex.cpp: copy fix from master (without chan…
…ge to specifications).
- Loading branch information
Showing
4 changed files
with
64 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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> | ||
|
@@ -12,7 +12,7 @@ | |
{xrst_begin base_complex.hpp} | ||
{xrst_spell | ||
complier | ||
invocations | ||
ge | ||
isnan | ||
} | ||
|
@@ -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 , | ||
|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
# | ||
|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
@@ -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); | ||
|
@@ -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" ); | ||
|