Blender  V3.3
function_derivative_test.cc
Go to the documentation of this file.
1 // Copyright (c) 2007, 2008, 2009 libmv authors.
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining a copy
4 // of this software and associated documentation files (the "Software"), to
5 // deal in the Software without restriction, including without limitation the
6 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7 // sell copies of the Software, and to permit persons to whom the Software is
8 // furnished to do so, subject to the following conditions:
9 //
10 // The above copyright notice and this permission notice shall be included in
11 // all copies or substantial portions of the Software.
12 //
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19 // IN THE SOFTWARE.
20 
22 #include "libmv/numeric/numeric.h"
23 #include "testing/testing.h"
24 
25 using namespace libmv;
26 
27 namespace {
28 
29 class F {
30  public:
31  typedef Vec2 FMatrixType;
32  typedef Vec3 XMatrixType;
33  Vec2 operator()(const Vec3& x) const {
34  Vec2 fx;
35  fx << 0.19 * x(0) + 0.19 * x(1) * x(1) + x(2),
36  3 * sin(x(0)) + 2 * cos(x(1));
37  return fx;
38  }
39  Mat23 J(const Vec3& x) const {
40  Mat23 jacobian;
41  jacobian << 0.19, 2 * 0.19 * x(1), 1.0, 3 * cos(x(0)), -2 * sin(x(1)), 0;
42  return jacobian;
43  }
44 };
45 
46 TEST(FunctionDerivative, SimpleCase) {
47  Vec3 x;
48  x << 0.76026643, 0.01799744, 0.55192142;
49  F f;
51  EXPECT_MATRIX_NEAR(f.J(x), J(x), 1e-8);
52  NumericJacobian<F, FORWARD> J_forward(f);
53  // Forward difference is very inaccurate.
54  EXPECT_MATRIX_NEAR(f.J(x), J_forward(x), 1e-5);
55 }
56 
57 } // namespace
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
SIMD_FORCE_INLINE btVector3 operator()(const btVector3 &x) const
Return the transform of the vector.
Definition: btTransform.h:90
#define F
INLINE Rall1d< T, V, S > cos(const Rall1d< T, V, S > &arg)
Definition: rall1d.h:319
INLINE Rall1d< T, V, S > sin(const Rall1d< T, V, S > &arg)
Definition: rall1d.h:311
Eigen::Vector2d Vec2
Definition: numeric.h:105
TEST(PolynomialCameraIntrinsics2, ApplyOnFocalCenter)
Eigen::Matrix< double, 2, 3 > Mat23
Definition: numeric.h:71
Eigen::Vector3d Vec3
Definition: numeric.h:106