Matrix Scale

riscv_status riscv_mat_scale_f16(const riscv_matrix_instance_f16 *pSrc, float16_t scale, riscv_matrix_instance_f16 *pDst)
riscv_status riscv_mat_scale_f32(const riscv_matrix_instance_f32 *pSrc, float32_t scale, riscv_matrix_instance_f32 *pDst)
riscv_status riscv_mat_scale_q15(const riscv_matrix_instance_q15 *pSrc, q15_t scaleFract, int32_t shift, riscv_matrix_instance_q15 *pDst)
riscv_status riscv_mat_scale_q31(const riscv_matrix_instance_q31 *pSrc, q31_t scaleFract, int32_t shift, riscv_matrix_instance_q31 *pDst)
group MatrixScale

Multiplies a matrix by a scalar. This is accomplished by multiplying each element in the matrix by the scalar. For example:

\[\begin{split} \begin{pmatrix} a_{1,1} & a_{1,2} & a_{1,3} \\ a_{2,1} & a_{2,2} & a_{2,3} \\ a_{3,1} & a_{3,2} & a_{3,3} \\ \end{pmatrix} K = \begin{pmatrix} K a_{1,1} & K a_{1,2} & K a_{1,3} \\ K a_{2,1} & K a_{2,2} & K a_{2,3} \\ K a_{3,1} & K a_{3,2} & K a_{3,3} \\ \end{pmatrix} \end{split}\]
Matrix Scaling of a 3 x 3 matrix

The function checks to make sure that the input and output matrices are of the same size.

In the fixed-point Q15 and Q31 functions, scale is represented by a fractional multiplication scaleFract and an arithmetic shift shift. The shift allows the gain of the scaling operation to exceed 1.0. The overall scale factor applied to the fixed-point data is

Functions

riscv_status riscv_mat_scale_f16(const riscv_matrix_instance_f16 *pSrc, float16_t scale, riscv_matrix_instance_f16 *pDst)

Floating-point matrix scaling.

Parameters
  • pSrc[in] points to input matrix

  • scale[in] scale factor to be applied

  • pDst[out] points to output matrix structure

Returns

execution status

  • RISCV_MATH_SUCCESS : Operation successful

  • RISCV_MATH_SIZE_MISMATCH : Matrix size check failed

riscv_status riscv_mat_scale_f32(const riscv_matrix_instance_f32 *pSrc, float32_t scale, riscv_matrix_instance_f32 *pDst)

Floating-point matrix scaling.

Parameters
  • pSrc[in] points to input matrix

  • scale[in] scale factor to be applied

  • pDst[out] points to output matrix structure

Returns

execution status

  • RISCV_MATH_SUCCESS : Operation successful

  • RISCV_MATH_SIZE_MISMATCH : Matrix size check failed

riscv_status riscv_mat_scale_q15(const riscv_matrix_instance_q15 *pSrc, q15_t scaleFract, int32_t shift, riscv_matrix_instance_q15 *pDst)

Q15 matrix scaling.

Scaling and Overflow Behavior

The input data *pSrc and scaleFract are in 1.15 format. These are multiplied to yield a 2.30 intermediate result and this is shifted with saturation to 1.15 format.

Parameters
  • pSrc[in] points to input matrix

  • scaleFract[in] fractional portion of the scale factor

  • shift[in] number of bits to shift the result by

  • pDst[out] points to output matrix structure

Returns

execution status

  • RISCV_MATH_SUCCESS : Operation successful

  • RISCV_MATH_SIZE_MISMATCH : Matrix size check failed

riscv_status riscv_mat_scale_q31(const riscv_matrix_instance_q31 *pSrc, q31_t scaleFract, int32_t shift, riscv_matrix_instance_q31 *pDst)

Q31 matrix scaling.

Scaling and Overflow Behavior

The input data *pSrc and scaleFract are in 1.31 format. These are multiplied to yield a 2.62 intermediate result which is shifted with saturation to 1.31 format.

Parameters
  • pSrc[in] points to input matrix

  • scaleFract[in] fractional portion of the scale factor

  • shift[in] number of bits to shift the result by

  • pDst[out] points to output matrix structure

Returns

execution status

  • RISCV_MATH_SUCCESS : Operation successful

  • RISCV_MATH_SIZE_MISMATCH : Matrix size check failed