Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
prova.c
Go to the documentation of this file.
1/*
2 This file is part of the Ansel project.
3 Copyright (C) 2023 Davide Patria.
4
5 Ansel is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 Ansel is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with Ansel. If not, see <http://www.gnu.org/licenses/>.
17*/
18
28#include "polar_decomposition.h"
29#include <stdio.h>
30
32void print_float(TYPE num);
33
35void check_orthonormal(TYPE Q[3][3]);
36
38void stampa_3x3(TYPE Q[3][3]);
39
41void copy(TYPE *dest, TYPE *source, size_t num_el);
42
43#ifndef TEST_N
44#define TEST_N 1
45#endif
46
47int main()
48{
49
50 TYPE A[3][3];
51 // simple case one
52 switch(TEST_N)
53 {
54 case 1:
55 {
56 TYPE temp[3][3] = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } };
57 copy(*A, *temp, 9);
58 }
59 case 2:
60 {
61 TYPE temp[3][3] = { { 0.1, 0.1, 0.3 }, { 0.2, 0.1, 0.2 }, { 0.3, 0.0, 0.1 } };
62 copy(*A, *temp, 9);
63 }
64 // TODO: check and use here the maledict test mentioned in the cpp version
65 case 3:
66 {
67 TYPE temp[3][3] = { { -1, 2, 0 }, { 1.3, 0.4, 3.4 }, { 0.3, 2.4, 3.4 } };
68 copy(*A, *temp, 9);
69 }
70 }
71
72 TYPE Q[3][3];
73 TYPE H[3][3];
74
75 // stampa_3x3(A);
77
78 // stampa_3x3(A);
79 stampa_3x3(Q);
81
82 matrix_multiply(*(Q), *(H), *(A), 3, 3, 3);
83
84 // stampa_3x3(A);
85
87
88 return 0;
89}
90
92void stampa_3x3(TYPE Q[3][3])
93{
94 for(size_t riga = 0; riga < 3; riga++)
95 {
96 for(size_t col = 0; col < 3; col++)
97 {
98 printf("%f ", Q[riga][col]);
99 if(col == 2) printf("\n");
100 }
101 }
102 printf("\n");
103}
104
107{
108 TYPE scalar01 = 0;
109 TYPE scalar12 = 0;
110 TYPE scalar02 = 0;
111
112 for(size_t i = 0; i < 3; i++)
113 {
114 scalar01 += Q[0][i] * Q[1][i];
115 scalar12 += Q[1][i] * Q[2][i];
116 scalar02 += Q[0][i] * Q[2][i];
117 }
118 print_float(scalar01);
119 print_float(scalar12);
120 print_float(scalar02);
121}
122
125{
126 printf("scalar12: %f\n", num);
127}
#define A(y, x)
#define H
Definition diffuse.c:613
Experimental 3x3 polar decomposition helpers used for color transform analysis.
#define TYPE
void matrix_multiply(const double *A, const double *B, double *RES, int rows_A, int cols_A, int cols_B)
Multiply two dense row-major matrices.
void polar_decomposition(double A[3][3], double Q[3][3], double H[3][3])
Compute the polar decomposition of a 3x3 matrix.
#define TEST_N
Definition prova.c:44
void stampa_3x3(double Q[3][3])
Print a 3x3 matrix in row-major order.
Definition prova.c:92
void check_orthonormal(double Q[3][3])
Print the pairwise row dot products of a 3x3 matrix.
Definition prova.c:106
void copy(double *dest, double *source, size_t num_el)
Copy a flat buffer used to initialize test matrices.
void print_float(double num)
Print one scalar diagnostic produced by the orthogonality check.
Definition prova.c:124
int main()
Definition prova.c:47