@@ -34,8 +34,7 @@ double f(const Vector2& x) {
3434TEST (testNumericalDerivative, numericalGradient) {
3535 Vector2 x (1 , 1.1 );
3636
37- Vector expected (2 );
38- expected << cos (x (0 )), -sin (x (1 ));
37+ Vector expected{{cos (x (0 )), -sin (x (1 ))}};
3938
4039 Vector actual = numericalGradient<Vector2>(f, x);
4140
@@ -46,8 +45,7 @@ TEST(testNumericalDerivative, numericalGradient) {
4645TEST (testNumericalDerivative, numericalHessian) {
4746 Vector2 x (1 , 1.1 );
4847
49- Matrix expected (2 , 2 );
50- expected << -sin (x (0 )), 0.0 , 0.0 , -cos (x (1 ));
48+ Matrix expected{{-sin (x (0 )), 0.0 , 0.0 , -cos (x (1 ))}};
5149
5250 Matrix actual = numericalHessian<Vector2>(f, x);
5351
@@ -66,8 +64,8 @@ TEST(testNumericalDerivative, numericalHessian2) {
6664 Vector2 v (0.5 , 1.0 );
6765 Vector2 x (v);
6866
69- Matrix expected = ( Matrix ( 2 , 2 ) << -cos (x (1 )) * sin (x (0 )), -sin (x (1 ))
70- * cos ( x ( 0 )), -cos (x (0 )) * sin (x (1 )), -sin (x (0 )) * cos (x (1 ))). finished () ;
67+ Matrix expected{{ -cos (x (1 )) * sin (x (0 )), -sin (x (1 )) * cos ( x ( 0 ))},
68+ { -cos (x (0 )) * sin (x (1 )), -sin (x (0 )) * cos (x (1 ))}} ;
7169
7270 Matrix actual = numericalHessian (f2, x);
7371
@@ -84,15 +82,15 @@ double f3(double x1, double x2) {
8482TEST (testNumericalDerivative, numericalHessian211) {
8583 double x1 = 1 , x2 = 5 ;
8684
87- Matrix expected11 = ( Matrix ( 1 , 1 ) << -sin (x1) * cos (x2)). finished () ;
85+ Matrix expected11{{ -sin (x1) * cos (x2)}} ;
8886 Matrix actual11 = numericalHessian211<double , double >(f3, x1, x2);
8987 EXPECT (assert_equal (expected11, actual11, 1e-5 ));
9088
91- Matrix expected12 = ( Matrix ( 1 , 1 ) << -cos (x1) * sin (x2)). finished () ;
89+ Matrix expected12{{ -cos (x1) * sin (x2)}} ;
9290 Matrix actual12 = numericalHessian212<double , double >(f3, x1, x2);
9391 EXPECT (assert_equal (expected12, actual12, 1e-5 ));
9492
95- Matrix expected22 = ( Matrix ( 1 , 1 ) << -sin (x1) * cos (x2)). finished () ;
93+ Matrix expected22{{ -sin (x1) * cos (x2)}} ;
9694 Matrix actual22 = numericalHessian222<double , double >(f3, x1, x2);
9795 EXPECT (assert_equal (expected22, actual22, 1e-5 ));
9896}
@@ -112,52 +110,48 @@ double f4(double x, double y, double z) {
112110//
113111TEST (testNumericalDerivative, numericalHessian311) {
114112 double x = 1 , y = 2 , z = 3 ;
115- Matrix expected11 = ( Matrix ( 1 , 1 ) << -sin (x) * cos (y) * z * z). finished () ;
116- Matrix actual11 = numericalHessian311<double , double , double >(f4, x, y, z);
113+ Matrix11 expected11{{ -sin (x) * cos (y) * z * z}} ;
114+ Matrix11 actual11 = numericalHessian311<double , double , double >(f4, x, y, z);
117115 EXPECT (assert_equal (expected11, actual11, 1e-5 ));
118116
119- Matrix expected12 = ( Matrix ( 1 , 1 ) << -cos (x) * sin (y) * z * z). finished () ;
120- Matrix actual12 = numericalHessian312<double , double , double >(f4, x, y, z);
117+ Matrix11 expected12{{ -cos (x) * sin (y) * z * z}} ;
118+ Matrix11 actual12 = numericalHessian312<double , double , double >(f4, x, y, z);
121119 EXPECT (assert_equal (expected12, actual12, 1e-5 ));
122120
123- Matrix expected13 = ( Matrix ( 1 , 1 ) << cos (x) * cos (y) * 2 * z). finished () ;
124- Matrix actual13 = numericalHessian313<double , double , double >(f4, x, y, z);
121+ Matrix11 expected13{{ cos (x) * cos (y) * 2 * z}} ;
122+ Matrix11 actual13 = numericalHessian313<double , double , double >(f4, x, y, z);
125123 EXPECT (assert_equal (expected13, actual13, 1e-5 ));
126124
127- Matrix expected22 = ( Matrix ( 1 , 1 ) << -sin (x) * cos (y) * z * z). finished () ;
128- Matrix actual22 = numericalHessian322<double , double , double >(f4, x, y, z);
125+ Matrix11 expected22{{ -sin (x) * cos (y) * z * z}} ;
126+ Matrix11 actual22 = numericalHessian322<double , double , double >(f4, x, y, z);
129127 EXPECT (assert_equal (expected22, actual22, 1e-5 ));
130128
131- Matrix expected23 = ( Matrix ( 1 , 1 ) << -sin (x) * sin (y) * 2 * z). finished () ;
132- Matrix actual23 = numericalHessian323<double , double , double >(f4, x, y, z);
129+ Matrix11 expected23{{ -sin (x) * sin (y) * 2 * z}} ;
130+ Matrix11 actual23 = numericalHessian323<double , double , double >(f4, x, y, z);
133131 EXPECT (assert_equal (expected23, actual23, 1e-5 ));
134132
135- Matrix expected33 = ( Matrix ( 1 , 1 ) << sin (x) * cos (y) * 2 ). finished () ;
136- Matrix actual33 = numericalHessian333<double , double , double >(f4, x, y, z);
133+ Matrix11 expected33{{ sin (x) * cos (y) * 2 }} ;
134+ Matrix11 actual33 = numericalHessian333<double , double , double >(f4, x, y, z);
137135 EXPECT (assert_equal (expected33, actual33, 1e-5 ));
138136}
139137
140138/* ************************************************************************* */
141139Vector6 f6 (const double x1, const double x2, const double x3, const double x4,
142140 const double x5, const double x6) {
143- Vector6 result;
144- result << sin (x1), cos (x2), x3 * x3, x4 * x4 * x4, sqrt (x5), sin (x6) - cos (x6);
145- return result;
141+ return {sin (x1), cos (x2), x3 * x3, x4 * x4 * x4, sqrt (x5), sin (x6) - cos (x6)};
146142}
147143
148144Vector g6 (const double x1, const double x2, const double x3, const double x4,
149145 const double x5, const double x6) {
150- Vector result (6 );
151- result << sin (x1), cos (x2), x3 * x3, x4 * x4 * x4, sqrt (x5), sin (x6) - cos (x6);
152- return result;
146+ return Vector (x1, x2, x3, x4, x5, x6);
153147}
154148
155149/* ************************************************************************* */
156150//
157151TEST (testNumericalDerivative, numeriDerivative61) {
158152 double x1 = 1 , x2 = 2 , x3 = 3 , x4 = 4 , x5 = 5 , x6 = 6 ;
159153
160- Matrix expected61 = ( Matrix ( 6 , 1 ) << cos (x1), 0 , 0 , 0 , 0 , 0 ). finished () ;
154+ Matrix expected61{{ cos (x1), 0 , 0 , 0 , 0 , 0 }} ;
161155 Matrix61 actual61 = numericalDerivative61<Vector6, double , double ,
162156 double , double , double , double >(f6, x1, x2, x3, x4, x5, x6);
163157
@@ -177,7 +171,7 @@ TEST(testNumericalDerivative, numeriDerivative61) {
177171TEST (testNumericalDerivative, numeriDerivative62) {
178172 double x1 = 1 , x2 = 2 , x3 = 3 , x4 = 4 , x5 = 5 , x6 = 6 ;
179173
180- Matrix expected62 = ( Matrix ( 6 , 1 ) << 0 , -sin (x2), 0 , 0 , 0 , 0 ). finished () ;
174+ Matrix expected62{{ 0 , -sin (x2), 0 , 0 , 0 , 0 }} ;
181175 Matrix61 actual62 = numericalDerivative62<Vector6, double , double , double ,
182176 double , double , double >(f6, x1, x2, x3, x4, x5, x6);
183177
@@ -196,7 +190,7 @@ TEST(testNumericalDerivative, numeriDerivative62) {
196190TEST (testNumericalDerivative, numeriDerivative63) {
197191 double x1 = 1 , x2 = 2 , x3 = 3 , x4 = 4 , x5 = 5 , x6 = 6 ;
198192
199- Matrix expected63 = ( Matrix ( 6 , 1 ) << 0 , 0 , 2 * x3, 0 , 0 , 0 ). finished () ;
193+ Matrix expected63{{ 0 , 0 , 2 * x3, 0 , 0 , 0 }} ;
200194 Matrix61 actual63 = numericalDerivative63<Vector6, double , double , double ,
201195 double , double , double >(f6, x1, x2, x3, x4, x5, x6);
202196
@@ -216,7 +210,7 @@ TEST(testNumericalDerivative, numeriDerivative63) {
216210TEST (testNumericalDerivative, numeriDerivative64) {
217211 double x1 = 1 , x2 = 2 , x3 = 3 , x4 = 4 , x5 = 5 , x6 = 6 ;
218212
219- Matrix expected64 = ( Matrix ( 6 , 1 ) << 0 , 0 , 0 , 3 * x4 * x4, 0 , 0 ). finished () ;
213+ Matrix expected64{{ 0 , 0 , 0 , 3 * x4 * x4, 0 , 0 }} ;
220214 Matrix61 actual64 = numericalDerivative64<Vector6, double , double , double ,
221215 double , double , double >(f6, x1, x2, x3, x4, x5, x6);
222216
@@ -236,7 +230,7 @@ TEST(testNumericalDerivative, numeriDerivative64) {
236230TEST (testNumericalDerivative, numeriDerivative65) {
237231 double x1 = 1 , x2 = 2 , x3 = 3 , x4 = 4 , x5 = 5 , x6 = 6 ;
238232
239- Matrix expected65 = ( Matrix ( 6 , 1 ) << 0 , 0 , 0 , 0 , 0.5 / sqrt (x5), 0 ). finished () ;
233+ Matrix expected65{{ 0 , 0 , 0 , 0 , 0.5 / sqrt (x5), 0 }} ;
240234 Matrix61 actual65 = numericalDerivative65<Vector6, double , double , double ,
241235 double , double , double >(f6, x1, x2, x3, x4, x5, x6);
242236
@@ -256,7 +250,7 @@ TEST(testNumericalDerivative, numeriDerivative65) {
256250TEST (testNumericalDerivative, numeriDerivative66) {
257251 double x1 = 1 , x2 = 2 , x3 = 3 , x4 = 4 , x5 = 5 , x6 = 6 ;
258252
259- Matrix expected66 = ( Matrix ( 6 , 1 ) << 0 , 0 , 0 , 0 , 0 , cos (x6) + sin (x6)). finished () ;
253+ Matrix expected66{{ 0 , 0 , 0 , 0 , 0 , cos (x6) + sin (x6)}} ;
260254 Matrix61 actual66 = numericalDerivative66<Vector6, double , double , double ,
261255 double , double , double >(f6, x1, x2, x3, x4, x5, x6);
262256
0 commit comments