Skip to content

Commit

Permalink
Merge pull request #71 from SpM-lab/terasaki/augment-deriv
Browse files Browse the repository at this point in the history
Augment deriv
  • Loading branch information
terasakisatoshi authored Dec 24, 2024
2 parents 8f86cdd + dc85740 commit 0e3fb11
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 13 deletions.
2 changes: 1 addition & 1 deletion include/sparseir/augment.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class TauConst : public AbstractAugmentation {
}

std::complex<double> operator()(MatsubaraFreq<Fermionic> n) const override {
std::invalid_argument("TauConst is not a Fermionic basis.");
throw std::invalid_argument("TauConst is not a Fermionic basis.");
return std::numeric_limits<std::complex<double>>::quiet_NaN();
}

Expand Down
41 changes: 29 additions & 12 deletions test/augment.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,19 @@ TEST_CASE("SparseIR Basis Functions", "[SparseIR]")
REQUIRE_THROWS_AS(tc(321), std::domain_error);

REQUIRE(tc(100) == 1 / std::sqrt(123));
//REQUIRE(tc(MatsubaraFreq(0)) == std::sqrt(123));
//REQUIRE(tc(MatsubaraFreq(92)) == 0.0);
//REQUIRE_THROWS_AS(tc(MatsubaraFreq(93)), std::runtime_error);

//REQUIRE(sparseir::deriv(tc)(4.2) == 0.0);
//REQUIRE(sparseir::deriv(tc, 0) == tc);
MatsubaraFreq<Bosonic> freq0(0);
MatsubaraFreq<Bosonic> freq92(92);
REQUIRE(tc(freq0) == std::sqrt(123));
REQUIRE(tc(freq92) == 0.0);
MatsubaraFreq<Fermionic> freq93(93);
REQUIRE_THROWS_AS(tc(freq93), std::invalid_argument);
auto tdc = tc.deriv();
REQUIRE(tdc(4.2) == 0.0);

tdc = tc.deriv(0);
double x = 4.2;
// Expected tdc == tc
REQUIRE(tdc(x) == tc(x));
}

SECTION("TauLinear")
Expand Down Expand Up @@ -67,10 +74,14 @@ TEST_CASE("SparseIR Basis Functions", "[SparseIR]")
MatsubaraFreq<Fermionic> freq93(93);
REQUIRE_THROWS_AS(tl(freq93), std::invalid_argument);

//REQUIRE(sparseir::deriv(tl, 0) == tl);
//REQUIRE(sparseir::deriv(tl)(4.2) ==
// Approx(std::sqrt(3 / 123) * 2 / 123));
//REQUIRE(sparseir::deriv(tl, 2)(4.2) == Approx(0.0));
double x = 4.2;
auto d0tl = tl.deriv(0);
REQUIRE(d0tl(x) == tl(x));
auto dtl = tl.deriv();
REQUIRE(dtl(4.2) ==
Approx(std::sqrt(3. / 123.) * 2. / 123.));
auto ddtl = tl.deriv(2);
REQUIRE(ddtl(4.2) == 0.0);
}

SECTION("MatsubaraConst")
Expand All @@ -91,8 +102,14 @@ TEST_CASE("SparseIR Basis Functions", "[SparseIR]")
MatsubaraFreq<Fermionic> freq93(93);
REQUIRE(mc(freq93) == 1.0);

//REQUIRE(sparseir::deriv(mc) == mc);
//REQUIRE(sparseir::deriv(mc, 0) == mc);
auto d0mc = mc.deriv(0);
auto dmc = mc.deriv();
double x = 4.2;
// Expected dmc == mc
REQUIRE(std::isnan(d0mc(x)));
REQUIRE(std::isnan(mc(x)));
REQUIRE(std::isnan(dmc(x)));
REQUIRE(std::isnan(mc(x)));
}
}

Expand Down

0 comments on commit 0e3fb11

Please sign in to comment.