Repository navigation
Fix wrapper input handling (NumPy arrays, MATLAB row/column vectors, mexAll GSL paths); add CI and wrapper tests; drop Python 2 - #21
Merged
Conversation
Python 2 has been end-of-life since 2020, and Ben decided to drop it (#19). Python/setup.py was its only build script and the only user of Python/catchaMouse16_wrap.c, so both go; setup_P3.py remains the build script. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The single-feature functions raised SystemError for NumPy arrays and for non-numeric items (#15): the C wrapper accepted only lists and tuples, returned NULL without setting an exception for anything else, and ignored PyFloat_AsDouble errors, so a bad item became -1 with a pending exception. The wrapper now reads float64 buffers (e.g., NumPy arrays) directly and converts any other one-dimensional sequence or iterable element by element, raising TypeError for strings, multi-dimensional arrays and non-numeric items. An empty series gives NaN instead of z-scoring zero values. It uses PyMem_Malloc with error checks and drops a redundant copy of the input and the unused int-valued wrapper. catchaMouse16_all passed list(data) to each feature, which for a NumPy array is a list of NumPy scalars; it now passes sequences through, and reads only one-shot iterators (generators) into a list. setup_P3.py imports setuptools instead of distutils (removed from the standard library in Python 3.12), and adds GSL's include and library folders from gsl-config when it is available, so Homebrew and conda installs build without setting CFLAGS or LDFLAGS. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
catchaMouse16_all transposed its input, so it failed on a column vector
("Input must be a column vector."), while the single-feature MEX functions
failed on a row vector (#15). The MEX wrapper now accepts any vector (the
data are contiguous either way) and returns NaN for an empty input, and
catchaMouse16_all passes data(:) after checking the input is a real vector.
mexAll hard-coded -I/usr/local/include and -L/usr/local/lib, which fails
for Apple-silicon Homebrew (/opt/homebrew) and conda installs. It is now a
function that takes an optional GSL install prefix and otherwise uses
gsl-config (also looked for in CONDA_PREFIX and the Homebrew bin folders,
since MATLAB's PATH often lacks them), then /opt/homebrew, /usr/local and
/usr. It adds an rpath for GSL's library folder so conda's @rpath libraries
load, works from any folder, writes the MEX files next to itself, and no
longer compiles the command-line program's main.c into every MEX file.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Nothing ran the C value checks from #3 automatically, the Python test only printed values (picking features via dir()[:16]), and MATLAB had no test (#14). The GitHub Actions workflow runs make test in C/ with gcc and clang on Ubuntu and clang on macOS (the FFT bug fixed in #2 was GCC-only), with GSL from apt or Homebrew. It passes only CC to make, so it doesn't depend on the Makefile's warning flags. It also builds and installs the Python extension with setup_P3.py, as the README says, and runs the Python tests on Ubuntu (Python 3.9 and 3.13) and macOS. Python/test_features.py now asserts the hctsa v1.03 reference values from C/tests/test_features.c (test_ts.csv and the C test series), with the same tolerance, and checks the input handling: NumPy arrays, lists, tuples and generators give identical values, bad input raises TypeError, and N = 8 and empty series give NaN rather than a crash. It runs with pytest or as a script. Matlab/test_catchaMouse16.m checks the same reference values for row and column vectors, catchaMouse16_all, short and empty series, and bad input. It needs a MATLAB licence, so it is not in CI. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The Python features now take NumPy arrays, the MATLAB functions take row or column vectors, mexAll finds GSL itself, the Python 2 build is gone, and the Python build needs setuptools rather than distutils. Remove the workarounds the README described for the old behavior and mention the test scripts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes the wrapper input handling found in the October 2026 correctness audit (#3, finding 14, and #4's "Code issues found"), adds the repo's first CI, and turns the Python test into real value checks, with a matching MATLAB test (#3, finding 13). The Python single-feature functions now accept NumPy arrays and any other sequence of numbers and raise
TypeErrorfor anything else, instead ofSystemError. The MATLAB functions accept row or column vectors, andmexAllfinds GSL itself instead of assuming/usr/local. As decided in #19, it also drops the Python 2 build.No feature values change: the wrappers call the same C functions on the same z-scored data. This PR does not touch
C/srcorC/Makefile, and the README diff is limited to the usage notes these fixes make obsolete.Closes #14
Closes #15
Part of #19 (Python 2 only; packaging and the Twitter badge are still open)
Fixed
SystemErrorfor NumPy arrays and non-numeric input (Wrapper input handling: MATLAB column vectors, mexAll GSL paths, Python NumPy arrays #15).Python/catchaMouse16_wrap_P3.caccepted only lists and tuples. For anything else it returnedNULLwithout setting an exception, and it ignoredPyFloat_AsDoubleerrors, so a non-numeric item became −1 with a pending exception; both surfaced asSystemError. The wrapper now copies float64 buffers (such as NumPy arrays, including non-contiguous ones) directly and converts any other one-dimensional sequence or iterable element by element. Strings, bytes, multi-dimensional arrays, scalars and non-numeric items raiseTypeErrorwith a message that names the bad element, for example "expected a sequence of numbers, but element 2 is str". An empty series gives NaN instead of z-scoring zero values. Memory comes fromPyMem_Mallocwith error checks; the redundant second copy of the input and the unused int-valued wrapper are gone. Memory use stays flat over 180,000 calls, including calls that raise.catchaMouse16_all. It calledlist(data), which for a NumPy array gives a list of NumPy scalars, so it worked, but each of the 16 features then converted those objects one by one. It now passes sequences and arrays straight through, and reads only one-shot iterators (such as generators) into a list. Bad input raises the sameTypeError.setup_P3.pyimportssetuptoolsrather thandistutils, which was removed from the standard library in Python 3.12. Whengsl-configis on the PATH, it adds GSL's include and library folders (with an rpath), so Homebrew and conda installs build without settingCFLAGSorLDFLAGS. The documentedpython3 setup_P3.py buildtheninstallstill works (checked with setuptools 84).Python/setup.pyand the Python 2 wrapperPython/catchaMouse16_wrap.c, which onlysetup.pyused, are removed. I kept the namesetup_P3.pybecause the GitBook install instructions use it.catchaMouse16_allpasseddata'to the MEX functions, which required a column vector, so it failed on a column vector and the single features failed on a row vector. The MEX wrapper (Matlab/M_wrapper.c) now accepts any vector, since the data are contiguous either way, and returns NaN for an empty input.catchaMouse16_allchecks that its input is a real vector and passesdouble(data(:)). A matrix still raises an error, now with the IDcatchaMouse16:notVector.mexAllGSL paths (Wrapper input handling: MATLAB column vectors, mexAll GSL paths, Python NumPy arrays #15).mexAllhard-coded-I/usr/local/includeand-L/usr/local/lib, which fails for Apple-silicon Homebrew and conda installs. It is now a function.mexAll(prefix)usesprefix/includeandprefix/lib. PlainmexAllusesgsl-config, also looking in$CONDA_PREFIX/binand Homebrew's bin folders because MATLAB's PATH often lacks them, then falls back to/opt/homebrew,/usr/localand/usr. If GSL is not found, it gives a clear error. It adds an rpath for GSL's library folder so conda's@rpathlibraries load, works from any folder, writes the MEX files next to itself, and no longer compilesC/src/main.c(the command-line program) into every MEX file..github/workflows/ci.ymlrunsmakeandmake testinC/with gcc and clang on Ubuntu and clang on macOS (the FFT bug in Fix FFT twiddle factors on GCC builds #2 was GCC-only), with GSL from apt or Homebrew. It passes onlyCCtomake(and Homebrew's GSL folders throughCPATH/LIBRARY_PATHon macOS), so it doesn't depend on the Makefile's warning flags, which Build with -Wall instead of -w #17 is changing. It also builds and installs the Python extension withsetup_P3.py, as the README describes, and runs the Python tests on Ubuntu (Python 3.9 and 3.13) and macOS (Python 3.13).Python/test_features.pyused to print values for features picked viadir()[:16]. It now asserts the hctsa v1.03 reference values fromC/tests/test_features.c, with the same tolerance (relative 1e-9): the 14test_ts.csvvalues, plusST_LocalExtremaon wn299 and rw437,DN_RemovePointson int1000 andSC_FluctAnalNaN on wn150. As in the C test,CO_AddNoiseand theSC_FluctAnalstandard error are only checked to be finite at N = 900. It also checks the feature names againstfeatureList.txt, thatcatchaMouse16_allmatches the single features, and the input handling: a NumPy array, a list, a tuple, a list of NumPy floats, a non-contiguous array and a generator all give identical values, integer input works, bad input raisesTypeError(single features andcatchaMouse16_all), and N = 8 and empty series give NaN rather than a crash. It runs withpytestor aspython3 test_features.py, and needs NumPy but no longer pandas.Matlab/test_catchaMouse16.mchecks the same reference values with row and column vectors, for the single features and forcatchaMouse16_all, plus N = 8, empty input and bad input (a matrix, a char array, complex data). It needs a MATLAB licence, so it is not in CI..tolist()), and the MATLAB example passes the same vector to both functions. ThemexAllrow describes how it finds GSL. The Python 2 anddistutilsnotes are replaced by "The Python build needs setuptools", and the README mentions both test scripts. Nothing else in the README changes.How it was tested
make testinC/: 20/20 checks pass with both compilers (unchanged; this PR doesn't touch C/).setup_P3.py(bothbuild_ext --inplaceand the README'sbuildtheninstallin a fresh venv).test_features.py: 7/7 tests pass under pytest with-W error, and as a script. The new test run against master's wrapper fails 6 of 7 tests (SystemErrorfor NumPy input, noTypeErrorfor bad input), so it catches the old behavior.mexAllcompiled all 16 MEX files with GSL found throughgsl-config, and again withmexAll('<conda prefix>'), both run from another folder.mexAll('/nonexistent')andmexAllwith no GSL on the PATH give the "not found" errors.test_catchaMouse16: all 45 checks pass. The/opt/homebrewfallback was not tested locally (no Homebrew GSL on this machine), but CI's macOS job uses Homebrew GSL for C and Python.make testgives 20 passed, 0 failed with gcc 13.3 and clang 18.1 on Ubuntu 24.04 (GSL 2.7.1) and Apple clang 21 on macOS arm64 (Homebrew GSL 2.8). The Python tests give 7 passed on Ubuntu with Python 3.9 and 3.13 and on macOS with Python 3.13.🤖 Generated with Claude Code