/* * Tensor3.h * @brief Rank 3 tensors based on http://www.gps.caltech.edu/~walter/FTensor/FTensor.pdf * Created on: Feb 10, 2010 * @author: Frank Dellaert */ #pragma once #include "tensors.h" namespace tensors { /** Rank 3 Tensor */ template class Tensor3 { Tensor2 T[N3]; public: /** default constructor */ Tensor3() { } /** construct from data */ Tensor3(const double data[N3][N2][N1]) { for (int k = 0; k < N3; k++) T[k] = data[k]; } /** construct from expression */ template Tensor3(const Tensor3Expression , Index , Index >& a) { for (int k = 0; k < N3; k++) T[k] = a(k); } double operator()(int i, int j, int k) const { return T[k](i, j); } /** convert to expression */ template Tensor3Expression , Index , Index > operator()(const Index& i, const Index& j, const Index& k) { return Tensor3Expression , Index , Index > (*this); } }; // Tensor3 /** Rank 3 permutation tensor */ struct Eta3 { /** calculate value. TODO: wasteful to actually use this */ double operator()(int i, int j, int k) const { return ((j - i) * (k - i) * (k - j)) / 2; } /** create expression */ template Tensor3Expression , Index<3, J> , Index<3, K> > operator()(const Index<3, I>& i, const Index<3, J>& j, const Index<3, K>& k) const { return Tensor3Expression , Index<3, J> , Index<3, K> > ( *this); } }; // Eta } // namespace tensors