Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Kirill Terekhov
INMOST
Commits
40108e63
Commit
40108e63
authored
Dec 09, 2016
by
Kirill Terekhov
Browse files
More unit tests
parent
f3e09d65
Changes
2
Hide whitespace changes
Inline
Side-by-side
Tests/autodiff_test000/CMakeLists.txt
View file @
40108e63
...
@@ -15,11 +15,12 @@ endif(USE_MPI)
...
@@ -15,11 +15,12 @@ endif(USE_MPI)
add_test
(
NAME autodiff_test000_hessian_sin COMMAND $<TARGET_FILE:autodiff_test000> 0
)
add_test
(
NAME autodiff_test000_hessian_sin COMMAND $<TARGET_FILE:autodiff_test000> 0
)
add_test
(
NAME autodiff_test000_hessian_sin_
mixed
COMMAND $<TARGET_FILE:autodiff_test000> 1
)
add_test
(
NAME autodiff_test000_hessian_sin_
of_poly
COMMAND $<TARGET_FILE:autodiff_test000> 1
)
add_test
(
NAME autodiff_test000_hessian_cos_
mixed
COMMAND $<TARGET_FILE:autodiff_test000> 2
)
add_test
(
NAME autodiff_test000_hessian_cos_
of_poly
COMMAND $<TARGET_FILE:autodiff_test000> 2
)
add_test
(
NAME autodiff_test000_hessian_sin_mult COMMAND $<TARGET_FILE:autodiff_test000> 3
)
add_test
(
NAME autodiff_test000_hessian_sin_mult COMMAND $<TARGET_FILE:autodiff_test000> 3
)
add_test
(
NAME autodiff_test000_hessian_cos_mult COMMAND $<TARGET_FILE:autodiff_test000> 4
)
add_test
(
NAME autodiff_test000_hessian_cos_mult COMMAND $<TARGET_FILE:autodiff_test000> 4
)
add_test
(
NAME autodiff_test000_hessian_sqrt_mixed COMMAND $<TARGET_FILE:autodiff_test000> 5
)
add_test
(
NAME autodiff_test000_hessian_sqrt_mixed COMMAND $<TARGET_FILE:autodiff_test000> 5
)
add_test
(
NAME autodiff_test000_hessian_poly COMMAND $<TARGET_FILE:autodiff_test000> 6
)
add_test
(
NAME autodiff_test000_hessian_poly COMMAND $<TARGET_FILE:autodiff_test000> 6
)
add_test
(
NAME autodiff_test000_hessian_sin_poly COMMAND $<TARGET_FILE:autodiff_test000> 7
)
add_test
(
NAME autodiff_test000_hessian_sin_poly COMMAND $<TARGET_FILE:autodiff_test000> 7
)
add_test
(
NAME autodiff_test000_hessian_minus_sin_poly COMMAND $<TARGET_FILE:autodiff_test000> 8
)
add_test
(
NAME autodiff_test000_hessian_const_minus_sin_of_poly COMMAND $<TARGET_FILE:autodiff_test000> 8
)
add_test
(
NAME autodiff_test000_hessian_const_minus_cos_of_poly COMMAND $<TARGET_FILE:autodiff_test000> 9
)
Tests/autodiff_test000/main.cpp
View file @
40108e63
...
@@ -155,7 +155,58 @@ int main(int argc,char ** argv)
...
@@ -155,7 +155,58 @@ int main(int argc,char ** argv)
_dydy
=
-
(
4
*
cos
(
2
*
((
_x
-
0.5
)
*
(
_x
-
0.5
)
+
(
_y
-
0.5
)
*
(
_y
-
0.5
)))
-
16
*
(
_y
-
0.5
)
*
(
_y
-
0.5
)
*
sin
(
2.0
*
((
_x
-
0.5
)
*
(
_x
-
0.5
)
+
(
_y
-
0.5
)
*
(
_y
-
0.5
))));
_dydy
=
-
(
4
*
cos
(
2
*
((
_x
-
0.5
)
*
(
_x
-
0.5
)
+
(
_y
-
0.5
)
*
(
_y
-
0.5
)))
-
16
*
(
_y
-
0.5
)
*
(
_y
-
0.5
)
*
sin
(
2.0
*
((
_x
-
0.5
)
*
(
_x
-
0.5
)
+
(
_y
-
0.5
)
*
(
_y
-
0.5
))));
f
=
1.0
-
sin
(
2
*
((
x
-
0.5
)
*
(
x
-
0.5
)
+
(
y
-
0.5
)
*
(
y
-
0.5
)));
f
=
1.0
-
sin
(
2
*
((
x
-
0.5
)
*
(
x
-
0.5
)
+
(
y
-
0.5
)
*
(
y
-
0.5
)));
}
}
else
if
(
test
==
9
)
{
_dx
=
(
4
*
(
_x
-
0.5
)
*
sin
(
2
*
((
_x
-
0.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
_x
*
sin
(
_x
*
_x
+
_y
);
_dydy
=
-
_x
*
sin
(
_x
*
_x
+
_y
);
f
=
sin
(
x
*
x
+
y
)
*
x
;
}
else
if
(
test
==
12
)
{
//f = sin(x)*y
//Expected Jacobian
// 0: y cos(x)
// 1: sin(x)
//Expected Hessian
// 0,0: -y*sin(x)
// 0,1: 2*cos(x)
// 1,1: 0
_dx
=
sin
(
_x
*
_x
+
_y
*
_y
)
+
2
*
_x
*
_x
*
cos
(
_x
*
_x
+
_y
*
_y
);
_dy
=
2
*
_x
*
_y
*
cos
(
_x
*
_x
+
_y
*
_y
);
_dxdx
=
6
*
_x
*
cos
(
_x
*
_x
+
_y
*
_y
)
-
4
*
_x
*
_x
*
_x
*
sin
(
_x
*
_x
+
_y
*
_y
);
_dxdy
=
4
*
_y
*
(
cos
(
_x
*
_x
+
_y
*
_y
)
-
2
*
_x
*
_x
*
sin
(
_x
*
_x
+
_y
*
_y
));
_dydy
=
2
*
_x
*
(
cos
(
_x
*
_x
+
_y
*
_y
)
-
2
*
_y
*
_y
*
sin
(
_x
*
_x
+
_y
*
_y
));
f
=
sin
(
x
*
x
+
y
*
y
)
*
x
;
}
double
dx
=
f
.
GetRow
()[
0
];
double
dx
=
f
.
GetRow
()[
0
];
double
dy
=
f
.
GetRow
()[
1
];
double
dy
=
f
.
GetRow
()[
1
];
double
dxdx
=
f
.
GetHessianRow
()[
Sparse
::
HessianRow
::
make_index
(
0
,
0
)];
double
dxdx
=
f
.
GetHessianRow
()[
Sparse
::
HessianRow
::
make_index
(
0
,
0
)];
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment