20 #ifndef KJB_M_CPP_M_MAT_UTIL_H
21 #define KJB_M_CPP_M_MAT_UTIL_H
29 #include <boost/type_traits.hpp>
30 #include <boost/concept_check.hpp>
31 #include <boost/multi_array.hpp>
49 template<
class value_type>
74 template <
class Iterator>
78 using namespace boost;
79 typedef typename std::iterator_traits<Iterator>::value_type Vector_type;
80 typedef typename Vector_type::value_type Value_type;
93 template <
class Iterator>
94 typename Matrix_traits<typename std::iterator_traits<Iterator>::value_type::value_type>::Matrix_type
97 using namespace boost;
98 typedef typename std::iterator_traits<Iterator>::value_type Vector_type;
99 typedef typename Vector_type::value_type Value_type;
101 typedef typename Vector_type::size_type Size_type;
107 return Matrix_type();
110 const Size_type NUM_COLS = std::distance(begin, end);
111 const Size_type NUM_ROWS = (*begin).size();
113 for( Iterator it = begin; it != end; ++it)
115 const Vector_type& column = *it;
116 if ( column.size() != NUM_ROWS )
119 "Input vectors differ in length" );
125 return Matrix_type();
128 Matrix_type result( NUM_ROWS, NUM_COLS );
131 for( Iterator it = begin; it != end; ++it )
133 result.set_col( col, it->begin(), it->end());
145 template <
class Container_>
147 typename Matrix_traits<typename Container_::value_type::value_type>::Matrix_type
150 using namespace ::boost;
151 BOOST_CONCEPT_ASSERT((Container<Container_>));
160 template <
class Container_>
162 typename Matrix_traits<typename Container_::value_type::value_type>::Matrix_type
165 using namespace ::boost;
166 BOOST_CONCEPT_ASSERT((Container<Container_>));
Definition for the Int_matrix class, a thin wrapper on the KJB Int_matrix struct and its related func...
Definition for the Matrix class, a thin wrapper on the KJB Matrix struct and its related functionalit...
Definition: m_concept.h:30
Object thrown when an argument is of the wrong size or dimensions.
Definition: l_exception.h:426
This class implements matrices, in the linear-algebra sense, restricted to integer-valued elements...
Definition: l_int_matrix.h:71
Matrix_traits< typename std::iterator_traits< Iterator >::value_type::value_type >::Matrix_type create_matrix_from_columns(const Iterator &begin, const Iterator &end)
Build a matrix from a container of column vectors.
Definition: m_mat_util.h:95
kjb::Matrix Matrix_type
Definition: m_mat_util.h:66
Matrix_traits< typename std::iterator_traits< Iterator >::value_type::value_type >::Matrix_type create_matrix_from_rows(Iterator begin, Iterator end)
Build a matrix from a container of row vectors.
Definition: m_mat_util.h:76
Definition: m_mat_util.h:50
Matrix_stl_view get_matrix_stl_view(kjb::Matrix &mat)
Definition: m_mat_util.cpp:26
Int_matrix matrix_transpose(const Int_matrix &op1)
Test for any difference between two matrices.
Definition: l_int_matrix.h:1331
#define KJB_THROW_2(ex, msg)
Definition: l_exception.h:48
boost::multi_array_ref< double, 2 > Matrix_stl_view
Definition: m_mat_util.h:174
kjb::Int_matrix Matrix_type
Definition: m_mat_util.h:58
This class implements matrices, in the linear-algebra sense, with real-valued elements.
Definition: m_matrix.h:94
Definition for the Int_vector class, a thin wrapper on the KJB Int_vector struct and its related func...
Definition for the Vector class, a thin wrapper on the KJB Vector struct and its related functionalit...