/* * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. * * Use of this source code is governed by a BSD-style license * that can be found in the LICENSE file in the root of the source * tree. An additional intellectual property rights grant can be found * in the file PATENTS. All contributing project authors may * be found in the AUTHORS file in the root of the source tree. */ #include "modules/audio_processing/beamformer/complex_matrix.h" #include "modules/audio_processing/beamformer/matrix_test_helpers.h" #include "test/gtest.h" namespace webrtc { TEST(ComplexMatrixTest, TestPointwiseConjugate) { const int kNumRows = 2; const int kNumCols = 4; const complex kValuesInitial[kNumRows][kNumCols] = { {complex(1.1f, 1.1f), complex(2.2f, -2.2f), complex(3.3f, 3.3f), complex(4.4f, -4.4f)}, {complex(5.5f, 5.5f), complex(6.6f, -6.6f), complex(7.7f, 7.7f), complex(8.8f, -8.8f)}}; const complex kValuesExpected[kNumRows][kNumCols] = { {complex(1.1f, -1.1f), complex(2.2f, 2.2f), complex(3.3f, -3.3f), complex(4.4f, 4.4f)}, {complex(5.5f, -5.5f), complex(6.6f, 6.6f), complex(7.7f, -7.7f), complex(8.8f, 8.8f)}}; ComplexMatrix initial_mat(*kValuesInitial, kNumRows, kNumCols); ComplexMatrix expected_result(*kValuesExpected, kNumRows, kNumCols); ComplexMatrix actual_result(kNumRows, kNumCols); actual_result.PointwiseConjugate(initial_mat); MatrixTestHelpers::ValidateMatrixEqualityComplexFloat(expected_result, actual_result); initial_mat.PointwiseConjugate(); MatrixTestHelpers::ValidateMatrixEqualityComplexFloat(initial_mat, actual_result); } TEST(ComplexMatrixTest, TestConjugateTranspose) { const int kNumInitialRows = 2; const int kNumInitialCols = 4; const int kNumResultRows = 4; const int kNumResultCols = 2; const complex kValuesInitial[kNumInitialRows][kNumInitialCols] = { {complex(1.1f, 1.1f), complex(2.2f, 2.2f), complex(3.3f, 3.3f), complex(4.4f, 4.4f)}, {complex(5.5f, 5.5f), complex(6.6f, 6.6f), complex(7.7f, 7.7f), complex(8.8f, 8.8f)}}; const complex kValuesExpected[kNumResultRows][kNumResultCols] = { {complex(1.1f, -1.1f), complex(5.5f, -5.5f)}, {complex(2.2f, -2.2f), complex(6.6f, -6.6f)}, {complex(3.3f, -3.3f), complex(7.7f, -7.7f)}, {complex(4.4f, -4.4f), complex(8.8f, -8.8f)}}; ComplexMatrix initial_mat( *kValuesInitial, kNumInitialRows, kNumInitialCols); ComplexMatrix expected_result( *kValuesExpected, kNumResultRows, kNumResultCols); ComplexMatrix actual_result(kNumResultRows, kNumResultCols); actual_result.ConjugateTranspose(initial_mat); MatrixTestHelpers::ValidateMatrixEqualityComplexFloat(expected_result, actual_result); initial_mat.ConjugateTranspose(); MatrixTestHelpers::ValidateMatrixEqualityComplexFloat(initial_mat, actual_result); } TEST(ComplexMatrixTest, TestZeroImag) { const int kNumRows = 2; const int kNumCols = 2; const complex kValuesInitial[kNumRows][kNumCols] = { {complex(1.1f, 1.1f), complex(2.2f, 2.2f)}, {complex(3.3f, 3.3f), complex(4.4f, 4.4f)}}; const complex kValuesExpected[kNumRows][kNumCols] = { {complex(1.1f, 0.f), complex(2.2f, 0.f)}, {complex(3.3f, 0.f), complex(4.4f, 0.f)}}; ComplexMatrix initial_mat(*kValuesInitial, kNumRows, kNumCols); ComplexMatrix expected_result(*kValuesExpected, kNumRows, kNumCols); ComplexMatrix actual_result; actual_result.ZeroImag(initial_mat); MatrixTestHelpers::ValidateMatrixEqualityComplexFloat(expected_result, actual_result); initial_mat.ZeroImag(); MatrixTestHelpers::ValidateMatrixEqualityComplexFloat(initial_mat, actual_result); } } // namespace webrtc