Skip to content

Commit 7362163

Browse files
author
allywarner
committed
Final Changes
1 parent bd870b3 commit 7362163

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

src/Core/Algorithms/Math/ComputeSVD.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ using namespace SCIRun::Core::Algorithms::Math;
4242

4343
void ComputeSVDAlgo::run(MatrixHandle input, DenseMatrixHandle& LeftSingMat, DenseMatrixHandle& SingVals, DenseMatrixHandle& RightSingMat) const
4444
{
45+
if (input->nrows() == 0 || input->ncols() == 0){
46+
47+
THROW_ALGORITHM_INPUT_ERROR("Input has a zero dimension.");
48+
}
4549
if (matrix_is::dense(input))
4650
{
4751
auto denseInput = matrix_cast::as_dense(input);

src/Modules/Math/Tests/ComputePCAtest.cc

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
DEALINGS IN THE SOFTWARE.
2727
*/
2828

29+
//ComputePCA module test.
2930
#include <Testing/ModuleTestBase/ModuleTestBase.h>
3031
#include <Modules/Math/ComputePCA.h>
3132
#include <Core/Datatypes/DenseColumnMatrix.h>
@@ -43,6 +44,7 @@ class ComputePCAtest : public ModuleTest
4344
{
4445
};
4546

47+
//Checks for null input.
4648
TEST_F(ComputePCAtest, CheckInputNull)
4749
{
4850
auto pcaMod = makeModule("ComputePCA");
@@ -52,25 +54,30 @@ TEST_F(ComputePCAtest, CheckInputNull)
5254
EXPECT_THROW(pcaMod -> execute(), NullHandleOnPortException);
5355
}
5456

55-
TEST_F(ComputePCAtest, CheckInputColumn)
57+
//Checks for dense input.
58+
TEST_F(ComputePCAtest, CheckInputDense)
5659
{
5760
auto pcaMod = makeModule("ComputePCA");
58-
DenseColumnMatrixHandle columnInput(new DenseColumnMatrix(5));
59-
(*columnInput) << 1,2,3,4,5;
60-
stubPortNWithThisData(pcaMod, 0, columnInput);
61+
MatrixHandle denseMatrix = MAKE_DENSE_MATRIX_HANDLE((1,2,5,6)(3,4,7,9)(7,8,9,1)(2,3,5,9));
62+
stubPortNWithThisData(pcaMod, 0, denseMatrix);
6163

6264
EXPECT_NO_THROW(pcaMod -> execute());
6365
}
6466

65-
TEST_F(ComputePCAtest, CheckInputDense)
67+
//ComputePCA currently only supports dense input, but we will leave these if we want to change it later.
68+
//There is a check for this in the algorithm.
69+
//Checks for column input.
70+
TEST_F(ComputePCAtest, CheckInputColumn)
6671
{
6772
auto pcaMod = makeModule("ComputePCA");
68-
MatrixHandle denseMatrix = MAKE_DENSE_MATRIX_HANDLE((1,2,5,6)(3,4,7,9)(7,8,9,1)(2,3,5,9));
69-
stubPortNWithThisData(pcaMod, 0, denseMatrix);
73+
DenseColumnMatrixHandle columnInput(new DenseColumnMatrix(5));
74+
(*columnInput) << 1,2,3,4,5;
75+
stubPortNWithThisData(pcaMod, 0, columnInput);
7076

7177
EXPECT_NO_THROW(pcaMod -> execute());
7278
}
7379

80+
//Checks for sparse input.
7481
TEST_F(ComputePCAtest, CheckInputSparse)
7582
{
7683
auto pcaMod = makeModule("ComputePCA");

0 commit comments

Comments
 (0)