summaryrefslogtreecommitdiff
path: root/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/MatrixFunctions/mat_inverse.c
blob: 74d3ccc9e80c6a1ff10e49ebf0a2e704b35c4671 (plain) (blame)
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
#include "ref.h"

arm_status ref_mat_inverse_f32(
  const arm_matrix_instance_f32 * pSrc,
  arm_matrix_instance_f32 * pDst)
{
	float32_t det;
	uint32_t i, size;
	arm_matrix_instance_f32 tmp;
	
	tmp.numCols = pSrc->numCols;
	tmp.numRows = pSrc->numRows;
	tmp.pData = scratchArray;
	
	det = ref_detrm(pSrc->pData,scratchArray,pSrc->numCols);
	
	size = pSrc->numCols * pSrc->numCols;
	
	ref_cofact(pSrc->pData,scratchArray,scratchArray + size,pSrc->numCols);
	
	ref_mat_trans_f32(&tmp,pDst);	
	
	for(i=0;i<size;i++)
	{
		pDst->pData[i] /= det;
	}
	
	return ARM_MATH_SUCCESS;
}

arm_status ref_mat_inverse_f64(
  const arm_matrix_instance_f64 * pSrc,
  arm_matrix_instance_f64 * pDst)
{
	float64_t det;
	uint32_t i, size;
	arm_matrix_instance_f64 tmp;
	
	tmp.numCols = pSrc->numCols;
	tmp.numRows = pSrc->numRows;
	tmp.pData = (float64_t*)scratchArray;
	
	det = ref_detrm64(pSrc->pData,(float64_t*)scratchArray,pSrc->numCols);
	
	size = pSrc->numCols * pSrc->numCols;
	
	ref_cofact64(pSrc->pData,(float64_t*)scratchArray,(float64_t*)scratchArray + size,pSrc->numCols);
	
	ref_mat_trans_f64(&tmp,pDst);	
	
	for(i=0;i<size;i++)
	{
		pDst->pData[i] /= det;
	}
	
	return ARM_MATH_SUCCESS;
}