Blender V5.3
BLI_math_solvers_test.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5#include "testing/testing.h"
6
7#include "BLI_math_solvers.hh"
8
9namespace blender {
10
11TEST(math_solvers, Tridiagonal1)
12{
13 const float a[1] = {1}; // ignored
14 const float b[1] = {2};
15 const float c[1] = {1}; // ignored
16 const float d[1] = {4};
17 float x[1];
18
19 EXPECT_TRUE(BLI_tridiagonal_solve(a, b, c, d, x, 1));
20 EXPECT_FLOAT_EQ(x[0], 2);
21}
22
23TEST(math_solvers, Tridiagonal3)
24{
25 const float a[3] = {1, 2, 3}; // 1 ignored
26 const float b[3] = {4, 5, 6};
27 const float c[3] = {7, 8, 9}; // 9 ignored
28 const float d[3] = {18, 36, 24};
29 float x[3];
30
31 EXPECT_TRUE(BLI_tridiagonal_solve(a, b, c, d, x, 3));
32 EXPECT_FLOAT_EQ(x[0], 1);
33 EXPECT_FLOAT_EQ(x[1], 2);
34 EXPECT_FLOAT_EQ(x[2], 3);
35}
36
37TEST(math_solvers, CyclicTridiagonal1)
38{
39 const float a[1] = {1};
40 const float b[1] = {2};
41 const float c[1] = {1};
42 const float d[1] = {4};
43 float x[1];
44
46 EXPECT_FLOAT_EQ(x[0], 1);
47}
48
49TEST(math_solvers, CyclicTridiagonal2)
50{
51 const float a[2] = {1, 2};
52 const float b[2] = {3, 4};
53 const float c[2] = {5, 6};
54 const float d[2] = {15, 16};
55 float x[2];
56
58 EXPECT_FLOAT_EQ(x[0], 1);
59 EXPECT_FLOAT_EQ(x[1], 2);
60}
61
62TEST(math_solvers, CyclicTridiagonal3)
63{
64 const float a[3] = {1, 2, 3};
65 const float b[3] = {4, 5, 6};
66 const float c[3] = {7, 8, 9};
67 const float d[3] = {21, 36, 33};
68 float x[3];
69
71 EXPECT_FLOAT_EQ(x[0], 1);
72 EXPECT_FLOAT_EQ(x[1], 2);
73 EXPECT_FLOAT_EQ(x[2], 3);
74}
75
76} // namespace blender
#define EXPECT_TRUE(result)
BMesh Iterators.
bool BLI_tridiagonal_solve_cyclic(const float *a, const float *b, const float *c, const float *d, float *r_x, int count)
Solve a possibly cyclic tridiagonal system using the Sherman-Morrison formula.
bool BLI_tridiagonal_solve(const float *a, const float *b, const float *c, const float *d, float *r_x, int count)
Solve a tridiagonal system of equations:
TEST(array_store, Nop)