Skip to content

Commit

Permalink
add Pars type-spec "!real" - #511
Browse files Browse the repository at this point in the history
  • Loading branch information
mohawk2 committed Jan 6, 2025
1 parent f419bef commit 4977f0d
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
- separate PDL::Type POD documentation
- partly restoring pre-2.096 xform type-selection: if xform given no typed outputs, and non-available (greater than last-given type) typed inputs, use last-given (#511, https://github.com/moocow-the-bovine/PDL-CCS/issues/18)
- fix Math::polyroots with native-complex input and supplied null output
- add Pars type-spec "!real" which makes it an error to supply real values (#511)

2.098 2025-01-03
- fix Windows build problems
Expand Down
4 changes: 4 additions & 0 deletions lib/PDL/Core/pdlapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -1126,6 +1126,10 @@ static inline pdl_error pdl__transtype_select(
continue;
short flags = vtable->par_flags[i];
pdl_datatypes dtype = pdl->datatype;
if (flags & PDL_PARAM_ISNOTREAL && dtype < PDL_CF)
return pdl_make_error(PDL_EUSERERROR,
"%s: ndarray %s must be complex, but is type %s",
vtable->name, vtable->par_names[i], PDL_TYPENAME(dtype));
if (flags & PDL_PARAM_ISNOTCOMPLEX && dtype >= PDL_CF)
return pdl_make_error(PDL_EUSERERROR,
"%s: ndarray %s must be real, but is type %s",
Expand Down
3 changes: 3 additions & 0 deletions lib/PDL/PP.pod
Original file line number Diff line number Diff line change
Expand Up @@ -912,6 +912,9 @@ and C<Doc> omitted):
As of 2.096, there is also a C<!complex> type, which means if a
complex-valued ndarray is supplied to the operation, an error will
be thrown. In the normal case, its type will be as if C<real> were given.
As of 2.099, there is further a C<!real> type, which is the opposite
of the above; the idea is to protect a user who e.g. through a bug
supplied a real ndarray to L<PDL::Ops/im>.

Finally, there are the C<type+> qualifiers. Let's illustrate the C<int+>
qualifier with the actual definition of sumover:
Expand Down
4 changes: 3 additions & 1 deletion lib/PDL/PP/PdlParObj.pm
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ our %INVALID_PAR = map +($_=>1), qw(
);

my $typeregex = join '|', map $_->ppforcetype, types;
my $complex_regex = join '|', qw(real complex !complex);
my $complex_regex = join '|', qw(real complex !real !complex);
our $sqbr_re = qr/\[([^]]*)\]/x;
our $pars_re = qr/^
\s*(?:($complex_regex|$typeregex)\b([+]*)|)\s* # $1,2: first option then plus
Expand All @@ -28,12 +28,14 @@ my %flag2info = (
phys => [[qw(FlagPhys)]],
real => [[qw(FlagTypeOverride FlagReal)]],
complex => [[qw(FlagTypeOverride FlagComplex)]],
'!real' => [[qw(FlagTypeOverride FlagNotReal)]],
'!complex' => [[qw(FlagTypeOverride FlagNotComplex)]],
(map +($_->ppforcetype => [[qw(FlagTypeOverride FlagTyped)], 'Type']), types),
);
my %flag2c = qw(
FlagReal PDL_PARAM_ISREAL
FlagComplex PDL_PARAM_ISCOMPLEX
FlagNotReal PDL_PARAM_ISNOTREAL
FlagNotComplex PDL_PARAM_ISNOTCOMPLEX
FlagTyped PDL_PARAM_ISTYPED
FlagTplus PDL_PARAM_ISTPLUS
Expand Down

0 comments on commit 4977f0d

Please sign in to comment.