2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2006--2010 Joe Neeman <joeneeman@gmail.com>
6 LilyPond is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 LilyPond is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
23 #include "std-vector.hh"
25 template<class T
, class A
=std::allocator
<T
> >
34 Matrix
<T
, A
> (vsize rows
, vsize columns
, T
const &t
)
35 : data_(rows
* columns
, t
)
40 const T
&at (vsize row
, vsize col
) const
42 assert (row
< rank_
&& col
* rank_
+ row
< data_
.size ());
44 return data_
[col
* rank_
+ row
];
47 T
&at (vsize row
, vsize col
)
49 assert (row
< rank_
&& col
* rank_
+ row
< data_
.size ());
51 return data_
[col
* rank_
+ row
];
54 void resize (vsize rows
, vsize columns
, T
const &t
)
57 data_
.resize (rows
* columns
, t
);
61 new_data
.resize (rows
* columns
, t
);
62 vsize cur_cols
= rank_
? data_
.size () / rank_
: 0;
64 for (vsize i
= 0; i
< cur_cols
; i
++)
65 for (vsize j
= 0; j
< rank_
; j
++)
66 new_data
[i
*rows
+ j
] = data_
[i
*rank_
+ j
];
77 #endif /* MATRIX_HH */