49 #include "RepastErrors.h"
88 virtual void set(
const T& value,
const Point<int>& index) = 0;
91 const T& operator[](
const Point<int>& index)
const;
110 defValue(defaultValue), _size(size), dCount(size.dimensionCount()) {
117 stride =
new int[dCount];
118 for (
int i = dCount - 1; i >= 0; i--) {
119 stride[i] = tmpStride;
120 tmpStride *= _size.getCoordinate(i);
125 Matrix<T>::~Matrix() {
130 void Matrix<T>::boundsCheck(
const Point<int>& index) {
131 if (index.dimensionCount() != dCount)
132 throw Repast_Error_47<Point<int> >(dCount, index.dimensionCount(), index);
133 for (
int i = 0; i < dCount; i++) {
134 if (index.getCoordinate(i) < 0 || index.getCoordinate(i) >= _size.getCoordinate(i))
135 throw Repast_Error_48<Point<int> >(i, index.getCoordinate(i), index, _size.getCoordinate(i));
140 int Matrix<T>::calcIndex(
const Point<int>& index) {
142 for (
size_t i = 0; i < index.dimensionCount(); i++) {
143 vIndex = vIndex + index[i] * stride[i];
149 T& Matrix<T>::operator[](
const Point<int>& index) {
154 const T& Matrix<T>::operator[](
const Point<int>& index)
const {
165 std::vector<T> values;
190 void set(
const T& value,
const Point<int>& index);
196 Matrix<T> (other._size, other.defaultValue()), values(other.values) {
209 values = std::vector<T>(rhs.values.begin(), rhs.values.end());
218 for (
int i = 0; i < Matrix<T>::dCount; i++) {
221 values = std::vector<T>(_size, defValue);
228 return values[vIndex];
235 values[vIndex] = value;
246 std::map<int, T> map;
248 typedef typename std::map<int, T>::iterator map_iter;
275 Matrix<T> (other._size, other.defaultValue()), map(other.map) {
279 SparseMatrix<T>& SparseMatrix<T>::operator=(
const SparseMatrix<T>& rhs) {
281 delete[] Matrix<T>::stride;
282 Matrix<T>::_size = rhs._size;
283 Matrix<T>::dCount = rhs.dCount;
284 Matrix<T>::defValue = rhs.defaultValue();
287 map = std::map<int, T>(rhs.map.begin(), rhs.map.end());
294 Matrix<T> (size, defValue) {
306 return res.first->second;