| 1 |
/* { dg-do compile } */ |
| 2 |
// { dg-additional-options "-Wno-return-type" } |
| 3 |
|
| 4 |
template < typename > class basic_stringstream; |
| 5 |
|
| 6 |
struct basic_string { |
| 7 |
basic_string(); |
| 8 |
}; |
| 9 |
|
| 10 |
struct ios_base { |
| 11 |
virtual ~ios_base(); |
| 12 |
}; |
| 13 |
|
| 14 |
class ostream:ios_base {}; |
| 15 |
class istream:virtual ios_base {}; |
| 16 |
|
| 17 |
template < typename > struct basic_iostream:public istream, ostream { |
| 18 |
~basic_iostream () {} |
| 19 |
}; |
| 20 |
extern template class basic_iostream < char >; |
| 21 |
|
| 22 |
template < typename > struct basic_stringstream:public basic_iostream < char > { |
| 23 |
basic_string _M_stringbuf; |
| 24 |
~basic_stringstream () {} |
| 25 |
}; |
| 26 |
extern template class basic_stringstream < char >; |
| 27 |
|
| 28 |
template < typename > struct AnyMatrixBase; |
| 29 |
template < typename, int _Rows, int _Cols, int = _Rows, int = _Cols > class Matrix; |
| 30 |
template < typename > class CwiseNullaryOp; |
| 31 |
|
| 32 |
template < typename Derived > struct MatrixBase:public AnyMatrixBase < Derived > { |
| 33 |
typedef CwiseNullaryOp < Derived > ConstantReturnType; |
| 34 |
ConstantReturnType Constant (); |
| 35 |
template < typename > Derived cast (); |
| 36 |
static CwiseNullaryOp < Derived > Random (int); |
| 37 |
}; |
| 38 |
|
| 39 |
template < typename Derived > struct AnyMatrixBase { |
| 40 |
Derived derived () {} |
| 41 |
Derived & derived () const {} |
| 42 |
}; |
| 43 |
|
| 44 |
template < typename, int > struct ei_matrix_storage {}; |
| 45 |
|
| 46 |
template < typename _Scalar, int, int, int _MaxRows, int _MaxCols > struct Matrix:MatrixBase < Matrix < _Scalar, _MaxRows, _MaxCols > > { |
| 47 |
typedef MatrixBase < Matrix > Base; |
| 48 |
ei_matrix_storage < int, _MaxCols > m_storage; |
| 49 |
Matrix operator= (const Matrix other) { |
| 50 |
_resize_to_match (other); |
| 51 |
lazyAssign (other.derived ()); |
| 52 |
} |
| 53 |
template < typename OtherDerived > Matrix lazyAssign (MatrixBase < OtherDerived > other) { |
| 54 |
_resize_to_match (other); |
| 55 |
return Base (other.derived ()); |
| 56 |
} |
| 57 |
Matrix (); |
| 58 |
template < typename OtherDerived > Matrix (const MatrixBase < OtherDerived > &other) { |
| 59 |
*this = other; |
| 60 |
} |
| 61 |
template < typename OtherDerived > void _resize_to_match (const MatrixBase < OtherDerived > &) { |
| 62 |
throw 1; |
| 63 |
} |
| 64 |
}; |
| 65 |
|
| 66 |
template < typename MatrixType > class CwiseNullaryOp: |
| 67 |
public MatrixBase < CwiseNullaryOp < MatrixType > > {}; |
| 68 |
|
| 69 |
int f() |
| 70 |
{ |
| 71 |
bool align_cols; |
| 72 |
if (align_cols) { |
| 73 |
basic_stringstream<char> sstr; |
| 74 |
f(); |
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
template < typename > struct AutoDiffScalar; |
| 79 |
template < typename Functor > struct AutoDiffJacobian:Functor { |
| 80 |
AutoDiffJacobian (Functor); |
| 81 |
typedef typename Functor::InputType InputType; |
| 82 |
typedef typename Functor::ValueType ValueType; |
| 83 |
typedef Matrix < int, Functor::InputsAtCompileTime, 1 > DerivativeType; |
| 84 |
typedef AutoDiffScalar < DerivativeType > ActiveScalar; |
| 85 |
typedef Matrix < ActiveScalar, Functor::InputsAtCompileTime, 1 > ActiveInput; |
| 86 |
void operator () (InputType x, ValueType *) { |
| 87 |
ActiveInput ax = x.template cast < ActiveScalar > (); |
| 88 |
} |
| 89 |
}; |
| 90 |
|
| 91 |
template < int NX, int NY > struct TestFunc1 { |
| 92 |
enum { |
| 93 |
InputsAtCompileTime = NX |
| 94 |
}; |
| 95 |
typedef Matrix < float, NX, 1 > InputType; |
| 96 |
typedef Matrix < float, NY, 1 > ValueType; |
| 97 |
typedef Matrix < float, NY, NX > JacobianType; |
| 98 |
int inputs (); |
| 99 |
}; |
| 100 |
|
| 101 |
template < typename Func > void forward_jacobian (Func f) { |
| 102 |
typename Func::InputType x = Func::InputType::Random (f.inputs ()); |
| 103 |
typename Func::ValueType y; |
| 104 |
typename Func::JacobianType jref = jref.Constant (); |
| 105 |
AutoDiffJacobian < Func > autoj (f); |
| 106 |
autoj (x, &y); |
| 107 |
} |
| 108 |
|
| 109 |
void test_autodiff_scalar () |
| 110 |
{ |
| 111 |
forward_jacobian (TestFunc1 < 2, 2 > ()); |
| 112 |
forward_jacobian (TestFunc1 < 3, 2 > ()); |
| 113 |
} |