ESP-IDF Firmware
Firmware architecture and call graph
Loading...
Searching...
No Matches
dspm Namespace Reference

DSP matrix namespace. More...

Data Structures

class  Mat
 Matrix. More...

Functions

std::ostream & operator<< (std::ostream &os, const Mat &m)
std::ostream & operator<< (std::ostream &os, const Mat::Rect &rect)
std::istream & operator>> (std::istream &is, Mat &m)
Mat operator+ (const Mat &A, const Mat &B)
Mat operator+ (const Mat &A, float C)
Mat operator- (const Mat &A, const Mat &B)
Mat operator- (const Mat &A, float C)
Mat operator* (const Mat &A, const Mat &B)
Mat operator* (const Mat &A, float C)
Mat operator* (float C, const Mat &A)
Mat operator/ (const Mat &A, float C)
Mat operator/ (const Mat &A, const Mat &B)
bool operator== (const Mat &A, const Mat &B)
ostream & operator<< (ostream &os, const Mat &m)
ostream & operator<< (ostream &os, const Mat::Rect &rect)
istream & operator>> (istream &is, Mat &m)

Detailed Description

DSP matrix namespace.

DSP library matrix namespace.

Function Documentation

◆ operator*() [1/3]

Mat dspm::operator* ( const Mat & A,
const Mat & B )
  • operator, multiplication of two matrices. The operator use DSP optimized implementation of multiplication.
Parameters
[in]AInput matrix A
[in]BInput matrix B
Returns
  • result matrix A*B

Definition at line 933 of file mat.cpp.

934{
935 if (m1.cols != m2.rows) {
936 ESP_LOGW("Mat", "operator * Error: matrices do not have correct dimensions");
937 Mat err_ret;
938 return err_ret;
939 }
940 Mat temp(m1.rows, m2.cols);
941
942 if (m1.sub_matrix || m2.sub_matrix) {
943 dspm_mult_ex_f32(m1.data, m2.data, temp.data, m1.rows, m1.cols, m2.cols, m1.padding, m2.padding, temp.padding);
944 } else {
945 dspm_mult_f32(m1.data, m2.data, temp.data, m1.rows, m1.cols, m2.cols);
946 }
947
948 return temp;
949
950}
Matrix.
Definition mat.h:30
#define dspm_mult_ex_f32
Definition dspm_mult.h:226
#define dspm_mult_f32
Definition dspm_mult.h:221

References dspm::Mat::cols, dspm::Mat::data, dspm_mult_ex_f32, dspm_mult_f32, dspm::Mat::padding, dspm::Mat::rows, and dspm::Mat::sub_matrix.

◆ operator*() [2/3]

Mat dspm::operator* ( const Mat & A,
float C )
  • operator, multiplication of matrix with constant The operator use DSP optimized implementation of multiplication.
Parameters
[in]AInput matrix A
[in]Cfloating point value
Returns
  • result matrix A*B

Definition at line 952 of file mat.cpp.

953{
954 if (m.sub_matrix) {
955 Mat temp(m.rows, m.cols);
956 dspm_mulc_f32(m.data, temp.data, num, m.rows, m.cols, m.padding, temp.padding, 1, 1);
957 return temp;
958 } else {
959 Mat temp(m);
960 return (temp *= num);
961 }
962}
#define dspm_mulc_f32
Definition dspm_mulc.h:57
const int m
Definition test_mmult.c:16

References dspm::Mat::data, dspm_mulc_f32, m, and dspm::Mat::padding.

◆ operator*() [3/3]

Mat dspm::operator* ( float C,
const Mat & A )
  • operator, multiplication of matrix with constant The operator use DSP optimized implementation of multiplication.
Parameters
[in]Cfloating point value
[in]AInput matrix A
Returns
  • result matrix A*B

Definition at line 964 of file mat.cpp.

965{
966 return (m * num);
967}

References m.

◆ operator+() [1/2]

Mat dspm::operator+ ( const Mat & A,
const Mat & B )
  • operator, sum of two matrices The operator use DSP optimized implementation of multiplication.
Parameters
[in]AInput matrix A
[in]BInput matrix B
Returns
  • result matrix A+B

Definition at line 855 of file mat.cpp.

856{
857 if ((m1.rows != m2.rows) || (m1.cols != m2.cols)) {
858 ESP_LOGW("Mat", "operator + Error: matrices do not have equal dimensions");
859 Mat err_ret;
860 return err_ret;
861 }
862
863 if (m1.sub_matrix || m2.sub_matrix) {
864 Mat temp(m1.rows, m2.cols);
865 dspm_add_f32(m1.data, m2.data, temp.data, m1.rows, m1.cols, m1.padding, m2.padding, temp.padding, 1, 1, 1);
866 return temp;
867 } else {
868 Mat temp(m1);
869 return (temp += m2);
870 }
871}
#define dspm_add_f32
Definition dspm_add.h:62

References dspm::Mat::cols, dspm::Mat::data, dspm_add_f32, dspm::Mat::padding, dspm::Mat::rows, and dspm::Mat::sub_matrix.

◆ operator+() [2/2]

Mat dspm::operator+ ( const Mat & A,
float C )
  • operator, sum of matrix with constant The operator use DSP optimized implementation of multiplication.
Parameters
[in]AInput matrix A
[in]CInput constant
Returns
  • result matrix A+C

Definition at line 873 of file mat.cpp.

874{
875 if (m.sub_matrix) {
876 Mat temp(m.rows, m.cols);
877 dspm_addc_f32(m.data, temp.data, C, m.rows, m.cols, m.padding, temp.padding, 1, 1);
878 return temp;
879 } else {
880 Mat temp(m);
881 return (temp += C);
882 }
883}
#define dspm_addc_f32
Definition dspm_addc.h:57
float C[4][16]
Definition test_mmult.c:22

References C, dspm::Mat::data, dspm_addc_f32, m, and dspm::Mat::padding.

◆ operator-() [1/2]

Mat dspm::operator- ( const Mat & A,
const Mat & B )
  • operator, subtraction of two matrices The operator use DSP optimized implementation of multiplication.
Parameters
[in]AInput matrix A
[in]BInput matrix B
Returns
  • result matrix A-B

Definition at line 903 of file mat.cpp.

904{
905 if ((m1.rows != m2.rows) || (m1.cols != m2.cols)) {
906 ESP_LOGW("Mat", "operator - Error: matrices do not have equal dimensions");
907 Mat err_ret;
908 return err_ret;
909 }
910
911 if (m1.sub_matrix || m2.sub_matrix) {
912 Mat temp(m1.rows, m1.cols);
913 dspm_sub_f32(m1.data, m2.data, temp.data, m1.rows, m1.cols, m1.padding, m2.padding, temp.padding, 1, 1, 1);
914 return temp;
915 } else {
916 Mat temp(m1);
917 return (temp -= m2);
918 }
919}
#define dspm_sub_f32
Definition dspm_sub.h:58

References dspm::Mat::cols, dspm::Mat::data, dspm_sub_f32, dspm::Mat::padding, dspm::Mat::rows, and dspm::Mat::sub_matrix.

◆ operator-() [2/2]

Mat dspm::operator- ( const Mat & A,
float C )
  • operator, sum of matrix with constant The operator use DSP optimized implementation of multiplication.
Parameters
[in]AInput matrix A
[in]CInput constant
Returns
  • result matrix A+C

Definition at line 921 of file mat.cpp.

922{
923 if (m.sub_matrix) {
924 Mat temp(m.rows, m.cols);
925 dspm_addc_f32(m.data, temp.data, -C, m.rows, m.cols, m.padding, temp.padding, 1, 1);
926 return temp;
927 } else {
928 Mat temp(m);
929 return (temp -= C);
930 }
931}

References C, dspm::Mat::data, dspm_addc_f32, m, and dspm::Mat::padding.

◆ operator/() [1/2]

Mat dspm::operator/ ( const Mat & A,
const Mat & B )

/ operator, divide matrix A by matrix B

Parameters
[in]AInput matrix A
[in]BInput matrix B
Returns
  • result matrix C, where C[i,j] = A[i,j]/B[i,j]

Definition at line 981 of file mat.cpp.

982{
983 if ((A.rows != B.rows) || (A.cols != B.cols)) {
984 ESP_LOGW("Mat", "Operator + Error: matrices do not have equal dimensions");
985 Mat err_ret;
986 return err_ret;
987 }
988
989 Mat temp(A.rows, A.cols);
990 for (int row = 0; row < A.rows; row++) {
991 for (int col = 0; col < A.cols; col++) {
992 temp(row, col) = A(row, col) / B(row, col);
993 }
994 }
995 return temp;
996}
float B[8][16]
Definition test_mmult.c:21
float A[4][8]
Definition test_mmult.c:20

References A, and B.

◆ operator/() [2/2]

Mat dspm::operator/ ( const Mat & A,
float C )

/ operator, divide of matrix by constant The operator use DSP optimized implementation of multiplication.

Parameters
[in]AInput matrix A
[in]Cfloating point value
Returns
  • result matrix A*B

Definition at line 969 of file mat.cpp.

970{
971 if (m.sub_matrix) {
972 Mat temp(m.rows, m.cols);
973 dspm_mulc_f32(m.data, temp.data, 1 / num, m.rows, m.cols, m.padding, temp.padding, 1, 1);
974 return temp;
975 } else {
976 Mat temp(m);
977 return (temp /= num);
978 }
979}

References dspm::Mat::data, dspm_mulc_f32, m, and dspm::Mat::padding.

◆ operator<<() [1/4]

ostream & dspm::operator<< ( ostream & os,
const Mat & m )

Definition at line 998 of file mat.cpp.

999{
1000 for (int i = 0; i < m.rows; ++i) {
1001 os << m(i, 0);
1002 for (int j = 1; j < m.cols; ++j) {
1003 os << " " << m(i, j);
1004 }
1005 os << endl;
1006 }
1007 return os;
1008}

References m.

◆ operator<<() [2/4]

ostream & dspm::operator<< ( ostream & os,
const Mat::Rect & rect )

Definition at line 1010 of file mat.cpp.

1011{
1012 os << "row start " << rect.y << endl;
1013 os << "col start " << rect.x << endl;
1014 os << "row count " << rect.height << endl;
1015 os << "col count " << rect.width << endl;
1016
1017 return os;
1018}
int width
Definition mat.h:51
int height
Definition mat.h:52

References dspm::Mat::Rect::height, dspm::Mat::Rect::width, dspm::Mat::Rect::x, and dspm::Mat::Rect::y.

◆ operator<<() [3/4]

std::ostream & dspm::operator<< ( std::ostream & os,
const Mat & m )

Print matrix to the standard iostream.

Parameters
[in]osoutput stream
[in]mmatrix to print
Returns
  • output stream

References m.

◆ operator<<() [4/4]

std::ostream & dspm::operator<< ( std::ostream & os,
const Mat::Rect & rect )

Print rectangular ROI to the standard iostream.

Parameters
[in]osoutput stream
[in]rectROI
Returns
  • output stream

◆ operator==()

bool dspm::operator== ( const Mat & A,
const Mat & B )

== operator, compare two matrices

Parameters
[in]AInput matrix A
[in]BInput matrix B
Returns
  • true if matrices are the same
  • false if matrices are different

Definition at line 885 of file mat.cpp.

886{
887 if ((m1.cols != m2.cols) || (m1.rows != m2.rows)) {
888 return false;
889 }
890
891 for (int row = 0; row < m1.rows; row++) {
892 for (int col = 0; col < m1.cols; col++) {
893 if (m1(row, col) != m2(row, col)) {
894 ESP_LOGW("Mat", "operator == Error: %i %i, m1.data=%f, m2.data=%f \n", row, col, m1(row, col), m2(row, col));
895 return false;
896 }
897 }
898 }
899
900 return true;
901}

References dspm::Mat::cols, and dspm::Mat::rows.

◆ operator>>() [1/2]

istream & dspm::operator>> ( istream & is,
Mat & m )

Definition at line 1020 of file mat.cpp.

1021{
1022 for (int i = 0; i < m.rows; ++i) {
1023 for (int j = 0; j < m.cols; ++j) {
1024 is >> m(i, j);
1025 }
1026 }
1027 return is;
1028}

References m.

◆ operator>>() [2/2]

std::istream & dspm::operator>> ( std::istream & is,
Mat & m )

Fill the matrix from iostream.

Parameters
[in]isinput stream
[in]mmatrix to fill
Returns
  • input stream

References A, B, C, and m.