File: DenseSymMatProd.cpp

package info (click to toggle)
spectra 1.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,788 kB
  • sloc: cpp: 23,044; ansic: 175; fortran: 131; makefile: 90
file content (29 lines) | stat: -rw-r--r-- 909 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <Eigen/Core>
#include <Spectra/MatOp/DenseSymMatProd.h>

#include "catch.hpp"

using namespace Spectra;

template <typename TestType>
using Matrix = Eigen::Matrix<TestType, Eigen::Dynamic, Eigen::Dynamic>;
using Eigen::Index;

TEMPLATE_TEST_CASE("matrix operations", "[DenseSymMatProd]", float, double)
{
    std::srand(123);
    constexpr Index n = 100;

    Matrix<TestType> mat = Matrix<TestType>::Random(n, n);
    Matrix<TestType> mat1 = mat + mat.transpose();  // It needs to be symetric
    Matrix<TestType> mat2 = Matrix<TestType>::Random(n, n);

    DenseSymMatProd<TestType> dense1(mat1);
    Matrix<TestType> xs = dense1 * mat2;
    Matrix<TestType> ys = mat1 * mat2;

    INFO("The matrix-matrix product must be the same as in eigen.")
    REQUIRE(xs.isApprox(ys));
    INFO("The accesor operator must produce the same element as in eigen")
    REQUIRE(mat1(15, 23) == dense1(23, 15));
}