Method, device and storage medium for matrix calculation based on micro control unit

By constructing data tuples and reading data sequentially, the problem of high computation time overhead in sparse matrix calculations in MCUs is solved, achieving more efficient data processing, adapting to the constraints of limited MCU storage resources, and improving computational efficiency.

CN123178761APending Publication Date: 2026-11-27PAXINI TECHNOLOGY (SHENZHEN) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511240771.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Priority Date
2025-05-20
Filing Date
2025-09-02
Publication Date
2026-11-27

AI Technical Summary

Technical Problem

In the prior art, microcontroller units (MCUs) have a large computation time overhead when performing sparse matrix calculations, which affects the data processing speed, especially when calculating gradients, and cannot meet the requirements for real-time performance and accuracy.

Method used

By obtaining the first matrix and the second matrix, a one-dimensional array is constructed by selecting the target element from the first matrix according to the index and numerical conditions, and the index value of the corresponding element in the second matrix that has a calculation relationship with the target element is determined to construct a data tuple. In response to the matrix calculation instruction, the data in the data tuple is read in sequence to perform matrix calculation.

Benefits of technology

The sequential access order of data has been optimized, reducing data reading time overhead and improving the data processing capabilities of the MCU, especially significantly improving computational efficiency when calculating large sparse matrices.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123178761A_ABST
    Figure CN123178761A_ABST
Patent Text Reader

Abstract

The application discloses a method and device for matrix calculation based on a micro control unit and a storage medium, comprising: obtaining a first matrix and a second matrix; selecting a target element from the first matrix and constructing a corresponding one-dimensional array according to an index and a numerical condition; determining an index value of a corresponding element in the second matrix which has a calculation relationship with the target element; determining the number of target elements in each row of the first matrix; constructing a data tuple based on the one-dimensional array, the index value and the number of target elements; and in response to a matrix calculation instruction, reading data in the data tuple in sequence to perform matrix calculation. The data tuple constructed by the above method optimizes the continuous access order of data, so that the micro control unit can realize the continuity of memory access when performing matrix calculation, and effectively reduces the time overhead of the micro control unit data access.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of microcontroller technology, and in particular to a method, apparatus and storage medium for matrix calculation based on a microcontroller. Background Technology

[0002] Microcontroller units (MCUs) are widely used in fields such as intelligent robots, industrial automation, and haptic interaction devices. They typically serve as the core computing platform and play a crucial role in real-time control systems.

[0003] In specific MCU computing scenarios, the storage, retrieval, and computation of large sparse matrices are sometimes involved. Taking a mechanics inversion system as an example, large sparse matrices are the mathematical foundation for core algorithms such as contact force modeling and inverse kinematics. Especially in the coupled process of inverse kinematics, the MCU will use large sparse matrices to calculate gradients, and the computational efficiency directly determines the real-time performance and accuracy of tactile inversion.

[0004] Currently, MCUs typically use traditional compression algorithms such as compressed row storage or compressed column storage for storing and retrieving sparse matrices. However, for MCUs with limited hardware resources, these compression algorithms still incur significant computational overhead, especially during gradient calculations, which can severely impact the MCU's data processing speed.

[0005] In view of this, there is an urgent need for a method, device and storage medium for matrix calculation based on microcontroller units to reduce the computation time overhead of MCUs and improve data processing speed.

[0006] The above content is only used to help understand the technical solution of this application and does not represent an admission that the above content is prior art. Summary of the Invention

[0007] The main objective of this application is to provide a method, apparatus, and storage medium for matrix calculation based on a microcontroller unit, aiming to solve the technical problem of reducing the computation time overhead of the MCU when performing matrix operations and improving the data processing speed.

[0008] In a first aspect, this application proposes a method for matrix computation based on a microcontroller unit, comprising:

[0009] Obtain a first matrix and a second matrix; select target elements from the first matrix and construct a corresponding one-dimensional array based on the index and numerical conditions; determine the index values ​​of the corresponding elements in the second matrix that have a calculation relationship with the target elements; determine the number of target elements in each row of the first matrix; construct a data tuple based on the one-dimensional array, the index values, and the number of target elements; and, in response to a matrix calculation instruction, sequentially read the data in the data tuple to perform matrix calculations.

[0010] In some embodiments, the first matrix is ​​a matrix with the same number of rows and columns, and the second matrix is ​​a single-column matrix with the same number of rows as the first matrix.

[0011] In some embodiments, the number of rows and columns of the first matrix is ​​the number of variable nodes in the mechanical inversion system. The first matrix is ​​a coefficient matrix, and the second matrix is ​​a displacement matrix. The elements in the second matrix are the displacements of the variable nodes. The variable nodes are nodes in the mechanical inversion system, including variable nodes to be optimized and displacement input nodes. The coefficient matrix includes an inversion force coefficient matrix and an inversion displacement coefficient matrix. The index and numerical conditions include retaining the row index corresponding to the variable node to be optimized, retaining the column index corresponding to the displacement input node, and retaining non-zero values.

[0012] In some embodiments, the index and numerical conditions include row index conditions, column index conditions, and numerical conditions. Selecting target elements from the first matrix and constructing corresponding one-dimensional arrays based on the index and numerical conditions includes: determining the target row and target column in the first matrix based on the row index conditions and column index conditions; filtering elements that are simultaneously in the target row and target column according to the numerical conditions in row priority order to determine the target elements; and constructing the one-dimensional array based on the filtering order of the target elements.

[0013] In some embodiments, the computational relationship is a multiplication relationship for calculating gradients, and determining the index value of the corresponding element in the second matrix that has a computational relationship with the target element includes: determining the corresponding element in the second matrix corresponding to each target element based on the multiplication relationship for calculating gradients; and determining the row index value of the corresponding element in the second matrix.

[0014] In some embodiments, constructing a data tuple based on the one-dimensional array, the index value, and the target number of elements includes: storing the one-dimensional array, the index value, and the target number of elements in association based on their respective attribute identifiers to construct the data tuple, wherein the data tuple is stored contiguously in memory to ensure the continuity of memory access when the microcontroller reads data in the data tuple in sequence.

[0015] In some embodiments, the step of sequentially reading data from the data tuple for matrix calculation includes: reading the number of target elements from the data tuple; sequentially reading a corresponding number of target elements and index values ​​from the data tuple according to the number of target elements; obtaining the corresponding element indicated by the index value; performing a multiplication operation on each target element and its corresponding element, and summing all products to obtain the calculation result.

[0016] In some embodiments, after performing multiplication on each target element and its corresponding element and summing all products to obtain the calculation result, the method further includes: obtaining the current loop count, subtracting one from the current loop count to obtain the remaining loop count; if the remaining loop count is greater than zero, performing the step of reading the number of target elements from the data tuple.

[0017] In a second aspect, this application also provides an apparatus for matrix calculation based on a microcontroller unit, comprising: an acquisition module for acquiring a first matrix and a second matrix; a selection module for selecting target elements from the first matrix and constructing a corresponding one-dimensional array based on index and numerical conditions; an index value determination module for determining the index values ​​of corresponding elements in the second matrix that have a calculation relationship with the target elements; an element count determination module for determining the number of target elements in each row of the first matrix; a data tuple construction module for constructing data tuples based on the one-dimensional array, the index values, and the number of target elements; and a calculation module for performing matrix calculations based on the data tuples in response to a matrix calculation instruction.

[0018] In a third aspect, this application also provides a storage medium, which is a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, it implements the steps of the matrix calculation method based on the microcontroller unit as described in any of the preceding claims.

[0019] This application provides a method for matrix calculation based on a microcontroller unit. After obtaining a first matrix and a second matrix, a one-dimensional array is constructed by selecting target elements from the first matrix that satisfy index and numerical conditions. Next, the index values ​​of corresponding elements in the second matrix that have a calculation relationship with the target elements are determined. The one-dimensional array, index values, and the number of target elements are then used to construct a corresponding data tuple. When matrix calculation is required, in response to a matrix calculation instruction, the data in the data tuple is read sequentially and used for matrix calculation. By constructing data tuples and using them for matrix calculation, the sequential access order of data can be optimized, enabling the microcontroller unit to achieve continuous memory access during matrix calculation. This effectively reduces the time overhead of data reading and improves the overall data processing capability of the microcontroller unit. Attached Figure Description

[0020] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application.

[0021] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, for those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0022] Figure 1 This is a flowchart illustrating a method for matrix calculation based on a microcontroller unit, as provided in Embodiment 1 of this application.

[0023] Figure 2 This is a flowchart illustrating Embodiment 2 of the present application, which involves matrix calculation based on a microcontroller unit.

[0024] Figure 3 This is a simplified flowchart illustrating the process of solving for mechanical inversion quantities using the mechanical inversion system provided in Embodiment 2 of this application.

[0025] Figure 4 This is a schematic diagram of the single-degree-of-freedom spring unit model in Embodiment 2 of this application;

[0026] Figure 5 This is a schematic diagram illustrating the data tuple construction process of the single-degree-of-freedom spring unit model in Embodiment 2 of this application;

[0027] Figure 6 This is a schematic diagram illustrating the calculation of gradients based on the assembly of optimization variables using data tuples in Embodiment 2 of this application.

[0028] Figure 7This is a schematic diagram of the module structure of a device for matrix calculation based on a microcontroller unit, according to an embodiment of this application.

[0029] The purpose, features, and advantages of this application will be further explained in conjunction with the embodiments and with reference to the accompanying drawings. Detailed Implementation

[0030] It should be understood that the specific embodiments described herein are merely illustrative of the technical solutions of this application and are not intended to limit this application.

[0031] The technical solutions in the embodiments of this disclosure will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of this disclosure, not all of them. Based on the embodiments in this disclosure, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this disclosure.

[0032] It should be understood that the terms “comprising” and “including” used in this disclosure and claims indicate the presence of the described features, integrals, steps, operations, elements and / or components, but do not exclude the presence or addition of one or more other features, integrals, steps, operations, elements, components and / or collections thereof.

[0033] It should also be understood that the terminology used herein is for the purpose of describing particular embodiments only and is not intended to limit the scope of this disclosure. As used in this disclosure and claims, the singular forms “a,” “an,” and “the” are intended to include the plural forms unless the context clearly indicates otherwise. It should also be understood that the term “and / or” as used in this disclosure and claims refers to any combination and all possible combinations of one or more of the associated listed items, and includes such combinations.

[0034] As used in this specification and claims, the term "if" may be interpreted, depending on the context, as "when," "once," "in response to determination," or "in response to detection." Similarly, the phrase "if determined" or "if [described condition or event] is detected" may be interpreted, depending on the context, as "once determined," "in response to determination," "once [described condition or event] is detected," or "in response to detection of [described condition or event]."

[0035] The specific embodiments disclosed herein will now be described in detail with reference to the accompanying drawings.

[0036] Reference Figure 1 , Figure 1This is a flowchart illustrating a first embodiment of the matrix calculation method based on a microcontroller unit (MCU) according to this application. In this embodiment, the matrix calculation method based on a MCU includes steps S101 to S106. It is understood that the execution entity of the method described in this embodiment is the MCU.

[0037] Step S101: Obtain the first matrix and the second matrix.

[0038] In this embodiment, the first matrix and the second matrix are two matrices that need to participate in matrix calculations. The first matrix is ​​a matrix with the same number of rows and columns, and the second matrix is ​​a single-column matrix with the same number of rows as the first matrix. The data type of the elements in the first and second matrices can be integers, floating-point numbers, or other custom data types; both can be sparse matrices. The first and second matrices can be used for various computational scenarios such as gradient calculation, feature extraction, and filtering.

[0039] Furthermore, the acquisition methods for the first and second matrices are not limited; they can be obtained through external sensors, storage devices, or program algorithms. Taking the acquisition of matrix data from external sensors as an example, in this method, the MCU can connect to multiple sensors (such as tactile sensors, array pressure sensors, etc.). It can receive data from each sensor through serial communication or a parallel interface, and store the received data as matrix data after preprocessing. In another acquisition method, the first and second matrices can be obtained through external memory. For example, for some large matrices stored in flash memory, the MCU can read them through a bus protocol. In other acquisition methods, the first and second matrices can also be calculated and generated by an algorithm program, or obtained from other hardware modules through an external interface. In addition, the acquisition methods for the first and second matrices can also be different. For example, the first matrix can be obtained through the calculation result of an algorithm program, while the second matrix can be read from a peripheral interface.

[0040] It should be noted that the terms "first" and "second" are only used to distinguish matrices and do not constitute any limitation on the size or elements of the matrix, as will be the case below.

[0041] Step S102: Select the target element from the first matrix and construct the corresponding one-dimensional array according to the index and numerical conditions.

[0042] In this embodiment, the index and numerical conditions include three parts: row index conditions, column index conditions, and numerical conditions. The index and numerical conditions can be pre-set during the program initialization phase. For example, specifying a specific row or column to traverse in the matrix in the code, or giving a fixed range of rows or columns. The numerical conditions can be a specific value, a fixed range of values, or other values ​​besides the specific value. Optionally, in other feasible implementations, the index and numerical conditions can also be dynamically set through external events such as user input, external data, and system status. Taking the MCU executing the tactile sensor inversion algorithm as an example, to ensure the reliability and timeliness of the inversion results, when performing matrix element filtering and matrix operations, the output changes of the tactile sensor at each time step can be analyzed based on the data flow of the tactile sensor, thereby dynamically adjusting the index and numerical conditions.

[0043] In the first matrix, the matrix rows that match the row index conditions are called target rows, and the matrix columns that match the column index conditions are called target columns. Further, when filtering target elements based on index and numerical conditions, the MCU quickly locates all elements simultaneously located in the target row and target column using both row and column index conditions, and filters out the target elements that meet the numerical conditions in row-major order. The filtered target elements form a one-dimensional array in the filtering order, and this one-dimensional array is stored in memory in a contiguous manner. During subsequent matrix calculations, when the MCU accesses these target elements in the filtering order, it can achieve contiguous access to memory. Optionally, in other feasible implementations, a column-major order can also be used to filter target elements from the first matrix and construct the corresponding one-dimensional array. The specific filtering order can be selected according to actual calculation or access requirements and is not limited here.

[0044] For matrices, row and column indices define the position of elements within the matrix, and some computational scenarios do not require all elements of the matrix to participate in the calculation. In this embodiment, by setting indices and numerical conditions, the target elements to be used in the calculation can be efficiently extracted from the first matrix. When the first matrix is ​​a large matrix, the amount of data stored can be effectively reduced. Furthermore, constructing the target elements into a one-dimensional array in sequence facilitates storage and access processing, greatly improving the flexibility and efficiency of the MCU in data processing.

[0045] Step S103: Determine the index value of the corresponding element in the second matrix that has a calculation relationship with the target element.

[0046] In this embodiment, the computational relationship between the target element of the first matrix and the corresponding element in the second matrix can be a multiplication relationship. Multiplying the target element by its corresponding element can be a basic operation in any computational scenario involving matrix multiplication (such as gradient calculation, convolution calculation, image filtering, etc.). The MCU can determine the corresponding element in the second matrix to be multiplied by the target element according to specific computational rules or logic. These rules or logic can be hard-coded in the program or dynamically determined by the algorithm. For example, when the target element needs to be multiplied by every element in the second matrix, then all elements in the second matrix are the corresponding elements of the target element. In the program implementation, the index value corresponding to each element in the second matrix can be read and saved using a for loop or nested loops. Furthermore, some algorithms may require skipping certain elements in the second matrix under specific conditions or performing different operations on certain specific elements. This can be achieved by setting corresponding conditional judgments and loop control structures in the program.

[0047] Furthermore, the index values ​​of the corresponding elements in the second matrix can also be stored in a one-dimensional array in the order in which they were determined, so as to facilitate the subsequent construction of data tuples.

[0048] Step S104: Determine the target number of elements in each row of the first matrix.

[0049] In this embodiment, the number of target elements in each row of the first matrix, i.e., the number of elements participating in matrix operations in each row during subsequent calculations, can be determined during the selection of target elements. As a feasible implementation, the program can be configured to count the number of target elements that meet the index and numerical conditions row by row. This counting is performed while selecting target elements in the target rows, and the count values ​​for the target rows are retained after selection. The number of target elements can also be represented by a one-dimensional array and stored in the order in which they are determined.

[0050] Step S105: Construct a data tuple based on the one-dimensional array, index value, and target number of elements.

[0051] In this embodiment, the data tuple constructed based on the one-dimensional array of target elements, index values, and the number of target elements is a data structure with three attributes. Each attribute has a corresponding attribute identifier. In a feasible implementation, the attribute identifier for the one-dimensional array containing the target elements is pre-set as VAL, the attribute identifier for the corresponding element index value is RHSIND, and the attribute identifier for the number of target elements is NPSET. Associating and storing these three types of data with their respective attribute identifiers yields the data tuple.

[0052] Understandably, compared to high-performance computers, MCUs have very limited storage resources, making the rational planning of data storage resources particularly important. In this embodiment, the data of each attribute in the data tuple is stored contiguously in memory as a one-dimensional array. In subsequent calculations, the MCU will read the data of each attribute in the data tuple for matrix calculations. Furthermore, when reading the data of each attribute in the data tuple, the MCU follows the previous storage order of the data for that attribute (i.e., the filtering order of target elements, the order in which index values ​​are determined, and the order in which the number of target elements is determined), thereby achieving continuity of memory access, reducing data access time overhead, and improving overall data processing performance.

[0053] Step S106: In response to the matrix calculation instruction, data in the data tuples are read sequentially to perform matrix calculations.

[0054] In this embodiment, the matrix calculation instruction guides the MCU to execute specific matrix calculation tasks, including how to extract relevant data from the data tuple and perform matrix calculations according to specified calculation rules. The matrix calculation instruction can be sent to the MCU by other external control units (such as the main controller) or initiated by the MCU itself when executing a program. Responding to the matrix calculation instruction means that the MCU needs to execute the corresponding matrix calculation task according to the instruction; the calculation process is based on the previously constructed data tuple.

[0055] Furthermore, the MCU can perform specific matrix calculations using an algorithm or program designed specifically for this data tuple. As a possible implementation, the execution logic of the algorithm or program is pre-designed to read the target element count from the data tuple, and based on this count, sequentially read the corresponding number of target elements and index values ​​from the one-dimensional array of target elements and the one-dimensional array of index values ​​in the data tuple. Then, based on the read index values, the corresponding elements indicated by those index values ​​are read from a second matrix. Multiplication is performed on each target element and its corresponding element, and all products are summed to obtain the final calculation result. It is understood that the above process can be repeated until the last target element count in the data tuple is read.

[0056] In other implementations, the execution logic of the algorithm or program can be configured according to the specific computational requirements. For example, suppose each target element needs to be multiplied by N (N>1 and is an integer) corresponding elements and all products are summed. In this case, the execution logic of the algorithm or program can be designed such that, for each target element read, N index values ​​are sequentially read from the index array, the current target element is multiplied by the corresponding element indicated by each index value, and all products are summed. In actual algorithm or program design, the above logic can be implemented through multiple loops or nested loops.

[0057] In this embodiment, the elements involved in the calculation of the two matrices are constructed into a data tuple, and the data of each attribute in this data tuple is stored contiguously in memory. When the MCU performs matrix calculations based on this data tuple, the data of each attribute is read sequentially, thus ensuring the continuity of memory access. This design adapts to the constraints of limited MCU storage resources and reduces the time overhead of data access, especially in scenarios involving large matrices, where the effect is more significant.

[0058] Based on Embodiment 1 of this application, the following Embodiment 2 will further explain the application of the matrix calculation method based on the microcontroller unit in a mechanics inversion system. Contents identical or similar to Embodiment 1 can be referred to the above description and will not be repeated hereafter. In Embodiment 2 of this application, the number of rows and columns of the first matrix represents the number of variable nodes in the mechanics inversion system. The first matrix is ​​a coefficient matrix, and the second matrix is ​​a displacement matrix, where the elements are the displacements of the variable nodes. The variable nodes are nodes in the mechanics inversion system, including the variable nodes to be optimized and the displacement input nodes. The coefficient matrix includes the inversion force coefficient matrix and the inversion displacement coefficient matrix. Correspondingly, the indexing and numerical conditions include retaining the row index corresponding to the variable node to be optimized, retaining the column index corresponding to the displacement input node, and retaining non-zero values.

[0059] In this embodiment, the mechanical inversion system can be understood as a system that infers the source of mechanical action or physical quantity (such as force, displacement, etc.) by measuring mechanical responses (such as pressure, deformation, displacement, vibration, etc.). This system can be widely used in feedback control research (such as tactile feedback, pressure feedback, motion feedback, etc.). For example, in a feasible implementation, the mechanical inversion system may include a tactile sensor and its inversion algorithm. The tactile sensor is responsible for collecting data such as contact force and pressure distribution in real time. The MCU executing the inversion algorithm is responsible for processing this data and performing reverse modeling based on a physical model (such as the equation of elasticity) or a deep learning model, and finally outputting the inversion result.

[0060] In a mechanics inversion system, variable nodes can be understood as nodes representing physical quantities (such as force, displacement, etc.). When an external force intervenes, the variable nodes may produce corresponding changes in physical quantities. Therefore, variable nodes can be further divided into displacement input nodes and variable nodes to be optimized. Displacement input nodes are variable nodes in the mechanics inversion system that produce displacement changes. The mechanics inversion quantities of the relevant variable nodes to be optimized can be calculated using the displacement of the displacement input nodes. Variable nodes to be optimized are those variable nodes in the mechanics inversion system that need to be reverse-engineered or optimized; they represent the mechanics inversion quantities (such as displacement, stress, etc.) that need to be solved, i.e., the target of the inversion calculation.

[0061] For ease of understanding, the following is combined with Figure 3 First, the complete calculation process for solving the mechanical inversion quantities in the mechanical inversion system will be explained. This calculation process is completed by the MCU. (Refer to...) Figure 3 The entire process can be divided into three stages: the finite element stage, the coupling stage, and the solution stage. In the finite element stage, the configuration and stress need to be updated, and the stiffness matrix K needs to be assembled. Based on the displacement of the input nodes, the optimization variable x is assembled. Next, in the coupling stage, a quadratic programming model g(x) is constructed based on the optimization variable x, and a second-order Taylor expansion is performed to calculate the gradient. The Hessian matrix H[g(x)] is used. In the solution phase, the gradient calculation results and the Hessian matrix are used to solve the SQP (Sequential Quadratic Programming) problem. After multiple iterations, the optimal solution is obtained as the final inversion result output. Simultaneously, a new round of finite element process is initiated, namely the inversion calculation of the mechanical inversion system at the next time step.

[0062] In the above process, the stiffness matrix K is used to describe the stiffness characteristics of the structure or material under stress in the mechanical inversion system. When the configuration or stress changes, the stiffness matrix K is updated accordingly. The number of rows and columns of the stiffness matrix K corresponds to the number of variable nodes in the mechanical inversion system. The first matrix is ​​derived from the stiffness matrix K and will be used as the coefficient matrix along with the displacement matrix (i.e., the second matrix) to calculate the gradient. The inversion process requires calculating the gradient expression of the objective function of the optimization model, as follows:

[0063]

[0064] in, To optimize variables, For displacement optimization variables. Correspondingly, when the first matrix is ​​used as the coefficient matrix, it includes the inverse force coefficient matrix 2K. T K and the inverted displacement coefficient matrix -2K have the same number of rows and columns as the number of variable nodes in the mechanical inversion system. The inverted force coefficient matrix is ​​the coefficient matrix used to assemble force optimization variables, while the inverted displacement coefficient matrix is ​​the coefficient matrix used to assemble displacement optimization variables. The row and column indices of the coefficient matrix correspond one-to-one with the variable node numbers. The displacement matrix, also known as the displacement vector matrix, consists of the displacement components (hereinafter referred to as displacements) of each variable node in a certain degree of freedom direction. It can be understood that the displacement matrix is ​​a single-column matrix with the same number of rows as the number of variable nodes. The row indices of the displacement matrix correspond one-to-one with the variable node numbers.

[0065] In practical applications, the coefficient matrix is ​​usually a large sparse matrix. To improve the computational efficiency and reduce computational complexity in the coupling phase, target elements need to be selected from the coefficient matrix based on indices and numerical conditions before calculating the gradient using the coefficient matrix and displacement matrix. Specifically, non-zero target elements are selected from the coefficient matrix based on the row index of the node to be optimized and the column index of the displacement input node. Simultaneously, the number of target elements in each row of the coefficient matrix is ​​also saved during this process.

[0066] Furthermore, it is necessary to determine the index values ​​of the corresponding elements in the displacement matrix that have a computational relationship with the target element. This is because when calculating the gradient, it is necessary to identify which variable nodes' displacements will affect the target element in order to establish a coupling relationship. These variable nodes are also the displacement input nodes with non-zero displacements. It can be understood that the computational relationship between the target element and its corresponding element is a multiplicative relationship used to calculate the gradient. As a feasible implementation method, when determining the index values ​​of the corresponding elements of the target element based on the displacement matrix, the target elements in the same row can be matched row by row. Specifically, for the target elements in the same row, the elements in the displacement matrix are traversed sequentially, and for each target element, non-zero elements (i.e., corresponding elements) are matched in order, and the corresponding index values ​​are saved.

[0067] Furthermore, the target elements selected from the coefficient matrix, the index values ​​of the corresponding elements in the displacement matrix, and the number of target elements in each row of the coefficient matrix are constructed into a data tuple. All three attribute data of this data tuple are stored contiguously in memory. When gradient calculation is required... First, the number of target elements is read from the data tuple. Then, the corresponding number of target elements and their indices are read sequentially from the one-dimensional array of target elements and the one-dimensional array of indices in the data tuple. The corresponding element indicated by the index value in the displacement matrix is ​​determined. Multiplication is performed on each target element and its corresponding element, and all products are summed to obtain the final calculation result. This process is repeated until the last target element in the data tuple has been read. The calculation results of each round are used to assemble the optimization variables, and the gradient calculation is based on these assembled optimization variables.

[0068] To facilitate a more thorough understanding of the technical solution of this application, a specific example is provided below for explanation. (Refer to...) Figure 4 , Figure 4The mechanical inversion system shown is a single-degree-of-freedom spring element model. Points 1, 2, 3, 4, and 5 are variable nodes. Points 2 and 3 are displacement input nodes, points 1 (f1) and 4 (f2) are variable nodes to be optimized for the inverted force, and points 4 (u4) and 5 (u5) are variable nodes to be optimized for the inverted displacement. The displacement of point 2 is -4, the displacement of point 3 is 5, and the displacements of points 1, 4, and 5 are all 0, thus forming the following... Figure 5 The corresponding displacement matrix is ​​u[0, -4, 5, 0, 0]. The row indices of the displacement matrix u, from top to bottom, are the numbers of the variable nodes.

[0069] Continue to refer to Figure 5 The inverted displacement coefficient matrix is ​​2K T K, the inverted force coefficient matrix is ​​-2K. The row and column indices of both correspond to the variable node numbers. The index and numerical conditions include: retaining the column index of the displacement input nodes, retaining the row index of the variable nodes to be optimized, and retaining non-zero values. Based on the above conditions, the displacement coefficient matrix 2K is inverted... T The one-dimensional array VAL1 constructed from the target elements selected from K is 20, 30, and 48. Similarly, the one-dimensional array VAL2 constructed from the target elements selected from the inverted force coefficient matrix -2K is -4 and -4. Next, the index values ​​of the corresponding elements in the displacement matrix that have a calculation relationship with each target element are determined. For the inverted displacement coefficient matrix, the corresponding element for 20 is -4, and the row index value of -4 is 2; the corresponding element for 30 is -4, and the index value is also 2; the corresponding element for 48 is 5, and the index value is 3. Thus, the index value array RSHIND1 is constructed as 2, 2, and 3. Similarly, the index value array RSHIND2 corresponding to the inverted force coefficient matrix is ​​2 and 3. The array NPSET1 containing the number of target elements in the inverted displacement coefficient matrix is ​​1 and 2. The array NPSET2 containing the number of target elements in the inverted force coefficient matrix is ​​1 and 1. Based on the above, the data tuples constructed from the inverted displacement coefficient matrix and the inverted force coefficient matrix are as follows: Figure 6 As shown, these are 2K T Ku and -2Ku. When calculating the gradient, they are based on 2K respectively. T Ku and -2Ku assembly force optimization variables and displacement optimization variables Specifically, with 2K TTaking Ku as an example, the data read from NPSET1 is 1. Then, the target element 20 and index value 2 are read from VAL1 and RSHIND1 respectively. The element indicated by index value 2 in the displacement matrix is ​​-4. Multiplying 20 by -4 yields -80. Continuing to read the next data from NPSET1, which is 2, we read 30 and 48 from VAL1, and 2 and 3 from RSHIND1. The calculation result is 30*-4+48*5=120. The calculation logic for the data tuple -2Ku is the same as above and will not be repeated here. The force optimization variables and displacement optimization variables assembled from the calculation results are as follows... Figure 6 As shown. Both are used to calculate the gradient.

[0070] It should be noted that the above example is merely a simple mechanical inversion system provided to facilitate the reader's understanding. It does not constitute a limitation on the practical application of the technical solution of this application.

[0071] In this embodiment, a data tuple is constructed using a first matrix and a second matrix. The data for each attribute in the data tuple is stored sequentially in memory (i.e., the order in which target elements are selected, the order in which index values ​​are determined, and the order in which the number of target elements is determined). When the matrix calculation method based on this data tuple is applied to the gradient calculation scenario of a mechanics inversion system, the constructed data tuple can adapt to the constraints of limited MCU storage resources. When used by the MCU to perform gradient calculations for finite element inversion problems in a mechanics inversion system, the MCU reads the data for each attribute sequentially (i.e., the order in which target elements are selected, the order in which index values ​​are determined, and the order in which the number of target elements is determined), ensuring continuous access to memory by the MCU, reducing the time overhead of data reading, significantly improving the single-step execution speed of the inversion calculation, and thus efficiently handling gradient solving in large-scale matrix calculations, achieving fast and efficient optimization operations in different application scenarios.

[0072] Reference Figure 2 , Figure 2 This is a flowchart illustrating the third embodiment of the matrix calculation method based on a microcontroller unit according to this application. The third embodiment can be considered as an implementation of step S106 in embodiment one. The content in this embodiment that is the same as or similar to that in embodiment one and embodiment two above can be referred to the above description, and will not be repeated hereafter.

[0073] Step S201: Read the target number of elements from the data tuple.

[0074] Step S202: Based on the number of target elements, read the corresponding number of target elements and their index values ​​sequentially from the data tuple.

[0075] Step S203: Obtain the corresponding element indicated by the index value.

[0076] Step S204: Perform multiplication on each target element and its corresponding element, and sum all products to obtain the calculation result.

[0077] This embodiment explains the implementation logic of a program or algorithm for performing matrix calculations based on data tuples, and provides the corresponding pseudocode. This program or algorithm can be used to optimize the coupling process of finite element inversion problems in mechanical inversion systems (such as tactile sensors and their inversion algorithms), that is, to improve gradient calculation efficiency.

[0078] Furthermore, the data tuple includes three attribute data: the number of target elements (NPSET), the index value (RSHIND), and the target element (VAL). The number of target elements is read from the data tuple, i.e., the data in NPSET is read. Next, based on the number of target elements, the corresponding number of target elements and index values ​​are read sequentially from the data tuples RSHIND and VAL, respectively. The corresponding element indicated by the index value in the second matrix is ​​obtained. Multiplication is performed on each target element and its corresponding element, and all products are summed to obtain the final calculation result. The above logic can be implemented using two nested for loops. The outer for loop iterates the number of data items in NPSET. The inner for loop iterates the number of target elements read from NPSET each time. Furthermore, after step S204, the current iteration count of the outer for loop is obtained, and the remaining iteration count is subtracted by one. If the remaining iteration count is greater than 0, step S201 is executed again to start a new round of looping. If the remaining loop count is 0, it means that the last data in NPSET has been read in sequence, and the loop ends at this time.

[0079] The pseudocode for this embodiment is as follows:

[0080] The function `matMul_flattenTraidMap_grad(n,VAL,RHSIND,NPSET,x,comRhs)` is used to flatten TraidMap_grad.

[0081] { / *enter:

[0082] n: The number of data items in NPSET

[0083] x: Right-hand vector

[0084] comRhs: Calculation result (must be initialized externally)* /

[0085] Initialize index ind = 0

[0086] for the result index indRes = 0 → n-1: / / Loop until the last data in NPSET is read.

[0087] {count = NPSET[indRes]; / / Read the number of target elements

[0088] {forj = 0 → count - 1: / / The number of loop iterations is the number of target elements read.}

[0089] comRhs[indRes]+=VAL[ind]*x[RHSIND[ind]];

[0090] ind++;

[0091] }

[0092] }

[0093] }

[0094] The program or algorithm for performing matrix calculations based on data tuples presented in this embodiment enables continuous access to memory, adapting to the constraints of limited MCU storage resources and reducing the time overhead of reading data. When used to perform gradient calculations for finite element inversion problems in mechanical inversion systems, it can significantly improve the single-step execution speed of inversion calculations, thereby efficiently handling gradient solutions in large-scale matrix calculations and achieving fast and efficient optimization operations in different application scenarios.

[0095] It should be noted that the above examples are only for understanding this application and do not constitute a limitation on the method of matrix calculation based on microcontroller units in this application. Any simple transformations based on this technical concept are within the protection scope of this application.

[0096] Reference Figure 7 This application also provides a matrix calculation device 700 based on a microcontroller unit. The microcontroller unit-based matrix calculation device 700 includes: an acquisition module 710 for acquiring a first matrix and a second matrix; a selection module 720 for selecting target elements from the first matrix and constructing a corresponding one-dimensional array based on index and numerical conditions; an index value determination module 730 for determining the index values ​​of corresponding elements in the second matrix that have a calculation relationship with the target elements; an element count determination module 740 for determining the number of target elements in each row of the first matrix; a data tuple construction module 750 for constructing data tuples based on the one-dimensional array, the index values, and the number of target elements; and a calculation module 760 for sequentially reading data from the data tuples to perform matrix calculations in response to a matrix calculation instruction.

[0097] The microcontroller-based matrix calculation apparatus 700 provided in this application, employing the microcontroller-based matrix calculation method described in the above embodiments, can solve the technical problem of reducing the computation time overhead of the MCU during matrix operations and improving data processing speed. Compared with the prior art, the beneficial effects of the microcontroller-based matrix calculation apparatus provided in this application are the same as those of the microcontroller-based matrix calculation method provided in the above embodiments, and other technical features in the microcontroller-based matrix calculation apparatus are the same as those disclosed in the methods of the above embodiments, and will not be repeated here.

[0098] This application provides a computer-readable storage medium storing computer-readable program instructions (i.e., a computer program) for executing the above-described method for matrix calculation based on a microcontroller unit. This solves the technical problem of reducing the computation time overhead of the MCU during matrix operations and improving data processing speed. Compared with the prior art, the beneficial effects of the computer-readable storage medium provided in this application are the same as those of the matrix calculation method based on a microcontroller unit provided in the above embodiments, and will not be repeated here.

[0099] The computer-readable storage medium provided in this application may be, for example, flash memory, but is not limited to, electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices, or any combination thereof. More specific examples of computer-readable storage media may include, but are not limited to: electrical connections having one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof. In this embodiment, the computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, system, or device. The program code contained on the computer-readable storage medium may be transmitted using any suitable medium, including but not limited to: wires, optical cables, RF (Radio Frequency), etc., or any suitable combination thereof.

[0100] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of this application. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, may be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.

[0101] The modules described in the embodiments of this application can be implemented in software or hardware. The names of the modules do not necessarily limit the functionality of the unit itself.

[0102] The above description is only a part of the embodiments of this application and does not limit the patent scope of this application. All equivalent structural transformations made under the technical concept of this application and using the contents of the specification and drawings of this application, or direct / indirect applications in other related technical fields, are included in the patent protection scope of this application.

Claims

1. A method for matrix calculation based on a microcontroller unit, characterized in that, include: Obtain the first matrix and the second matrix; Based on the index and numerical conditions, select the target element from the first matrix and construct the corresponding one-dimensional array; Determine the index value of the corresponding element in the second matrix that has a computational relationship with the target element; Determine the target number of elements in each row of the first matrix; Construct a data tuple based on the one-dimensional array, the index value, and the number of target elements; In response to a matrix calculation instruction, data from the data tuples are read sequentially to perform matrix calculations.

2. The method according to claim 1, characterized in that, The first matrix is ​​a matrix with the same number of rows and columns, and the second matrix is ​​a single-column matrix with the same number of rows as the first matrix.

3. The method according to claim 1 or 2, characterized in that, The number of rows and columns of the first matrix represents the number of variable nodes in the mechanics inversion system. The first matrix is ​​a coefficient matrix, and the second matrix is ​​a displacement matrix. The elements in the second matrix represent the displacements of the variable nodes. The variable nodes are nodes in the mechanics inversion system, including variable nodes to be optimized and displacement input nodes. The coefficient matrix includes an inversion force coefficient matrix and an inversion displacement coefficient matrix. The index and numerical conditions include retaining the row index corresponding to the variable node to be optimized, retaining the column index corresponding to the displacement input node, and retaining non-zero values.

4. The method according to claim 1, characterized in that, The index and numerical conditions include row index conditions, column index conditions, and numerical conditions. The step of selecting target elements from the first matrix and constructing corresponding one-dimensional arrays based on the index and numerical conditions includes: Based on the row index conditions and column index conditions, determine the corresponding target row and target column in the first matrix; Based on the numerical conditions, elements that are simultaneously in the target row and target column are filtered according to row priority to determine the target element; The target elements are constructed into the one-dimensional array based on the filtering order.

5. The method according to claim 1, characterized in that, The computational relationship is a multiplicative relationship used to calculate the gradient, and the index value of the corresponding element in the second matrix that has a computational relationship with the target element includes: Based on the multiplication relationship used to calculate the gradient, determine the corresponding element in the second matrix that corresponds to each of the target elements; Determine the row index value of the corresponding element in the second matrix.

6. The method according to claim 1, characterized in that, The construction of the data tuple based on the one-dimensional array, the index value, and the number of target elements includes: The one-dimensional array, the index value, and the number of target elements are associated and stored based on their respective attribute identifiers to construct the data tuple. The data tuple is stored contiguously in memory to ensure the continuity of memory access when the microcontroller reads the data in the data tuple in sequence.

7. The method according to claim 1 or 6, characterized in that, The step of sequentially reading data from the data tuples to perform matrix calculations includes: Read the number of target elements from the data tuple; Based on the number of target elements, read the corresponding number of target elements and their index values ​​sequentially from the data tuple; Determine the corresponding element indicated by the index value; Perform a multiplication operation on each target element and its corresponding element, and sum all the products to obtain the calculation result.

8. The method according to claim 7, characterized in that, After performing multiplication on each target element and its corresponding element, and summing all products to obtain the calculation result, the method further includes: Get the current loop count, and subtract one from the current loop count to get the remaining loop count; If the remaining number of iterations is greater than zero, the step of reading the target number of elements from the data tuple is executed.

9. A device for matrix calculation based on a microcontroller unit, characterized in that, include: The acquisition module is used to acquire the first matrix and the second matrix; The selection module is used to select target elements from the first matrix and construct the corresponding one-dimensional array based on the index and numerical conditions. An index value determination module is used to determine the index value of the corresponding element in the second matrix that has a calculation relationship with the target element; The element count determination module is used to determine the target number of elements in each row of the first matrix; A data tuple construction module is used to construct a data tuple based on the one-dimensional array, the index value, and the target number of elements; The calculation module is used to read data from the data tuples in sequence to perform matrix calculations in response to matrix calculation instructions.

10. A storage medium, characterized in that, The storage medium is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by a processor, it implements the steps of the matrix calculation method based on a microcontroller unit as described in any one of claims 1 to 8.