If it works, it works. But a few comments:

1) The BEGIN block wrapper is unnecessary here. Just put it somewhere near
the top of your code, before you invoke conv1d.
2) If your use of conv1d is inside a block, you can preface the hash
assignment with "local" and your override will be discarded when your code
exits the block. (Note: you can do this for any hash assignment, even with
entries of hashes declared as "my %hash".) This makes the override
lexically scoped, minimizing action-at-a-distance and the extraordinary
confusion it can cause. I'm thinking about a student who sees this
technique, then applies it wantonly in their own code to suppress unwanted
warnings, unwittingly and silently suppressing useful warnings and making
the debug process 5x harder than it should be.

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, 8:43 AM Ingo Schmid via pdl-general <
[email protected]> wrote:

>
> 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]> 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]
>> https://lists.sourceforge.net/lists/listinfo/pdl-general
>>
> _______________________________________________
> pdl-general mailing list
> [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