10 #define MAT_ALG_ACCURACY 1e-4f 14 static uint32_t m_z = 1234;
15 static uint32_t m_w = 76542;
16 m_z = 36969 * (m_z & 65535) + (m_z >> 16);
17 m_w = 18000 * (m_w & 65535) + (m_w >> 16);
18 return ((m_z << 16) + m_w) & 0xF;
23 for (
int i = 0; i < n; i++) {
24 for (
int j = 0; j < n; j++)
25 printf(
"%.10f ", A[i * n + j]);
30 static bool compare_mat(
const float *
A,
const float *
B,
const uint8_t n)
32 for(uint8_t i = 0; i < n; i++) {
33 for(uint8_t j = 0; j < n; j++) {
45 float test_mat[25],ident_mat[25];
47 for(uint8_t i = 0;i<25;i++) {
54 memset(ident_mat,0,
sizeof(ident_mat));
55 for(uint8_t i=0; i<3; i++) {
56 ident_mat[i*3+i] = 1.0f;
59 out_mat =
mat_mul(test_mat,mat,3);
66 printf(
"\n\n3x3 Test Matrix:\n");
68 printf(
"\nInverse of Inverse of matrix\n");
79 printf(
"Identity output Test Failed!!\n");
85 memset(ident_mat,0,
sizeof(ident_mat));
86 for(uint8_t i=0; i<4; i++) {
87 ident_mat[i*4+i] = 1.0f;
90 out_mat =
mat_mul(test_mat,mat,4);
96 printf(
"\n\n4x4 Test Matrix:\n");
98 printf(
"\nInverse of Inverse of matrix\n");
104 printf(
"Test Failed!!\n");
108 printf(
"Identity output Test Failed!!\n");
115 memset(ident_mat,0,
sizeof(ident_mat));
116 for(uint8_t i=0; i<5; i++) {
117 ident_mat[i*5+i] = 1.0f;
120 out_mat =
mat_mul(test_mat,mat,5);
128 printf(
"\n\n5x5 Test Matrix:\n");
130 printf(
"\nInverse of Inverse of matrix\n");
136 printf(
"Test Failed!!\n");
140 printf(
"Identity output Test Failed!!\n");
int printf(const char *fmt,...)
float * mat_mul(float *A, float *B, uint8_t n)
AP_HAL::UARTDriver * console
static void show_matrix(float *A, int n)
const AP_HAL::HAL & hal
-*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-
virtual void printf(const char *,...) FMT_PRINTF(2
bool inverse(float x[], float y[], uint16_t dim)
static uint16_t get_random(void)
static bool compare_mat(const float *A, const float *B, const uint8_t n)
static void test_matrix_inverse(void)