File: test_invert.c

package info (click to toggle)
sphinxbase 0.8%2B5prealpha-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 10,592 kB
  • ctags: 3,296
  • sloc: ansic: 29,950; sh: 11,802; makefile: 679; python: 335; perl: 121; yacc: 93; lex: 50
file content (89 lines) | stat: -rw-r--r-- 1,618 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include <stdio.h>
#include <string.h>

#include "matrix.h"
#include "ckd_alloc.h"

const float32 foo[3][3] = {
	{2, 1, 1},
	{1, 2, 1},
	{1, 1, 2}
};
const float32 bar[3][3] = {
	{2, 0.5, 1},
	{0.5, 2, 1},
	{1, 1, 2}
};

int
main(int argc, char *argv[])
{
	float32 **a, **ainv, **ii;
	int i, j;

	a = (float32 **)ckd_calloc_2d(3, 3, sizeof(float32));
	ainv = (float32 **)ckd_calloc_2d(3, 3, sizeof(float32));
	ii = (float32 **)ckd_calloc_2d(3, 3, sizeof(float32));

	memcpy(a[0], foo, sizeof(float32) * 3 * 3);
	printf("%d\n", invert(ainv, a, 3));
	/* Should see:
	   0.75 -0.25 -0.25 
	   -0.25 0.75 -0.25 
	   -0.25 -0.25 0.75 
	*/
	for (i = 0; i < 3; ++i) {
		for (j = 0; j < 3; ++j) {
			printf("%.2f ", ainv[i][j]);
		}
		printf("\n");
	}
	/* Should see:
	   1.00 0.00 0.00
	   0.00 1.00 0.00
	   0.00 0.00 1.00
	*/
	matrixmultiply(ii, ainv, a, 3);
	for (i = 0; i < 3; ++i) {
		for (j = 0; j < 3; ++j) {
			printf("%.2f ", ii[i][j]);
		}
		printf("\n");
	}

	memcpy(a[0], bar, sizeof(float32) * 3 * 3);
	printf("%d\n", invert(ainv, a, 3));
	/* Should see:
	*/
	for (i = 0; i < 3; ++i) {
		for (j = 0; j < 3; ++j) {
			printf("%.2f ", ainv[i][j]);
		}
		printf("\n");
	}
	/* Should see:
	   1.00 0.00 0.00 
	   0.00 1.00 0.00 
	   0.00 0.00 1.00 
	*/
	memset(ii[0], 0, sizeof(float32) * 3 * 3);
	matrixmultiply(ii, ainv, a, 3);
	for (i = 0; i < 3; ++i) {
		for (j = 0; j < 3; ++j) {
			printf("%.2f ", ii[i][j]);
		}
		printf("\n");
	}

	/* Should see:
	   -1
	*/
	a[0][0] = 1.0;
	printf("%d\n", invert(ainv, a, 3));

	ckd_free_2d((void **)a);
	ckd_free_2d((void **)ainv);
	ckd_free_2d((void **)ii);

	return 0;
}