Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 0 additions & 35 deletions .appveyor.yml

This file was deleted.

33 changes: 33 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: CI

on:
push:
branches: [master]
pull_request:
branches: [master]

jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]

steps:
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install cython numpy scipy
pip install -e .

- name: Run tests
run: python -m unittest discover bandmat
12 changes: 7 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
.git/
_darcs/
__pycache__/
*.pyc
*.so
*.c
*.egg
.eggs/
bandmat.egg-info/
build/
dist/
env/
.venv/
MANIFEST
*.c
*.pyc
*.so
20 changes: 0 additions & 20 deletions .travis.yml

This file was deleted.

68 changes: 15 additions & 53 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
bandmat
=======

|Linux build status| |Windows build status|
|CI status|

.. |Linux build status| image:: https://travis-ci.org/MattShannon/bandmat.svg?branch=master
:alt: Linux build status
:target: https://travis-ci.org/MattShannon/bandmat
.. |Windows build status| image:: https://ci.appveyor.com/api/projects/status/cy8ouawd9bnus0ai/branch/master?svg=true
:alt: Windows build status
:target: https://ci.appveyor.com/project/MattShannon/bandmat/branch/master
.. |CI status| image:: https://github.com/MattShannon/bandmat/actions/workflows/ci.yml/badge.svg?branch=master
:alt: CI status
:target: https://github.com/MattShannon/bandmat/actions/workflows/ci.yml

This package provides a simple banded matrix library for python.
It supports banded matrix-vector and matrix-matrix multiplication, converting
Expand Down Expand Up @@ -58,26 +55,16 @@ bandmat.
Installation
------------

For most purposes the simplest way to install bandmat is to use pip.
For example in Debian and Ubuntu::
For most purposes the simplest way to install bandmat is to use pip in a
virtual environment::

# (for python3, use "python3-numpy python3-scipy" instead)
sudo apt-get install python-numpy python-scipy
sudo pip install bandmat
python3 -m venv env
env/bin/pip install bandmat

The first command installs numpy and scipy from the system repository, since
installing numpy and scipy using pip is generally not recommended.
The second command installs the latest released version of
This installs the latest released version of
`bandmat on PyPI <https://pypi.python.org/pypi/bandmat>`_, together with any
currently uninstalled python packages required by bandmat.

bandmat can also be installed in a virtualenv::

# (for python3, use "python3-numpy python3-scipy" instead)
sudo apt-get install python-numpy python-scipy
virtualenv --system-site-packages env
env/bin/pip install bandmat

The latest development version of bandmat is available from a github repository
(see below).

Expand All @@ -104,42 +91,17 @@ To obtain the latest source code using git::

git clone git://github.com/MattShannon/bandmat.git

Development is in fact done using `darcs <http://darcs.net/>`_, with the darcs
repository converted to a git repository using
`darcs-to-git <https://github.com/purcell/darcs-to-git>`_.

To install any currently uninstalled python packages required by bandmat::
To install bandmat for development in a virtual environment::

# (for python3, use "cython3 python3-numpy python3-scipy" instead)
sudo apt-get install cython python-numpy python-scipy
sudo pip install -r requirements.txt
python3 -m venv env
env/bin/pip install -e .

To compile the cython part of bandmat in the current directory::
This will install the build dependencies (cython, numpy) and compile the
cython extensions automatically.
To recompile after modifying ``.pyx`` files::

python setup.py build_ext --inplace

This command must be run after every modification to the source ``.pyx`` files.

A note on ``setup.py``
----------------------

The included ``setup.py`` file operates in one of two modes depending on
whether or not the file ``dev`` is present in the project root directory.
In development mode (``dev`` present, as for the github repository), the
``build_ext`` command uses cython to compile cython modules from their ``.pyx``
source, and the ``sdist`` command is modified to first use cython to compile
cython modules from their ``.pyx`` source to ``.c`` files.
In distribution mode (``dev`` absent, as for source distributions such as the
code on PyPI), the ``build_ext`` command uses a C compiler to directly compile
cython modules from the corresponding ``.c`` files.
This approach ensures that source distributions can be installed on systems
without cython or with an incompatible version of cython, while ensuring that
distributed ``.c`` files are always up-to-date and that the source ``.pyx``
files are used instead of ``.c`` files during development.

The author would welcome any suggestions for more elegant ways to achieve a
similar effect to the approach described above!

Bugs
----

Expand Down
12 changes: 6 additions & 6 deletions bandmat/misc.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ cimport cython
cnp.import_array()
cnp.import_ufunc()

def fancy_plus_equals(cnp.ndarray[cnp.int_t, ndim=1] target_index_seq,
def fancy_plus_equals(cnp.ndarray[cnp.intp_t, ndim=1] target_index_seq,
cnp.ndarray[cnp.float64_t, ndim=1] source,
cnp.ndarray[cnp.float64_t, ndim=1] target):
"""Implements a += method with fancy indexing.
Expand All @@ -26,15 +26,15 @@ def fancy_plus_equals(cnp.ndarray[cnp.int_t, ndim=1] target_index_seq,
assert target_index_seq.shape[0] == source_size

cdef unsigned long source_index
cdef long target_index
cdef cnp.intp_t target_index

for source_index in range(source_size):
target_index = target_index_seq[source_index]
target[target_index] += source[source_index]

return

def fancy_plus_equals_2d(cnp.ndarray[cnp.int_t, ndim=1] target_index_seq,
def fancy_plus_equals_2d(cnp.ndarray[cnp.intp_t, ndim=1] target_index_seq,
cnp.ndarray[cnp.float64_t, ndim=2] source,
cnp.ndarray[cnp.float64_t, ndim=2] target):
"""Implements a += method with fancy indexing.
Expand All @@ -52,7 +52,7 @@ def fancy_plus_equals_2d(cnp.ndarray[cnp.int_t, ndim=1] target_index_seq,
assert target.shape[1] == size1

cdef unsigned long source_index
cdef long target_index
cdef cnp.intp_t target_index
cdef unsigned long index1

for source_index in range(source_size):
Expand All @@ -62,7 +62,7 @@ def fancy_plus_equals_2d(cnp.ndarray[cnp.int_t, ndim=1] target_index_seq,

return

def fancy_plus_equals_3d(cnp.ndarray[cnp.int_t, ndim=1] target_index_seq,
def fancy_plus_equals_3d(cnp.ndarray[cnp.intp_t, ndim=1] target_index_seq,
cnp.ndarray[cnp.float64_t, ndim=3] source,
cnp.ndarray[cnp.float64_t, ndim=3] target):
"""Implements a += method with fancy indexing.
Expand All @@ -83,7 +83,7 @@ def fancy_plus_equals_3d(cnp.ndarray[cnp.int_t, ndim=1] target_index_seq,
assert target.shape[2] == size2

cdef unsigned long source_index
cdef long target_index
cdef cnp.intp_t target_index
cdef unsigned long index1
cdef unsigned long index2

Expand Down
8 changes: 4 additions & 4 deletions bandmat/test_linalg.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def test__cholesky_banded(self, its=100):
# First part of the message is e.g. "2-th leading minor".
msgRe = (r'^' + re.escape(str(e)[:15]) +
r'.*not positive definite$')
with self.assertRaisesRegexp(la.LinAlgError, msgRe):
with self.assertRaisesRegex(la.LinAlgError, msgRe):
sla.cholesky(mat_bm.full(), lower=lower)
else:
assert np.shape(chol_data) == (depth + 1, size)
Expand Down Expand Up @@ -171,12 +171,12 @@ def test__solve_triangular_banded(self, its=100):
badFrame
)
msgRe = '^' + re.escape(msg) + '$'
with self.assertRaisesRegexp(la.LinAlgError, msgRe):
with self.assertRaisesRegex(la.LinAlgError, msgRe):
bla._solve_triangular_banded(
chol_data, b_arg, transposed=transposed, lower=lower,
overwrite_b=overwrite_b
)
with self.assertRaisesRegexp(la.LinAlgError, msgRe):
with self.assertRaisesRegex(la.LinAlgError, msgRe):
sla.solve_triangular(
chol_full, b, trans=transposed, lower=lower
)
Expand Down Expand Up @@ -299,7 +299,7 @@ def test_solveh(self, its=50):
if size == 0:
x_good = np.zeros((size,))
else:
x_good = sla.solve(a_full, b, sym_pos=True)
x_good = sla.solve(a_full, b, assume_a='pos')
assert_allclose(x, x_good)
assert not np.may_share_memory(x, a_bm.data)
assert not np.may_share_memory(x, b)
Expand Down
13 changes: 7 additions & 6 deletions bandmat/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import unittest
import random
import numpy as np
from numpy.random import randn, randint

from bandmat.misc import fancy_plus_equals, fancy_plus_equals_2d
Expand All @@ -23,7 +24,7 @@ def test_fancy_plus_equals(self, its=100):
target_size = random.choice([1, randint(1, 10), randint(1, 100)])
source = randn(source_size)
target = randn(target_size)
target_index_seq = randint(target_size, size=source_size)
target_index_seq = randint(target_size, size=source_size, dtype=np.intp)
array_mem = get_array_mem(target_index_seq, source, target)

target_good = target.copy()
Expand All @@ -41,7 +42,7 @@ def test_fancy_plus_equals_fails(self, its=100):
target_size = random.choice([1, randint(1, 10), randint(1, 100)])
source = randn(source_size)
target = randn(target_size)
target_index_seq = randint(target_size, size=source_size)
target_index_seq = randint(target_size, size=source_size, dtype=np.intp)
target_index_seq[randint(source_size)] = (
(-target_size - 1 - randint(10)) if rand_bool()
else target_size + randint(10)
Expand All @@ -57,7 +58,7 @@ def test_fancy_plus_equals_2d(self, its=100):
size1 = random.choice([0, 1, randint(10)])
source = randn(source_size, size1)
target = randn(target_size, size1)
target_index_seq = randint(target_size, size=source_size)
target_index_seq = randint(target_size, size=source_size, dtype=np.intp)
array_mem = get_array_mem(target_index_seq, source, target)

target_good = target.copy()
Expand All @@ -76,7 +77,7 @@ def test_fancy_plus_equals_2d_fails(self, its=100):
size1 = random.choice([1, randint(1, 10)])
source = randn(source_size, size1)
target = randn(target_size, size1)
target_index_seq = randint(target_size, size=source_size)
target_index_seq = randint(target_size, size=source_size, dtype=np.intp)
target_index_seq[randint(source_size)] = (
(-target_size - 1 - randint(10)) if rand_bool()
else target_size + randint(10)
Expand All @@ -93,7 +94,7 @@ def test_fancy_plus_equals_3d(self, its=100):
size2 = random.choice([0, 1, randint(10)])
source = randn(source_size, size1, size2)
target = randn(target_size, size1, size2)
target_index_seq = randint(target_size, size=source_size)
target_index_seq = randint(target_size, size=source_size, dtype=np.intp)
array_mem = get_array_mem(target_index_seq, source, target)

target_good = target.copy()
Expand All @@ -113,7 +114,7 @@ def test_fancy_plus_equals_3d_fails(self, its=100):
size2 = random.choice([1, randint(1, 10)])
source = randn(source_size, size1, size2)
target = randn(target_size, size1, size2)
target_index_seq = randint(target_size, size=source_size)
target_index_seq = randint(target_size, size=source_size, dtype=np.intp)
target_index_seq[randint(source_size)] = (
(-target_size - 1 - randint(10)) if rand_bool()
else target_size + randint(10)
Expand Down
10 changes: 0 additions & 10 deletions boring.darcs

This file was deleted.

Empty file removed dev
Empty file.
7 changes: 7 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[build-system]
requires = [
"cython",
"numpy",
"setuptools",
"wheel",
]
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
numpy>=1.6.1
scipy>=0.9.0
numpy>=1.26.0
scipy>=1.12.0
Loading
Loading