From 8bf8e4dc1f65a37e280a08fd9a64f5cc6e5eaab7 Mon Sep 17 00:00:00 2001 From: Manohar Paluri Date: Mon, 1 Mar 2010 18:07:18 +0000 Subject: [PATCH] added operator() to change values --- cpp/Tensor2.h | 62 +++++++++++++++++++++++++++------------------------ 1 file changed, 33 insertions(+), 29 deletions(-) diff --git a/cpp/Tensor2.h b/cpp/Tensor2.h index 87e2b3962..36bc5ce75 100644 --- a/cpp/Tensor2.h +++ b/cpp/Tensor2.h @@ -10,41 +10,45 @@ namespace tensors { - /** Rank 2 Tensor */ - template - class Tensor2 { - protected: - Tensor1 T[N2]; +/** Rank 2 Tensor */ +template +class Tensor2 { +protected: + Tensor1 T[N2]; - public: +public: - /** default constructor */ - Tensor2() { - } + /** default constructor */ + Tensor2() { + } - /* construct from data */ - Tensor2(const double data[N2][N1]) { - for (int j = 0; j < N2; j++) - T[j] = Tensor1 (data[j]); - } + /* construct from data */ + Tensor2(const double data[N2][N1]) { + for (int j = 0; j < N2; j++) + T[j] = Tensor1 (data[j]); + } - /** construct from expression */ - template - Tensor2(const Tensor2Expression , Index >& a) { - for (int j = 0; j < N2; j++) - T[j] = a(j); - } + /** construct from expression */ + template + Tensor2(const Tensor2Expression , Index >& a) { + for (int j = 0; j < N2; j++) + T[j] = a(j); + } - double operator()(int i, int j) const { - return T[j](i); - } + const double & operator()(int i, int j) const { + return T[j](i); + } - /** convert to expression */ - template Tensor2Expression , Index< - N2, J> > operator()(Index i, Index j) const { - return Tensor2Expression , Index > (*this); - } - }; + double & operator()(int i, int j) { + return T[j](i); + } + + /** convert to expression */ + template Tensor2Expression , Index< + N2, J> > operator()(Index i, Index j) const { + return Tensor2Expression , Index > (*this); + } +}; } // namespace tensors