#ifndef STIM_TENSOR2_H #define STIM_TENSOR2_H #include "matrix_sym.h" namespace stim { /*This class represents a symmetric rank-2 2D tensor, useful for structure tensors */ template class tensor2 : public matrix_sym { protected: public: //calculate the eigenvectors and eigenvalues of the tensor CUDA_CALLABLE void eig(stim::matrix& v, stim::matrix& lambda) { lambda = 0; //initialize the eigenvalue matrix to zero T t = M[0] + M[2]; //calculate the trace of the tensor T d = M[0] * M[2] - M[1] * M[1]; //calculate the determinant of the tensor lambda(0, 0) = t / 2 + sqrt(t*t / 4 - d); lambda(1, 1) = t / 2 - sqrt(t*t / 4 - d); if (M[1] == 0) { v = stim::matrix::identity(); } else { v(0, 0) = lambda(0, 0) - d; v(0, 1) = lambda(1, 1) - d; v(1, 0) = v(1, 1) = M[1]; } } CUDA_CALLABLE tensor2 operator=(stim::matrix_sym rhs){ stim::matrix_sym::operator=(rhs); return *this; } }; } //end namespace stim #endif