From 40e8a19dc6f96af6d946251071ac419e3fc2c0d4 Mon Sep 17 00:00:00 2001 From: Ed J Date: Fri, 20 Dec 2024 19:01:11 +0000 Subject: [PATCH] fix types, machine_epsilon() - https://github.com/PDLPorters/pdl/issues/511 --- lib/Photonic/Roles/Reorthogonalize.pm | 4 +-- t/field-lenr2.t | 35 ++++++++++++++------------- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/lib/Photonic/Roles/Reorthogonalize.pm b/lib/Photonic/Roles/Reorthogonalize.pm index 777a2405..14c3a311 100644 --- a/lib/Photonic/Roles/Reorthogonalize.pm +++ b/lib/Photonic/Roles/Reorthogonalize.pm @@ -187,8 +187,8 @@ sub _checkorthogonalize { return 0 if $self->fullorthogonalize_N; #already orthogonalizing if ($self->_justorthogonalized) { $self->_write_justorthogonalized(0); - my $current_W=PDL->ones($n)*$self->noise; - my $next_W=PDL->ones($n+1)*$self->noise; + my $current_W=PDL->ones($g_n->type, $n)*$self->noise; + my $next_W=PDL->ones($g_np1->type, $n+1)*$self->noise; $current_W->(-1).=$g_n; $next_W->(-1).=$g_np1; $self->_current_W($current_W); diff --git a/t/field-lenr2.t b/t/field-lenr2.t index 2cd5c167..f09d5dd9 100644 --- a/t/field-lenr2.t +++ b/t/field-lenr2.t @@ -40,6 +40,7 @@ use Photonic::LE::NR2::SHChiTensor; use Test::More; use lib 't/lib'; use TestUtils; +use Machine::Epsilon; my $ea=1+2*i; my $eb=3+4*i; @@ -364,46 +365,46 @@ $expected = pdl(<<'EOF'); [ -0.014991596+0.011757369i ] ] EOF -ok(Cagree($got, $expected, 1e-18), "SHChiTensor SHPs P2") or diag "got: $got\nexpected: $expected"; +ok(Cagree($got, $expected, machine_epsilon()), "SHChiTensor SHPs P2") or diag "got: $got\nexpected: $expected"; $got = $chi->evaluate; $expected = pdl(<<'EOF'); -[ [ [ 2.06087e-17+3.64698e-17i ] ] ] +[ [ [ 0 ] ] ] EOF -ok(Cagree($got, $expected, 1e-41), "P2") or diag "got: $got\nexpected: $expected"; +ok(Cagree($got, $expected, machine_epsilon()), "P2") or diag "got: $got\nexpected: $expected"; $got = $chi->evaluate(kind => 'f', mask => pdl(1)); $expected = pdl(<<'EOF'); -[ [ [ 4.0239976e-18-9.855343e-19i ] ] ] +[ [ [ 0 ] ] ] EOF -ok(Cagree($got, $expected, 1e-50), "P2") or diag "got: $got\nexpected: $expected"; +ok(Cagree($got, $expected, machine_epsilon()), "P2") or diag "got: $got\nexpected: $expected"; $got = $chi->evaluate(kind => 'l'); $expected = pdl(<<'EOF'); -[ [ [ 1.4979937e-18+3.6442788e-18i ] ] ] +[ [ [ 0 ] ] ] EOF -ok(Cagree($got, $expected, 1e-51), "selfConsistentVecL") or diag "got: $got\nexpected: $expected"; +ok(Cagree($got, $expected, machine_epsilon()), "selfConsistentVecL") or diag "got: $got\nexpected: $expected"; $got = $chi->evaluate(kind => 'a'); $expected = pdl(<<'EOF'); -[ [ [ -4.890401e-16+5.6504395e-16i ] ] ] +[ [ [ 0 ] ] ] EOF -ok(Cagree($got, $expected, 1e-47), "P2LMCalt") or diag "got: $got\nexpected: $expected"; +ok(Cagree($got, $expected, machine_epsilon()), "P2LMCalt") or diag "got: $got\nexpected: $expected"; $got = $chi->evaluate(kind => 'd'); $expected = pdl(<<'EOF'); -[ [ [ 5.0464683e-18+2.5232341e-18i ] ] ] +[ [ [ 0 ] ] ] EOF -ok(Cagree($got, $expected, 1e-50), "dipolar") or diag "got: $got\nexpected: $expected"; +ok(Cagree($got, $expected, machine_epsilon()), "dipolar") or diag "got: $got\nexpected: $expected"; $got = $chi->evaluate(kind => 'q'); $expected = pdl(<<'EOF'); -[ [ [ 1.5770213e-19+3.1540427e-19i ] ] ] +[ [ [ 0 ] ] ] EOF -ok(Cagree($got, $expected, 1e-50), "quadrupolar") or diag "got: $got\nexpected: $expected"; +ok(Cagree($got, $expected, machine_epsilon()), "quadrupolar") or diag "got: $got\nexpected: $expected"; $got = $chi->evaluate(kind => 'e'); $expected = pdl(<<'EOF'); -[ [ [ 9.9352345e-18+1.5770213e-18i ] ] ] +[ [ [ 0 ] ] ] EOF -ok(Cagree($got, $expected, 1e-50), "external") or diag "got: $got\nexpected: $expected"; +ok(Cagree($got, $expected, machine_epsilon()), "external") or diag "got: $got\nexpected: $expected"; $got = $chi->evaluate(kind => 'el'); $expected = pdl(<<'EOF'); -[ [ [ 7.2542982e-18+1.4193192e-18i ] ] ] +[ [ [ 0 ] ] ] EOF -ok(Cagree($got, $expected, 1e-50), "externalVecL") or diag "got: $got\nexpected: $expected"; +ok(Cagree($got, $expected, machine_epsilon()), "externalVecL") or diag "got: $got\nexpected: $expected"; done_testing;