<commit_before>// Copyright (c) 2010, Lawrence Livermore National Security, LLC. Produced at
// the Lawrence Livermore National Laboratory. LLNL-CODE-443211. All Rights
// reserved. See file COPYRIGHT for details.
//
// This file is part of the MFEM library. For more information and source code
// availability see http://mfem.org.
//
// MFEM is free software; you can redistribute it and/or modify it under the
// terms of the GNU Lesser General Public License (as published by the Free
// Software Foundation) version 2.1 dated February 1999.

#include "mfem.hpp"
#include "catch.hpp"

using namespace mfem;

TEST_CASE( "DenseMatrix LinearSolve methods",
           "[DenseMatrix]" )
{
  SECTION( "singular_system" )
  {
    constexpr int N = 3;

    DenseMatrix A( N );
    A.SetRow( 0, 0.0 );
    A.SetRow( 1, 0.0 );
    A.SetRow( 2, 0.0 );

    double X[3];

    int rc = LinearSolve( A, X );
    REQUIRE( rc < 0 );
  }

  SECTION( "1x1_system" )
  {
    constexpr int N = 1;
    DenseMatrix A(N);
    A(0,0) = 2;

    double X[ 1 ] = { 12 };

    int rc = LinearSolve( A, X );
    REQUIRE( rc==0 );
    REQUIRE( X[0] == Approx(6) );
  }

  SECTION( "2x2_system" )
  {
    constexpr int N = 2;

    DenseMatrix A( N );
    A(0,0)=2. ; A(0,1)=1.;
    A(1,0)=3. ; A(1,1)=4.;

    double X[ 2 ] = { 1, 14 };

    int rc = LinearSolve( A, X );

    REQUIRE( rc==0 );
    REQUIRE( X[0] == Approx(-2) );
    REQUIRE( X[1] == Approx(5) );
  }

  SECTION( "3x3_system" )
  {
    constexpr int N = 3;

    DenseMatrix A( N );
    A( 0,0 )=4; A( 0,1 )=5; A( 0,2 )=-2;
    A( 1,0 )=7; A( 1,1 )=-1; A( 1,2 )= 2;
    A( 2,0 )=3; A( 2,1 )=1; A( 2,2 )= 4;

    double X[ 3 ] = { -14, 42, 28 };

    int rc = LinearSolve( A, X );

    REQUIRE( rc==0 );
    REQUIRE( X[0] == Approx(4)  );
    REQUIRE( X[1] == Approx(-4) );
    REQUIRE( X[2] == Approx(5) );
  }

}

TEST_CASE("DenseMatrix A*B^T methods",
          "[DenseMatrix]")
{
   double tol = 1e-12;
<commit_msg>STYLE: fix format<commit_after>// Copyright (c) 2010, Lawrence Livermore National Security, LLC. Produced at
// the Lawrence Livermore National Laboratory. LLNL-CODE-443211. All Rights
// reserved. See file COPYRIGHT for details.
//
// This file is part of the MFEM library. For more information and source code
// availability see http://mfem.org.
//
// MFEM is free software; you can redistribute it and/or modify it under the
// terms of the GNU Lesser General Public License (as published by the Free
// Software Foundation) version 2.1 dated February 1999.

#include "mfem.hpp"
#include "catch.hpp"

using namespace mfem;

TEST_CASE( "DenseMatrix LinearSolve methods",
           "[DenseMatrix]" )
{
   SECTION( "singular_system" )
   {
      constexpr int N = 3;

      DenseMatrix A( N );
      A.SetRow( 0, 0.0 );
      A.SetRow( 1, 0.0 );
      A.SetRow( 2, 0.0 );

      double X[3];

      int rc = LinearSolve( A, X );
      REQUIRE( rc < 0 );
   }

   SECTION( "1x1_system" )
   {
      constexpr int N = 1;
      DenseMatrix A(N);
      A(0,0) = 2;

      double X[ 1 ] = { 12 };

      int rc = LinearSolve( A, X );
      REQUIRE( rc==0 );
      REQUIRE( X[0] == Approx(6) );
   }

   SECTION( "2x2_system" )
   {
      constexpr int N = 2;

      DenseMatrix A( N );
      A(0,0)=2. ; A(0,1)=1.;
      A(1,0)=3. ; A(1,1)=4.;

      double X[ 2 ] = { 1, 14 };

      int rc = LinearSolve( A, X );

      REQUIRE( rc==0 );
      REQUIRE( X[0] == Approx(-2) );
      REQUIRE( X[1] == Approx(5) );
   }

   SECTION( "3x3_system" )
   {
      constexpr int N = 3;

      DenseMatrix A( N );
      A( 0,0 )=4; A( 0,1 )=5; A( 0,2 )=-2;
      A( 1,0 )=7; A( 1,1 )=-1; A( 1,2 )= 2;
      A( 2,0 )=3; A( 2,1 )=1; A( 2,2 )= 4;

      double X[ 3 ] = { -14, 42, 28 };

      int rc = LinearSolve( A, X );

      REQUIRE( rc==0 );
      REQUIRE( X[0] == Approx(4)  );
      REQUIRE( X[1] == Approx(-4) );
      REQUIRE( X[2] == Approx(5) );
   }

}

TEST_CASE("DenseMatrix A*B^T methods",
          "[DenseMatrix]")
{
   double tol = 1e-12;

{'fraction_non_alphanumeric': 0.16966516741629187, 'fraction_numerical': 0.05547226386806597, 'mean_word_length': 2.2360549717057396, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3504924', 'n_tokens_mistral': 1760, 'n_tokens_neox': 1578, 'n_words': 472}