Skip to content

Add check for array contiguity#199

Merged
rpreen merged 1 commit intoxcsf-dev:masterfrom
dpaetzel:add-array-contiguity-check
Jul 16, 2025
Merged

Add check for array contiguity#199
rpreen merged 1 commit intoxcsf-dev:masterfrom
dpaetzel:add-array-contiguity-check

Conversation

@dpaetzel
Copy link
Copy Markdown
Collaborator

Fixes #198 for now by throwing an error.

For me, this works:

>>> import xcsf
>>> import numpy as np
>>> xcsf.XCS(x_dim=2, max_trials=10).fit(np.array([[1.1, 1.3], [1.2, 2.2]], order='F'), np.array([0.0, 1.0], order='F'))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: X and Y must be C-contiguous
>>> xcsf.XCS(x_dim=2, max_trials=10).fit(np.array([[1.1, 1.3], [1.2, 2.2]]), np.array([0.0, 1.0], order='F'))
2025-07-16T16:04:29.780 trials=10 train=0.52924 pset=2000.0 mset=105.6 mfrac=0.00
>>> 

@dpaetzel
Copy link
Copy Markdown
Collaborator Author

Note that this is still missing the predict part for now.

@codecov
Copy link
Copy Markdown

codecov bot commented Jul 16, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 70.58%. Comparing base (6d476e3) to head (ca15acd).
Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #199   +/-   ##
=======================================
  Coverage   70.58%   70.58%           
=======================================
  Files          61       61           
  Lines        8939     8939           
  Branches      933      933           
=======================================
  Hits         6310     6310           
  Misses       2629     2629           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dpaetzel dpaetzel force-pushed the add-array-contiguity-check branch from ceb9126 to 612e807 Compare July 16, 2025 14:13
@dpaetzel
Copy link
Copy Markdown
Collaborator Author

I added the same code to predict as well.

>>> m = xcsf.XCS(x_dim=2, max_trials=10).fit(np.array([[1.1, 1.3], [1.2, 2.2]]), np.array([0.0, 1.0], order='F')).predict(np.array([[1.0, 2.0], [2.3, 3.3]]))
2025-07-16T16:11:27.428 trials=10 train=0.10000 pset=2000.0 mset=17.9 mfrac=0.00
>>> m = xcsf.XCS(x_dim=2, max_trials=10).fit(np.array([[1.1, 1.3], [1.2, 2.2]]), np.array([0.0, 1.0], order='F')).predict(np.array([[1.0, 2.0], [2.3, 3.3]], order='F'))
2025-07-16T16:11:33.610 trials=10 train=0.45355 pset=2000.0 mset=74.5 mfrac=0.00
>>>

@dpaetzel
Copy link
Copy Markdown
Collaborator Author

This could be cleaned up a bit (e.g. storing NPY_ARRAY_C_CONTIGUOUS_ as a global constant) but I wanted to keep all the changes in the same place for now.

@dpaetzel dpaetzel force-pushed the add-array-contiguity-check branch from ba52eae to ca15acd Compare July 16, 2025 14:15
@rpreen rpreen merged commit 07fb6f0 into xcsf-dev:master Jul 16, 2025
10 of 11 checks passed
rpreen pushed a commit that referenced this pull request Jul 21, 2025
rpreen added a commit that referenced this pull request Jul 21, 2025
* [pre-commit.ci] pre-commit autoupdate

updates:
- [github.com/pre-commit/mirrors-clang-format: v20.1.7 → v20.1.8](pre-commit/mirrors-clang-format@v20.1.7...v20.1.8)
- [github.com/astral-sh/ruff-pre-commit: v0.12.2 → v0.12.3](astral-sh/ruff-pre-commit@v0.12.2...v0.12.3)

* Add checks for array contiguity (#199)

Fixes #198.

* Add `clean` parameter to `json_read` (#202)

* add Ruff Python linting/formatting

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: David Pätzel <david.paetzel@posteo.de>
Co-authored-by: Richard Preen <rpreen@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Check memory layout of NumPy arrays before processing

2 participants