32 dlib::matrix<T> data_;
35 explicit Matrix(
size_t n): data_(n, n) {}
36 Matrix(
size_t nr,
size_t nc): data_(nr, nc) {}
37 size_t nr()
const {
return data_.nr(); }
38 size_t nc()
const {
return data_.nc(); }
39 T& operator()(
size_t i,
size_t j) {
return data_(i, j); }
40 const T& operator()(
size_t i,
size_t j)
const {
return data_(i, j); }
41 const dlib::matrix<T>& dlib()
const {
return data_; }
49 Matrix(): nr_(0), nc_(0), data_(NULL) {}
50 explicit Matrix(
size_t n): nr_(n), nc_(n), data_(
new T[n*n]) {}
51 Matrix(
size_t nr,
size_t nc): nr_(nr), nc_(nc), data_(
new T[nr*nc]) {}
55 Matrix(
const Matrix<T> &other): nr_(other.nr_), nc_(other.nc_), data_(
new T[other.size()]) {
56 memcpy(data_, other.data_, size()*
sizeof(T));
59 if (size() != other.size()) {
61 data_ =
new T[other.size()];
65 memcpy(data_, other.data_, size()*
sizeof(T));
70 size_t nr()
const {
return nr_; }
71 size_t nc()
const {
return nc_; }
74 T& operator()(
size_t i,
size_t j) {
75 ASSERT_require(i < nr_);
76 ASSERT_require(j < nc_);
77 return data_[i*nc_+j];
79 const T& operator()(
size_t i,
size_t j)
const {
80 ASSERT_require(i < nr_);
81 ASSERT_require(j < nc_);
82 return data_[i*nc_+j];
90 size_t size()
const {
return nr()*nc(); }
92#ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
94 friend class boost::serialization::access;
97 void save(S &s,
const unsigned )
const {
98 size_t nr = this->nr(), nc = this->nc();
99 s & BOOST_SERIALIZATION_NVP(nr);
100 s & BOOST_SERIALIZATION_NVP(nc);
101 if (nr > 0 && nc > 0) {
102 const T *values = &(*this)(0, 0);
103 s & boost::serialization::make_nvp(
"values", boost::serialization::make_array(values, nr*nc));
108 void load(S &s,
const unsigned ) {
110 s & BOOST_SERIALIZATION_NVP(nr);
111 s & BOOST_SERIALIZATION_NVP(nc);
113 if (nr > 0 && nc > 0) {
114 T *values = &tmp(0, 0);
115 s & boost::serialization::make_nvp(
"values", boost::serialization::make_array(values, nr*nc));
120 BOOST_SERIALIZATION_SPLIT_MEMBER();