Skip to content

Commit

Permalink
Merge pull request #544 from hameerabbasi/array-shape
Browse files Browse the repository at this point in the history
Allow an ndarray of integers as a shape.
  • Loading branch information
hameerabbasi authored Mar 27, 2022
2 parents 3923946 + 28febaa commit 30b7172
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 167 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
python: [3.7, 3.8, 3.9]
python: ['3.8', '3.9', '3.10']
numba_boundscheck: [0]
include:
- os: macos-latest
python: 3.9
python: '3.10'
- os: windows-latest
python: 3.9
python: '3.10'
- os: ubuntu-latest
python: 3.9
python: '3.10'
numba_boundscheck: 1
fail-fast: false
runs-on: ${{ matrix.os }}
Expand Down Expand Up @@ -79,7 +79,7 @@ jobs:
activate-environment: sparse-dev
allow-softlinks: true
environment-file: ci/environment.yml
python-version: 3.9
python-version: '3.10'
miniforge-variant: Mambaforge
use-only-tar-bz2: true
use-mamba: true
Expand Down
52 changes: 0 additions & 52 deletions azure-pipelines.yml

This file was deleted.

8 changes: 0 additions & 8 deletions ci/01-install.sh

This file was deleted.

17 changes: 0 additions & 17 deletions ci/azure-docs.yml

This file was deleted.

28 changes: 0 additions & 28 deletions ci/azure-steps.yml

This file was deleted.

16 changes: 0 additions & 16 deletions ci/environment-3.6.yml

This file was deleted.

16 changes: 0 additions & 16 deletions ci/environment-3.7.yml

This file was deleted.

16 changes: 0 additions & 16 deletions ci/environment-3.8.yml

This file was deleted.

2 changes: 1 addition & 1 deletion readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ build:
image: latest

python:
version: 3.7
version: '3.9'
pip_install: true
extra_requirements:
- docs
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ def parse_requires():
"License :: OSI Approved :: BSD License",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3 :: Only",
"Intended Audience :: Developers",
"Intended Audience :: Science/Research",
Expand All @@ -74,5 +74,5 @@ def parse_requires():
entry_points={
"numba_extensions": ["init = sparse._numba_extension:_init_extension"]
},
python_requires=">=3.6, <4",
python_requires=">=3.8, <4",
)
21 changes: 16 additions & 5 deletions sparse/_coo/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,12 +241,11 @@ def __init__(
if self.data.ndim != 1:
raise ValueError("data must be a scalar or 1-dimensional.")

if shape and not self.coords.size:
self.coords = np.zeros(
(len(shape) if isinstance(shape, Iterable) else 1, 0), dtype=np.intp
)

if shape is None:
warnings.warn(
"shape should be provided. This will raise a ValueError in the future.",
DeprecationWarning,
)
if self.coords.nbytes:
shape = tuple((self.coords.max(axis=1) + 1))
else:
Expand All @@ -255,6 +254,18 @@ def __init__(
if not isinstance(shape, Iterable):
shape = (shape,)

if isinstance(shape, np.ndarray):
shape = tuple(shape)

if shape and not self.coords.size:
warnings.warn(
"coords should be an ndarray. This will raise a ValueError in the future.",
DeprecationWarning,
)
self.coords = np.zeros(
(len(shape) if isinstance(shape, Iterable) else 1, 0), dtype=np.intp
)

super().__init__(shape, fill_value=fill_value)
if idx_dtype:
if not can_store(idx_dtype, max(shape)):
Expand Down
7 changes: 7 additions & 0 deletions sparse/tests/test_coo.py
Original file line number Diff line number Diff line change
Expand Up @@ -1672,3 +1672,10 @@ def test_scalar_elemwise():
x1 = s1.todense()

assert_eq(s1 * x2, x1 * x2)


def test_array_as_shape():
coords = [[0, 1, 2, 3, 4], [0, 1, 2, 3, 4]]
data = [10, 20, 30, 40, 50]

s = sparse.COO(coords, data, shape=np.array((5, 5)))

0 comments on commit 30b7172

Please sign in to comment.