(https://i.imgur.com/4SOwu1E.png)
Description
เซ็ตของฟังชั่นนี้จัดให้มี basic matrix math operations. The functions ทำงานบน matrix data structures. ตัวอย่างเช่น, the type definition สำหรับ the floating-point matrix structure ถูกแสดงข้างล่าง :
typedef struct
{
uint16_t numRows; // number of rows of the matrix.
uint16_t numCols; // number of columns of the matrix.
float32_t *pData; // points to the data of the matrix.
} arm_matrix_instance_f32;
มี definitions ที่เหมือนกันสำหรับ Q15 and Q31 data type
The structure ระบุขนาดของ the matrix และจากนั้นชี้ไปยัง an array of data. The array มีขนาด numRows X numCols และ the values ถูกจัดเรียงใน row order. นั่นคือ, the matrix element (i, j) ถูกเก็บที่ :
pData[i*numCols + j]
Init Functions
มี an associated initialization function สำหรับแต่ละประเภทของ matrix data structure. The initialization function เซ็ตค่าของ the internal structure fields. อ้างอิงถึง the function arm_mat_init_f32(), arm_mat_init_q31() and arm_mat_init_q15() สำหรับ floating-point, Q31 and Q15 types, ตามลำดับ.
การใช้ของ the initialization function เป็นทางเลือก. อย่างไรก็ตาม, ถ้า initialization function ถูกใช้ดังนั้น the instance structure ไม่สามารถถูกวางลงใน a const data section. เพื่อวาง the instance structure ใน a const data section, เริ่มต้นอย่างแมนน้วล the data structure. ตัวอย่างเช่น:
arm_matrix_instance_f32 S = {nRows, nColumns, pData};
arm_matrix_instance_q31 S = {nRows, nColumns, pData};
arm_matrix_instance_q15 S = {nRows, nColumns, pData};
โดยที่ nRows ระบุจำนวนของ rows, nColumns ระบุจำนวนของ columns, และ pData ชี้ไปยัง the data array.
Size Checking
โดยค่าเริ่มต้นทุก the matrix functions ดำเนินการ size checking บน the input และ output matrices. ตัวอย่างเช่น, the matrix addition function จะตรวจสอบว่า the two input matrices และ the output matrix ทั้งหมดมีจำนวนเดียวกันของ rows และ columns. ถ้า the size check ล้มเหลว the functions คืนค่า :
ARM_MATH_SIZE_MISMATCH
มิฉะนั้น the functions คืนค่า
ARM_MATH_SUCCESS
มีโสหุ้ยบางอย่างที่เกี่ยวข้องกับ matrix size checking นี้. The matrix size checking ถูกเปิดการใช้งานโดยทาง the #define
ARM_MATH_MATRIX_CHECK
ภายใน the library project settings. โดยค่าเริ่มต้น macro นี้ถูก defined และ size checking ถูกเปิดการใช้งาน. โดยการเปลี่ยน the project settings และการไม่กำหนด macro size checking นี้ถูกเอาออกและ the functions จะรันเร็วขึ้นเล็กน้อย. ด้วย size checking ถูกปิดการใช้งาน the functions จะคืนค่า ARM_MATH_SUCCESS เสมอ.
(https://i.imgur.com/ciRLkQe.png)
Description
เริ่มต้น the underlying matrix data structure. The functions เซ็ต the numRows, numCols, และ pData fields ของ the matrix data structure.
(https://i.imgur.com/5m9gS8H.png)
References arm_matrix_instance_f32::numCols, arm_matrix_instance_f32::numRows, and arm_matrix_instance_f32::pData.
Referenced by main().
(https://i.imgur.com/WLNlqYf.png)
(https://i.imgur.com/jEfZCFK.png)
(https://i.imgur.com/c0jQ5w5.png)
Description
บวก two matrices.
(https://i.imgur.com/hoL6RlG.png)
The functions จะเช็คเพื่อทำให้แน่ใจว่า pSrcA, pSrcB, and pDst มี the same number of rows and columns.
(https://i.imgur.com/4Ai1Q40.png)
Returns
The function คืนค่าอย่างใดอย่างหนึ่ง ARM_MATH_SIZE_MISMATCH หรือ ARM_MATH_SUCCESS ขึ้นอยู่กับผลของ size checking.
References ARM_MATH_SIZE_MISMATCH, ARM_MATH_SUCCESS, arm_matrix_instance_f32::numCols, arm_matrix_instance_f32::numRows, arm_matrix_instance_f32::pData, and status.
(https://i.imgur.com/QkmUEQY.png)
(https://i.imgur.com/Ejx8bld.png)
(https://i.imgur.com/dxaFTXN.png)
Description
Subtract two matrices.
(https://i.imgur.com/vLgWJdz.png)
The functions จะเช็คเพื่อทำให้แน่ใจว่า pSrcA, pSrcB, and pDst มี the same number of rows and columns.
(https://i.imgur.com/iImsOGq.png)
(https://i.imgur.com/6kqZ3ci.png)
(https://i.imgur.com/u2bQTwU.png)
(https://i.imgur.com/eNhZKdi.png)
Description
คุณ two matrices.
(https://i.imgur.com/TMlqxbf.png)
Matrix multiplication ถูกกำหนดเฉพาะถ้าจำนวนของ columns ของ the first matrix เท่ากันกับจำนวนของ rows ของ the second matrix. การคูณ an M x N matrix ด้วย an N x P matrix ได้ผลใน an M x P matrix. เมื่อ matrix size checking ถูกเปิดการใช้งาน, the functions จะเช็ค: (1) ว่า the inner dimensions ของ pSrcA และ pSrcB เท่ากัน; และ (2) ว่าขนาดของ the output matrix เท่ากับ the outer dimensions ของ pSrcA และ pSrcB.
(https://i.imgur.com/w60ZMhs.png)
(https://i.imgur.com/LwM0kml.png)
Returns
The function คืนค่าอย่างใดอย่างหนึ่ง ARM_MATH_SIZE_MISMATCH หรือ ARM_MATH_SUCCESS ขึ้นอยู่กับผลที่ออกมาของ size checking.
Scaling and Overflow Behavior:
ความแตกต่างระหว่าง the function arm_mat_mult_q15() และ fast variant นี้คือว่า the fast variant ใช้ a 32-bit มากกว่า a 64-bit accumulator. The result ของแต่ละ 1.15 x 1.15 multiplication ถูกตัดเป็น 2.30 format. intermediate results เหล่านี้ถูกสะสมใน a 32-bit register ใน 2.30 format. สุดท้าย, the accumulator ถูกทำให้อิ่มตัวและถูกแปลงเป็น a 1.15 result.
The fast version มี the same overflow behavior อย่าง the standard version แต่จัดให้มีความเที่ยงตรงที่น้อยกว่าเนื่องจากมันทิ้ง the low 16 bits ของแต่ละ multiplication result. เพื่อหลีกเลี่ยง overflows อย่างสมบูรณ์ the input signals ต้องถูก scaled down. Scale down หนึ่งของ the input matrices โดย log2(numColsA) bits เพื่อหลีกเลี่ยง overflows, เนื่องจากทั้งหมดของ numColsA additions ถูกคำนวณภายในสำหรับแต่ละ output element.
ดู arm_mat_mult_q15() สำหรับ a slower implementation ของ function นี้ซึ่งใช้ 64-bit accumulation เพื่อจัดให้มีความเที่ยงตรงที่สูงกว่า.
References __SIMD32, __SMLAD(), ARM_MATH_SIZE_MISMATCH, ARM_MATH_SUCCESS, arm_matrix_instance_q15::numCols, arm_matrix_instance_q15::numRows, arm_matrix_instance_q15::pData, and status.
(https://i.imgur.com/EYjAXYU.png)
Returns
The function คืนค่าอย่างใดอย่างหนึ่ง ARM_MATH_SIZE_MISMATCH หรือ ARM_MATH_SUCCESS ขึ้นอยู่กับผลที่ออกมาของ size checking.
Scaling and Overflow Behavior:
ความแตกต่างระหว่าง the function arm_mat_mult_q31() และ fast variant นี้คือว่า the fast variant ใช้ a 32-bit มากกว่า a 64-bit accumulator. The result ของแต่ละ 1.31 x 1.31 multiplication ถูกตัดเป็น 2.30 format. intermediate results เหล่านี้ถูกสะสมใน a 32-bit register ใน 2.30 format. สุดท้าย, the accumulator ถูกทำให้อิ่มตัวและถูกแปลงเป็น a 1.31 result.
The fast version มี the same overflow behavior อย่าง the standard version แต่จัดให้มีความเที่ยงตรงที่น้อยกว่าเนื่องจากมันทิ้ง the low 32 bits ของแต่ละ multiplication result. เพื่อหลีกเลี่ยง overflows อย่างสมบูรณ์ the input signals ต้องถูก scaled down. Scale down หนึ่งของ the input matrices โดย log2(numColsA) bits เพื่อหลีกเลี่ยง overflows, เนื่องจากทั้งหมดของ numColsA additions ถูกคำนวณภายในสำหรับแต่ละ output element.
ดู arm_mat_mult_q31() สำหรับ a slower implementation ของ function นี้ซึ่งใช้ 64-bit accumulation เพื่อจัดให้มีความเที่ยงตรงที่สูงกว่า.
References __SMMLA(), ARM_MATH_SIZE_MISMATCH, ARM_MATH_SUCCESS, arm_matrix_instance_q31::numCols, arm_matrix_instance_q31::numRows, arm_matrix_instance_q31::pData, and status.
(https://i.imgur.com/RyhkTmd.png)
Returns
The function คืนค่าอย่างใดอย่างหนึ่ง ARM_MATH_SIZE_MISMATCH หรือ ARM_MATH_SUCCESS ขึ้นอยู่กับผลที่ออกมาของ size checking.
Scaling and Overflow Behavior:
The function ถูกจัดให้มีใช้โดยใช้ a 64-bit internal accumulator. The input เพื่อ the multiplications อยู่ใน 1.15 format และการคูณให้ผล a 2.30 result The 2.30 intermediate results ถูกสะสมใน a 64-bit accumulator ใน 34.30 format. การเข้าใกล้นี้จัดให้มี 33 guard bits และไม่มีความเสี่ยงของ overflow. The 34.30 result จากนั้นถูกตัดเป็น 34.15 format โดยการทิ้ง the low 15 bits และจากนั้นถูกทำให้อิ่มตัวเป็น 1.15 format.
อ้างอิงถึง arm_mat_mult_fast_q15() สำหรับ a faster แต่ less precise version ของ function นี้สำหรับ Cortex-M3 and Cortex-M4.
References __SIMD32, __SMLALD(), ARM_MATH_SIZE_MISMATCH, ARM_MATH_SUCCESS, arm_matrix_instance_q15::numCols, arm_matrix_instance_q15::numRows, arm_matrix_instance_q15::pData, and status.
(https://i.imgur.com/br1RUgW.png)
Returns
The function คืนค่าอย่างใดอย่างหนึ่ง ARM_MATH_SIZE_MISMATCH หรือ ARM_MATH_SUCCESS ขึ้นอยู่กับผลที่ออกมาของ size checking.
Scaling and Overflow Behavior:
The function ถูกจัดให้มีใช้โดยใช้ an internal 64-bit accumulator. The accumulator มี a 2.62 format และรักษา full precision ของ the intermediate multiplication results แต่จัดให้มีเฉพาะ a single guard bit. ไม่มี saturation บน intermediate additions. ดังนั้น, ถ้า the accumulator overflows มันจะพันรอบและบิดเบือน the result. The input signals ควรถูก scaled down เพื่อหลีกเลี่ยง intermediate overflows. The input ดังนั้นถูก scaled down โดย log2(numColsA) bits เพื่อหลีกเลี่ยง overflows, เนื่องจากทั้งหมดของ numColsA additions ถูกดำเนินการภายใน. The 2.62 accumulator ถูกเลื่อนไปทางขวาไป 31 bits และถูกทำให้อิ่มตัวเป็น 1.31 format เพื่อให้ผล the final result.
ดู arm_mat_mult_fast_q31() สำหรับ a faster แต่ less precise implementation ของ function นี้สำหรับ Cortex-M3 and Cortex-M4.
References ARM_MATH_SIZE_MISMATCH, ARM_MATH_SUCCESS, clip_q63_to_q31(), arm_matrix_instance_q31::numCols, arm_matrix_instance_q31::numRows, arm_matrix_instance_q31::pData, and status.
file:///D:/System%20Workbench/STM32CubeF1-master/Drivers/CMSIS/docs/DSP/html/group__MatrixTrans.html
(https://i.imgur.com/ku0i4j9.png)
Description
ไขว้ a matrix. การไขว้ an M x N matrix พลิกมันรอบเส้นทะแยงมุมตรงกลางและได้ผลใน an N x M matrix.(จาก rom เป็น column จาก column เป็น row)
(https://i.imgur.com/Y1xGtjX.png)
(https://i.imgur.com/6Lxg40s.png)
(https://i.imgur.com/FQwkpgU.png)
(https://i.imgur.com/FgTxBfJ.png)
file:///D:/System%20Workbench/STM32CubeF1-master/Drivers/CMSIS/docs/DSP/html/group__MatrixScale.html
(https://i.imgur.com/tWDhNeg.png)
Description
คูณ a matrix ด้วย a scalar. นี้ถูกทำให้สำเร็จโดยการคูณแต่ละ element ใน the matrix ด้วย the scalar. ตัวอย่างเช่น :
(https://i.imgur.com/aPkZPlt.png)
The function เช็คเพื่อให้แน่ใจว่า the input and output matrices มีขนาดเดียวกัน.
ใน the fixed-point Q15 and Q31 functions, scale ถูกแสดงโดย a fractional multiplication scaleFract และ an arithmetic shift shift. The shift ยอมให้ the gain ของ the scaling operation เกิน 1.0. The overall scale factor ที่ใช้กับ the fixed-point data คือ
scale = scaleFract * 2^shift.
(https://i.imgur.com/qNmQCdI.png)
(https://i.imgur.com/FGY7FJ1.png)
(https://i.imgur.com/CxsKKX1.png)
file:///D:/System%20Workbench/STM32CubeF1-master/Drivers/CMSIS/docs/DSP/html/group__MatrixInv.html
(https://i.imgur.com/VHiLZzY.png)
Description
คำนวณหา the inverse of a matrix.
The inverse ถูกกำหนดเฉพาะถ้า the input matrix เป็นสี่เหลี่ยมจัตุรัสและ non-singular (the determinant เป็น non-zero). The function เช็คว่า the input and output matrices เป็นสี่เหลี่ยมจัตุรัสและมีขนาดเดียวกัน.
Matrix inversion มีความละเอียดอ่อนเชิงตัวเลข และ the CMSIS DSP library รองรับเฉพาะ matrix inversion ของ floating-point matrices.
Algorithm
The Gauss-Jordan method ถูกใช้เพื่อหา the inverse. The algorithm ดำเนินการลำดับของ elementary row-operations จนกระทั่งมันลด the input matrix เป็น an identity matrix. การใช้ลำดับเดียวกันของ elementary row-operations ไปเป็น an identity matrix ให้ผล the inverse matrix. ถ้า the input matrix เป็น singular, ดังนั้น the algorithm จะสิ้นสุดและคืนค่า error status ARM_MATH_SINGULAR.
(https://i.imgur.com/AhoBEqB.png)
ปล. ลองดูนี่ก็ได้ การหา Matrix Inverse
https://www.youtube.com/watch?v=MaTLj9c0J8c (https://www.youtube.com/watch?v=MaTLj9c0J8c)
(https://i.imgur.com/yKjIro4.png)
Returns
The function คืนค่า ARM_MATH_SIZE_MISMATCH ถ้า the input matrix ไม่เป็นสี่เหลี่ยมจัตุรัสหรือถ้าขนาดของ the output matrix ไม่ตรงกันกับขนาดของ the input matrix. ถ้า the input matrix ถูกพบว่าเป็น singular (ไม่สามารถ inverse ได้), ดังนั้น the function คืนค่า ARM_MATH_SINGULAR. มิฉะนั้น, the function คืนค่า ARM_MATH_SUCCESS.
References ARM_MATH_SINGULAR, ARM_MATH_SIZE_MISMATCH, ARM_MATH_SUCCESS, arm_matrix_instance_f32::numCols, arm_matrix_instance_f32::numRows, arm_matrix_instance_f32::pData, and status.
Referenced by main().
(https://i.imgur.com/aRi4WZU.png)
Returns
The function คืนค่า ARM_MATH_SIZE_MISMATCH ถ้า the input matrix ไม่เป็นสี่เหลี่ยมจัตุรัสหรือถ้าขนาดของ the output matrix ไม่ตรงกันกับขนาดของ the input matrix. ถ้า the input matrix ถูกพบว่าเป็น singular (non-invertible), ดังนั้น the function คืนค่า ARM_MATH_SINGULAR. มิฉะนั้น, the function คืนค่า ARM_MATH_SUCCESS.
References ARM_MATH_SINGULAR, ARM_MATH_SIZE_MISMATCH, ARM_MATH_SUCCESS, arm_matrix_instance_f64::numCols, arm_matrix_instance_f64::numRows, arm_matrix_instance_f64::pData, and status.
file:///D:/System%20Workbench/STM32CubeF1-master/Drivers/CMSIS/docs/DSP/html/group__CmplxMatrixMult.html
(https://i.imgur.com/2UK9YsN.png)
Description
Matrix multiplication ถูกกำหนดเฉพาะถ้าจำนวนของ columns ของ the first matrix เท่ากันกับจำนวนของ rows ของ the second matrix. การคูณ an M x N matrix ด้วย an N x P matrix ได้ผลใน an M x P matrix. เมื่อ matrix size checking ถูกเปิดการใช้งาน, the functions จะเช็ค: (1) ว่า the inner dimensions ของ pSrcA และ pSrcB เท่ากัน; และ (2) ว่าขนาดของ the output matrix เท่ากับ the outer dimensions ของ pSrcA และ pSrcB.
(https://i.imgur.com/F1inXJy.png)
(https://i.imgur.com/ohCbYU7.png)
Returns
The function คืนค่าอย่างใดอย่างหนึ่ง ARM_MATH_SIZE_MISMATCH หรือ ARM_MATH_SUCCESS ขึ้นอยู่กับผลที่ออกมาของ size checking.
Conditions for optimum performance
Input, output and state buffers ควรถูกวางแนวโดย 32-bit
Restrictions
ถ้า the silicon ไม่รองรับ unaligned memory access enable the macro UNALIGNED_SUPPORT_DISABLE ในกรณีนี้ input, output, scratch buffers ควรถูกวางแนวโดย 32-bit
Scaling and Overflow Behavior:
The function ถูกจัดให้มีใช้โดยใช้ a 64-bit internal accumulator. The input เพื่อ the multiplications อยู่ใน 1.15 format และการคูณให้ผล a 2.30 result The 2.30 intermediate results ถูกสะสมใน a 64-bit accumulator ใน 34.30 format. การเข้าใกล้นี้จัดให้มี 33 guard bits และไม่มีความเสี่ยงของ overflow. The 34.30 result จากนั้นถูกตัดเป็น 34.15 format โดยการทิ้ง the low 15 bits และจากนั้นถูกทำให้อิ่มตัวเป็น 1.15 format.
อ้างอิงถึง arm_mat_mult_fast_q15() สำหรับการเร็วขึ้นแต่เป็นเวอร์ชั่นที่ความเที่ยงตรงน้อยลงงของฟังชั่นนี้.
References __SIMD32, __SMUADX(), __SMUSD(), ARM_MATH_SIZE_MISMATCH, ARM_MATH_SUCCESS, arm_matrix_instance_q15::numCols, arm_matrix_instance_q15::numRows, arm_matrix_instance_q15::pData, and status.
(https://i.imgur.com/1Q09Ira.png)
Returns
The function คืนค่าอย่างใดอย่างหนึ่ง ARM_MATH_SIZE_MISMATCH หรือ ARM_MATH_SUCCESS ขึ้นอยู่กับผลที่ออกมาของ size checking.
Scaling and Overflow Behavior:
The function ถูกจัดให้มีใช้โดยใช้ an internal 64-bit accumulator. The accumulator มี a 2.62 format และรักษา full precision ของ the intermediate multiplication results แต่จัดให้มีเฉพาะ a single guard bit. ไม่มี saturation บน intermediate additions. ดังนั้น, ถ้า the accumulator overflows มันจะพันรอบและบิดเบือน the result. The input signals ควรถูก scaled down เพื่อหลีกเลี่ยง intermediate overflows. The input ดังนั้นถูก scaled down โดย log2(numColsA) bits เพื่อหลีกเลี่ยง overflows, เนื่องจากทั้งหมดของ numColsA additions ถูกดำเนินการภายใน. The 2.62 accumulator ถูกเลื่อนไปทางขวาไป 31 bits และถูกทำให้อิ่มตัวเป็น 1.31 format เพื่อให้ผล the final result.
References ARM_MATH_SIZE_MISMATCH, ARM_MATH_SUCCESS, clip_q63_to_q31(), arm_matrix_instance_q31::numCols, arm_matrix_instance_q31::numRows, arm_matrix_instance_q31::pData, and status.