blob: 48fe9553b43a46682136d5f300fe02d51f3ba9ed [file] [log] [blame]
Austin Schuh70cc9552019-01-21 19:46:48 -08001
2// Ceres Solver - A fast non-linear least squares minimizer
3// Copyright 2017 Google Inc. All rights reserved.
4// http://ceres-solver.org/
5//
6// Redistribution and use in source and binary forms, with or without
7// modification, are permitted provided that the following conditions are met:
8//
9// * Redistributions of source code must retain the above copyright notice,
10// this list of conditions and the following disclaimer.
11// * Redistributions in binary form must reproduce the above copyright notice,
12// this list of conditions and the following disclaimer in the documentation
13// and/or other materials provided with the distribution.
14// * Neither the name of Google Inc. nor the names of its contributors may be
15// used to endorse or promote products derived from this software without
16// specific prior written permission.
17//
18// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28// POSSIBILITY OF SUCH DAMAGE.
29//
30// Author: mierle@gmail.com (Keir Mierle)
31
32#ifndef CERES_INTERNAL_TINY_SOLVER_TEST_UTIL_H_
33#define CERES_INTERNAL_TINY_SOLVER_TEST_UTIL_H_
34
35namespace ceres {
36
37template<typename T>
38bool EvaluateResidualsAndJacobians(const T* parameters,
39 T* residuals,
40 T* jacobian) {
41 T x = parameters[0];
42 T y = parameters[1];
43 T z = parameters[2];
44
45 residuals[0] = x + static_cast<T>(2) * y + static_cast<T>(4) * z;
46 residuals[1] = y * z;
47
48 if (jacobian) {
49 jacobian[0 * 2 + 0] = static_cast<T>(1);
50 jacobian[0 * 2 + 1] = static_cast<T>(0);
51
52 jacobian[1 * 2 + 0] = static_cast<T>(2);
53 jacobian[1 * 2 + 1] = z;
54
55 jacobian[2 * 2 + 0] = static_cast<T>(4);
56 jacobian[2 * 2 + 1] = y;
57 }
58 return true;
59}
60
61} // namespace ceres
62
63#endif // CERES_INTERNAL_TINY_SOLVER_TEST_UTIL_H_