Hi Ingo,

The most surgical way to achieve this would be something like this, in your 
calling code:

{
    local $SIG{__WARN__} = sub {
        my $warn = shift;
        return if $warn =~ /PDL::Primitive::conv1d does not handle bad values 
at/;
        warn $warn;
    };
    # conv1d stuff
}

The most correct solution would be to fix conv1d so that it does actually 
handle BAD values. I did this with matmult not long ago, since having upgraded 
the warning to a real Perl warning made the PDL::Transform tests annoyingly 
noisy without that. Take a look at the current matmult for inspiration - it 
took a matter of minutes :-)

Best regards,
Ed
________________________________
From: Ingo Schmid via pdl-general <[email protected]>
Sent: 16 October 2025 13:43
To: perldl <[email protected]>
Subject: [Pdl-general] Fwd: turn off warnings



Hi,

may thanks!

I've placed this in the respective module, which does the job. But I guess it 
is not local?


BEGIN {
    $SIG{__WARN__} = sub {
        my $warn = shift;
        return if $warn =~ /PDL::Primitive::conv1d does not handle bad values 
at/;
        warn $warn;
    };
}

Ingo

On 16.10.25 2:29 PM, David Mertens wrote:
There is an official way for a module to establish warnings that callers can 
enable or disable using warnings::register (see 
https://perldoc.perl.org/warnings#Reporting-Warnings-from-a-Module). I don't 
think PDL has done this.

The other approach is to set a warnings handler. brian d foy covers that in an 
article about overriding warnings 
(https://www.effectiveperlprogramming.com/2011/09/intercept-module-warnings-with-a-warn-handler/).
 You will almost certainly want to use the "local" override since that'll be 
reset after you exit the current block, just like a lexically scoped "no 
'warnings'" statement.

David

 "Debugging is twice as hard as writing the code in the first place.
  Therefore, if you write the code as cleverly as possible, you are,
  by definition, not smart enough to debug it." -- Brian Kernighan

On Thu, Oct 16, 2025, 6:43 AM Ingo Schmid via pdl-general 
<[email protected]<mailto:[email protected]>> 
wrote:

Hi,

in my code, I use conv1d (PDL::Primitive) a lot, which generates a BAD values 
warning every time. Is there a way to suppress this selectively?

Thanks

Ingo

_______________________________________________
pdl-general mailing list
[email protected]<mailto:[email protected]>
https://lists.sourceforge.net/lists/listinfo/pdl-general
_______________________________________________
pdl-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pdl-general

Reply via email to