File matrixmatrixmultiplytrace.h
File List > algebra > matrix3x3algebra > matrixmatrixmultiplytrace.h
Go to the documentation of this file
#ifndef COSMOINTERFACE_MATRIX3X3ALGEBRA_MATRIXMATRIXMULTIPLYTRACE_H
#define COSMOINTERFACE_MATRIX3X3ALGEBRA_MATRIXMATRIXMULTIPLYTRACE_H
/* This file is part of TempLat, available at https://cosmolattice.github.io/templat .
Copyright 2021-2026 The TempLat authors, see AUTHORS.md.
Released under the MIT license, see LICENSE.md. */
// File info: Main contributor(s): Jorge Baeza-Ballesteros, Year: 2026
#include "TempLat/lattice/algebra/operators/power.h"
#include "TempLat/lattice/algebra/operators/multiply.h"
#include "TempLat/lattice/algebra/operators/subtract.h"
#include "TempLat/lattice/algebra/matrix3x3algebra/allmatrixcomponents.h"
namespace TempLat
{
template <class R, class T> class MatrixMatrixMultiplicationTrace : public TempLat::BinaryOperator<R, T>
{
public:
// Put public methods here. These should change very little over time.
using TempLat::BinaryOperator<R, T>::mR;
using TempLat::BinaryOperator<R, T>::mT;
MatrixMatrixMultiplicationTrace(const R &pR, const T &pT) : TempLat::BinaryOperator<R, T>(pR, pT) {}
auto Get() const
{
return getComponent(mR, 1_c, 1_c) * getComponent(mT, 1_c, 1_c) +
getComponent(mR, 1_c, 2_c) * getComponent(mT, 2_c, 1_c) +
getComponent(mR, 1_c, 3_c) * getComponent(mT, 3_c, 1_c) +
getComponent(mR, 2_c, 1_c) * getComponent(mT, 1_c, 2_c) +
getComponent(mR, 2_c, 2_c) * getComponent(mT, 2_c, 2_c) +
getComponent(mR, 2_c, 3_c) * getComponent(mT, 3_c, 2_c) +
getComponent(mR, 3_c, 1_c) * getComponent(mT, 1_c, 3_c) +
getComponent(mR, 3_c, 2_c) * getComponent(mT, 2_c, 3_c) +
getComponent(mR, 3_c, 3_c) * getComponent(mT, 3_c, 3_c);
}
template <typename... IDX>
requires requires(std::decay_t<R> r, std::decay_t<T> t, IDX... idx) {
requires IsVariadicIndex<IDX...>;
DoEval::eval(r, idx...);
DoEval::eval(t, idx...);
}
DEVICE_INLINE_FUNCTION auto eval(const IDX &...idx) const
{
auto cL = DoEval::eval(mR, idx...);
auto cR = DoEval::eval(mT, idx...);
return cL[0] * cR[0] + cL[1] * cR[3] + cL[2] * cR[6] + cL[3] * cR[1] + cL[4] * cR[4] + cL[5] * cR[7] +
cL[6] * cR[2] + cL[7] * cR[5] + cL[8] * cR[8];
}
virtual std::string operatorString() const override { return "*"; }
};
template <typename R, typename T>
requires(HasMatrixGet<R> && HasMatrixGet<T>)
auto multiplyTrace(const R &r, const T &t)
{
return MatrixMatrixMultiplicationTrace<R, T>(r, t);
}
} // namespace TempLat
#endif