From 996baab0edd9237d56709b3ac1fb8e44bc575ed5 Mon Sep 17 00:00:00 2001 From: Ed J Date: Thu, 26 Dec 2024 05:55:25 +0000 Subject: [PATCH] use boolean vector to see what types an xform supports - #511 --- lib/PDL/Core/pdlapi.c | 15 ++++++--------- lib/PDL/IO/Misc.pd | 2 +- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/lib/PDL/Core/pdlapi.c b/lib/PDL/Core/pdlapi.c index 8a041b6fe..b543459f5 100644 --- a/lib/PDL/Core/pdlapi.c +++ b/lib/PDL/Core/pdlapi.c @@ -1090,7 +1090,6 @@ static inline pdl_error pdl__transtype_select( ) { pdl_error PDL_err = {0, NULL, 0}; *retval = PDL_INVALID; - pdl_datatypes last_dtype = PDL_INVALID; PDL_Indx i; pdl_transvtable *vtable = trans->vtable; for (i=0; inpdls; i++) { @@ -1104,8 +1103,11 @@ static inline pdl_error pdl__transtype_select( "%s: ndarray %s must be real, but is type %s", vtable->name, vtable->par_names[i], PDL_TYPENAME(dtype)); } - if (vtable->gentypes[0] != PDL_INVALID && - vtable->gentypes[1] == PDL_INVALID) { + char type_avail[PDL.ntypes]; for (i=0; igentypes[i]!=-1; i++) + type_avail[last_dtype = vtable->gentypes[i]] = 1; + if (vtable->gentypes[0] == last_dtype) { *retval = vtable->gentypes[0]; /* only one allowed type, use that */ return PDL_err; } @@ -1130,12 +1132,7 @@ static inline pdl_error pdl__transtype_select( )) *retval = new_transtype; } - for (i=0; vtable->gentypes[i]!=-1; i++) { - last_dtype = vtable->gentypes[i]; - if (*retval != last_dtype) continue; - return PDL_err; - } - *retval = last_dtype; + if (*retval == PDL_INVALID || !type_avail[*retval]) *retval = last_dtype; return PDL_err; } diff --git a/lib/PDL/IO/Misc.pd b/lib/PDL/IO/Misc.pd index 97ef8a7f5..8c6b3124a 100644 --- a/lib/PDL/IO/Misc.pd +++ b/lib/PDL/IO/Misc.pd @@ -1016,7 +1016,7 @@ sub PDL::swcols{ The default value is to assign C<$PDL::undefval> to undefined values, but if C is set this is used instead. This would normally be set to a number, but if it is set to C and PDL is compiled - with Badvalue support (see L) then undefined values are set to + with Badvalue support (see L) then undefined values are set to the appropriate badvalue and the column is marked as bad. DEFTYPE: Sets the default type of the columns - see the documentation for