SparseMatrix<number> &
copy_from (const SparseMatrix<somenumber> &source);
+ /**
+ * This function is complete
+ * analogous to the
+ * @ref{SparsityPattern}@p{::copy_from}
+ * function in that it allows to
+ * initialize a whole matrix in
+ * one step. See there for more
+ * information on argument types
+ * and their meaning. You can
+ * also find a small example on
+ * how to use this function
+ * there.
+ *
+ * The only difference to the
+ * cited function is that the
+ * objects which the inner
+ * iterator points to need to be
+ * of type @p{std::pair<unsigned int, value},
+ * where @p{value}
+ * needs to be convertible to the
+ * element type of this class, as
+ * specified by the @p{number}
+ * template argument.
+ *
+ * Previous content of the matrix
+ * is overwritten. Note that the
+ * entries specified by the input
+ * parameters need not
+ * necessarily cover all elements
+ * of the matrix. Elements not
+ * covered remain untouched.
+ */
+ template <typename ForwardIterator>
+ void copy_from (const ForwardIterator begin,
+ const ForwardIterator end);
+
/**
* Add @p{matrix} scaled by
* @p{factor} to this matrix. The
* Exception
*/
DeclException0 (ExcInvalidConstructorCall);
+ /**
+ * Exception
+ */
+ DeclException2 (ExcIteratorRange,
+ int, int,
+ << "The iterators denote a range of " << arg1
+ << " elements, but the given number of rows was " << arg2);
private:
/**
};
+
template <typename number>
inline
number & SparseMatrix<number>::diag_element (const unsigned int i)
};
+
template <typename number>
inline
number
};
+
template <typename number>
inline
number SparseMatrix<number>::global_entry (const unsigned int j) const
};
+
template <typename number>
inline
number & SparseMatrix<number>::global_entry (const unsigned int j)
};
+
+template <typename number>
+template <typename ForwardIterator>
+void
+SparseMatrix<number>::copy_from (const ForwardIterator begin,
+ const ForwardIterator end)
+{
+ Assert (static_cast<unsigned int>(std::distance (begin, end)) == m(),
+ ExcIteratorRange (std::distance (begin, end), m()));
+
+ // for use in the inner loop, we
+ // define a typedef to the type of
+ // the inner iterators
+ typedef typename std::iterator_traits<ForwardIterator>::value_type::const_iterator inner_iterator;
+ unsigned int row=0;
+ for (ForwardIterator i=begin; i!=end; ++i, ++row)
+ {
+ const inner_iterator end_of_row = i->end();
+ for (inner_iterator j=i->begin(); j!=end_of_row; ++j)
+ // write entries
+ set (row, j->first, j->second);
+ };
+};
+
+
+
/*---------------------------- sparse_matrix.h ---------------------------*/
#endif