summaryrefslogtreecommitdiff
path: root/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/MatrixFunctions/mat_scale.c
blob: d426ad63fb48ea1aa3f7fa6c77d3689fb20b8196 (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
58
59
60
61
62
63
64
#include "ref.h"

arm_status ref_mat_scale_f32(
  const arm_matrix_instance_f32 * pSrc,
  float32_t scale,
  arm_matrix_instance_f32 * pDst)
{
	uint32_t i;
  uint32_t numSamples;                           /* total number of elements in the matrix  */

	/* Total number of samples in the input matrix */
	numSamples = (uint32_t) pSrc->numRows * pSrc->numCols;
	
	for(i=0;i<numSamples;i++)
	{
		pDst->pData[i] = pSrc->pData[i] * scale;
	}
	
	return ARM_MATH_SUCCESS;
}

arm_status ref_mat_scale_q31(
  const arm_matrix_instance_q31 * pSrc,
  q31_t scale,
  int32_t shift,
  arm_matrix_instance_q31 * pDst)
{
	uint32_t i;
  uint32_t numSamples;                           /* total number of elements in the matrix  */
	int32_t totShift = shift + 1; 
	q31_t tmp;

	/* Total number of samples in the input matrix */
	numSamples = (uint32_t) pSrc->numRows * pSrc->numCols;
	
	for(i=0;i<numSamples;i++)
	{
		tmp = ((q63_t)pSrc->pData[i] * scale) >> 32;
		pDst->pData[i] = ref_sat_q31((q63_t)tmp << totShift );
	}
	
	return ARM_MATH_SUCCESS;
}

arm_status ref_mat_scale_q15(
  const arm_matrix_instance_q15 * pSrc,
  q15_t scale,
  int32_t shift,
  arm_matrix_instance_q15 * pDst)
{
	uint32_t i;
  uint32_t numSamples;                           /* total number of elements in the matrix  */
	int32_t totShift = 15 - shift;

	/* Total number of samples in the input matrix */
	numSamples = (uint32_t) pSrc->numRows * pSrc->numCols;
	
	for(i=0;i<numSamples;i++)
	{
		pDst->pData[i] = ref_sat_q15( ((q31_t)pSrc->pData[i] * scale) >> totShift);
	}
	
	return ARM_MATH_SUCCESS;
}