| 689 | |
| 690 | template <typename SCAL> |
| 691 | ConstantElementByElementMatrix<SCAL> :: |
| 692 | ConstantElementByElementMatrix (size_t ah, size_t aw, Matrix<SCAL> amatrix, |
| 693 | Table<int> acol_dnums, Table<int> arow_dnums) |
| 694 | : h(ah), w(aw), matrix(amatrix), col_dnums(std::move(acol_dnums)), row_dnums(std::move(arow_dnums)) |
| 695 | { |
| 696 | is_complex = std::is_same<SCAL, Complex>(); |
| 697 | |
| 698 | // checking zero entries: |
| 699 | int num_zero_rows = 0; |
| 700 | Array<int> compress; |
| 701 | for (int i = 0; i < matrix.Height(); i++) |
| 702 | if (L2Norm(matrix.Row(i)) == 0) |
| 703 | num_zero_rows++; |
| 704 | else |
| 705 | compress.Append(i); |
| 706 | if (num_zero_rows) |
| 707 | { |
| 708 | Matrix<SCAL> cmatrix(compress.Size(), matrix.Width()); |
| 709 | for (int i = 0; i < compress.Size(); i++) |
| 710 | cmatrix.Row(i) = matrix.Row(compress[i]); |
| 711 | |
| 712 | Table<int> ccol_dnums(col_dnums.Size(), compress.Size()); |
| 713 | for (int i = 0; i < col_dnums.Size(); i++) |
| 714 | for (int j = 0; j < compress.Size(); j++) |
| 715 | ccol_dnums[i][j] = col_dnums[i][compress[j]]; |
| 716 | |
| 717 | matrix = std::move(cmatrix); |
| 718 | col_dnums = std::move(ccol_dnums); |
| 719 | } |
| 720 | |
| 721 | |
| 722 | int num_zero_cols = 0; |
| 723 | compress.SetSize(0); |
| 724 | for (int i = 0; i < matrix.Width(); i++) |
| 725 | if (L2Norm(matrix.Col(i)) == 0) |
| 726 | num_zero_cols++; |
| 727 | else |
| 728 | compress.Append(i); |
| 729 | if (num_zero_cols) |
| 730 | { |
| 731 | Matrix<SCAL> cmatrix(matrix.Height(), compress.Size()); |
| 732 | for (int i = 0; i < compress.Size(); i++) |
| 733 | cmatrix.Col(i) = matrix.Col(compress[i]); |
| 734 | |
| 735 | Table<int> crow_dnums(row_dnums.Size(), compress.Size()); |
| 736 | for (int i = 0; i < row_dnums.Size(); i++) |
| 737 | for (int j = 0; j < compress.Size(); j++) |
| 738 | crow_dnums[i][j] = row_dnums[i][compress[j]]; |
| 739 | |
| 740 | matrix = std::move(cmatrix); |
| 741 | row_dnums = std::move(crow_dnums); |
| 742 | } |
| 743 | |
| 744 | /* |
| 745 | int num_zero = 0; |
| 746 | for (int i = 0; i < matrix.Width(); i++) |
| 747 | for (int j = 0; j < matrix.Height(); j++) |
| 748 | if (matrix(i,j) == 0) |
nothing calls this directly
no test coverage detected