浏览代码

bug fix: in method MatrixT::setRow wrong dimension check

Frank Prüfer 11 年之前
父节点
当前提交
d38845830a
共有 2 个文件被更改,包括 27 次插入1 次删除
  1. 11 1
      core/vector/MatrixT.tcc
  2. 16 0
      core/vector/tests/test_setRow.txt

+ 11 - 1
core/vector/MatrixT.tcc

@@ -417,11 +417,21 @@ MatrixT<ElementType>::operator _Op##= (const MatrixT<ElementType>& v) {   \
   template<typename ElementType>
   void MatrixT<ElementType>::setRow(const uint & row, const NICE::VectorT<ElementType> & v)
   {
-    if (rows() < v.size() )
+    if (cols() < v.size() )
     {
       _THROW_EMatrix("Matrix setRow: target matrix too small.");
     }
+    
+    if (row >= rows() )
+    {
+      _THROW_EMatrix("Matrix setRow: row does not specify a proper row index.");
+    }
 
+    if ( cols() > v.size() )
+    {
+      cerr<<"Warning: Matrix setRow: row is longer than vector."<<endl;
+    }
+    
     // FIXME use IPP?
     for (unsigned int j = 0; j < v.size(); j++)
     {

+ 16 - 0
core/vector/tests/test_setRow.txt

@@ -0,0 +1,16 @@
+MatrixT<double> a(1,2,4.5);
+MatrixT<double> b(2,1,4.5);
+MatrixT<double> c(1,3,4.5);
+VectorT<double> v(2,1.0);
+
+a.setRow(0,v);
+//a(0,0) and a(0,1) should now be 1.0 and not 4.5
+
+a.setRow(1,v)
+//should fail, because this row is non-existent
+
+b.setRow(0,v)
+//should fail, because vector is too long 
+
+c.setRow(0,v)
+//should give a warning, because vector is shorter than one complete row