Skip to content

Commit 3a25234

Browse files
committed
core: specialized cast helper
1 parent 6b97b07 commit 3a25234

2 files changed

Lines changed: 47 additions & 1 deletion

File tree

include/pycppad/cast.hpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
/*
2-
* Copyright 2021 INRIA
2+
* Copyright 2021-2022 INRIA
33
*/
44

55
#ifndef __pycppad_cast_hpp__
66
#define __pycppad_cast_hpp__
77

88
#include "pycppad/fwd.hpp"
99

10+
#include <eigenpy/user-type.hpp>
11+
1012
namespace pycppad
1113
{
1214
namespace internal
@@ -42,4 +44,26 @@ namespace pycppad
4244
} // namespace internal
4345
} // namespace pycppad
4446

47+
namespace eigenpy {
48+
49+
template <typename Scalar, typename To>
50+
struct cast<::CppAD::AD<Scalar>, To>
51+
{
52+
typedef ::CppAD::AD<Scalar> From;
53+
static To run(const From & from) {
54+
return ::pycppad::internal::Cast<From, To>::run(from);
55+
}
56+
};
57+
58+
template <typename From, typename Scalar>
59+
struct cast<From,::CppAD::AD<Scalar>>
60+
{
61+
typedef ::CppAD::AD<Scalar> To;
62+
static To run(const From & from) {
63+
return To(static_cast<Scalar>(from));
64+
}
65+
};
66+
67+
} // namespace eigenpy
68+
4569
#endif //#ifndef __pycppad_cast_hpp__

include/pycppad/codegen/cg.hpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,28 @@
1212

1313
#include "pycppad/cast.hpp"
1414

15+
namespace eigenpy {
16+
17+
template <typename Scalar, typename To>
18+
struct cast<::CppAD::cg::CG<Scalar>, To>
19+
{
20+
typedef ::CppAD::cg::CG<Scalar> From;
21+
static To run(const From & from) {
22+
return ::pycppad::internal::Cast<From, To>::run(from);
23+
}
24+
};
25+
26+
template <typename From, typename Scalar>
27+
struct cast<From,::CppAD::cg::CG<Scalar>>
28+
{
29+
typedef ::CppAD::cg::CG<Scalar> To;
30+
static To run(const From & from) {
31+
return To(static_cast<Scalar>(from));
32+
}
33+
};
34+
35+
} // namespace eigenpy
36+
1537
namespace pycppad
1638
{
1739
namespace internal

0 commit comments

Comments
 (0)