/**
* Add rectangular block.
*
- * A rectangular block of the
- * matrix <tt>src</tt> is added to
- * <tt>this</tt>. The upper left
- * corner of the block being
- * copied is
+ * A rectangular block of the matrix
+ * <tt>src</tt> is added to
+ * <tt>this</tt>. The upper left corner
+ * of the block being copied is
* <tt>(src_offset_i,src_offset_j)</tt>.
- * The upper left corner of the
- * copied block is
+ * The upper left corner of the copied
+ * block is
* <tt>(dst_offset_i,dst_offset_j)</tt>.
- * The size of the rectangular
- * block being copied is the
- * maximum size possible,
- * determined either by the size
- * of <tt>this</tt> or <tt>src</tt>.
+ * The size of the rectangular block
+ * being copied is the maximum size
+ * possible, determined either by the
+ * size of <tt>this</tt> or <tt>src</tt>
+ * and the given offsets.
*/
template<typename number2>
void add (const FullMatrix<number2> &src,
const unsigned int src_offset_i,
const unsigned int src_offset_j)
{
+ Assert (dst_offset_i < m(),
+ ExcIndexRange (dst_offset_i, 0, m()));
+ Assert (dst_offset_j < n(),
+ ExcIndexRange (dst_offset_j, 0, n()));
+ Assert (src_offset_i < src.m(),
+ ExcIndexRange (src_offset_i, 0, src.m()));
+ Assert (src_offset_j < src.n(),
+ ExcIndexRange (src_offset_j, 0, src.n()));
+
// Compute maximal size of copied block
- const unsigned int rows = (m() - dst_offset_i >= src.m() - src_offset_i)
- ? src.m() - src_offset_i
- : m() - dst_offset_i;
- const unsigned int cols = (n() - dst_offset_j >= src.n() - src_offset_j)
- ? src.n() - src_offset_j
- : n() - dst_offset_j;
+ const unsigned int rows = std::min (m() - dst_offset_i,
+ src.m() - src_offset_i);
+ const unsigned int cols = std::min (n() - dst_offset_j,
+ src.n() - src_offset_j);
for (unsigned int i=0; i<rows ; ++i)
for (unsigned int j=0; j<cols ; ++j)
- this->el(dst_offset_i+i,dst_offset_j+j)
- = src.el(src_offset_i+i,src_offset_j+j);
+ (*this)(dst_offset_i+i,dst_offset_j+j)
+ = src(src_offset_i+i,src_offset_j+j);
}
ExcIndexRange (src_offset_j, 0, src.n()));
// Compute maximal size of copied block
- const unsigned int rows = (m() - dst_offset_i >= src.m() - src_offset_i)
- ? src.m()
- : m();
- const unsigned int cols = (n() - dst_offset_j >= src.n() - src_offset_j)
- ? src.n()
- : n();
+ const unsigned int rows = std::min (m() - dst_offset_i,
+ src.m() - src_offset_i);
+ const unsigned int cols = std::min (n() - dst_offset_j,
+ src.n() - src_offset_j);
for (unsigned int i=0; i<rows ; ++i)
for (unsigned int j=0; j<cols ; ++j)
const unsigned int src_offset_i,
const unsigned int src_offset_j)
{
+ Assert (dst_offset_i < m(),
+ ExcIndexRange (dst_offset_i, 0, m()));
+ Assert (dst_offset_j < n(),
+ ExcIndexRange (dst_offset_j, 0, n()));
+ Assert (src_offset_i < src.m(),
+ ExcIndexRange (src_offset_i, 0, src.m()));
+ Assert (src_offset_j < src.n(),
+ ExcIndexRange (src_offset_j, 0, src.n()));
+
// Compute maximal size of copied block
- const unsigned int rows = (m() - dst_offset_i >= src.n() - src_offset_i)
- ? src.n()
- : m();
- const unsigned int cols = (n() - dst_offset_j >= src.m() - src_offset_j)
- ? src.m()
- : n();
+ const unsigned int rows = std::min (m() - dst_offset_i,
+ src.m() - src_offset_i);
+ const unsigned int cols = std::min (n() - dst_offset_j,
+ src.n() - src_offset_j);
for (unsigned int i=0; i<rows ; ++i)
for (unsigned int j=0; j<cols ; ++j)
- this->el(dst_offset_i+i,dst_offset_j+j)
- += factor * src.el(src_offset_i+j,src_offset_j+i);
+ (*this)(dst_offset_i+i,dst_offset_j+j)
+ += factor * src(src_offset_i+j,src_offset_j+i);
}