Skip to content

Introduce indexing for 1d arrays (using an nd approach)#1

Open
dschult wants to merge 5 commits into
csr-1dfrom
index1d-nd
Open

Introduce indexing for 1d arrays (using an nd approach)#1
dschult wants to merge 5 commits into
csr-1dfrom
index1d-nd

Conversation

@dschult
Copy link
Copy Markdown
Owner

@dschult dschult commented Feb 15, 2024

Turn on indexing for 1d csr_arrays!

This version rewrites _validate_indices from scratch using an N-D approach

  • adds 1-d sections to getitem and setitem dunders

  • rewrites _validate_indices with an N-d approach.

  • Reduce helper functions to one _compatible_boolean_array which in-lines its helper functions.

  • shorter, more readable, cleaner

  • also computes the shape of the output of this indexing.

  • passes all tests

  • adds 1d test for indexing (and passes those also)

  • __getitem__ and __setitem__ are still in the 1d/2d paradigm. Changing those will require changing the methods _get_intXslice and friends. Probably a rewrite of that is needed for N-D. When to do that?

This builds on the csr-1d branch, but should work with dok-1d branch after turning on tests for it.
And it should work for the 2d-arrays and matrix classes directly off of main (though test_indexing1d.py won't pass obviously).

@dschult dschult changed the title Index1d nd Introduce indexing for 1d arrays (using an nd approach) Feb 15, 2024
Comment thread scipy/sparse/_index.py
idx = np.atleast_1d(idx)

# broadcast scalar to full 1d
if issparse(x):
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Densification of input

Comment thread scipy/sparse/_index.py Outdated
Comment on lines +375 to +384
try:
ix = next(iter(idx), None)
for _ in range(max_ndim):
if isinstance(ix, bool):
# 1st element is boolean, check the rest
idx = np.asanyarray(idx)
if idx.dtype.kind == 'b':
return idx
return None
ix = next(iter(ix), None)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

z = np.add([[False, True, False], [False, False, False]], False, casting='equiv')

@stefanv
Copy link
Copy Markdown

stefanv commented Feb 15, 2024

np.lib.stride_tricks.as_strided can be used to emulate any large array:

np.lib.stride_tricks.as_strided([0], strides=(0, 0), shape=(5000, 5000))

@stefanv
Copy link
Copy Markdown

stefanv commented Feb 15, 2024

With dtype:

np.lib.stride_tricks.as_strided(np.array([1], dtype=float), strides=(0, 0), shape=(50000, 50000))

@dschult dschult force-pushed the csr-1d branch 3 times, most recently from 4f67011 to 92f3364 Compare March 6, 2024 04:20
@dschult dschult force-pushed the csr-1d branch 2 times, most recently from 58cef49 to 4596915 Compare March 22, 2024 19:54
dschult pushed a commit that referenced this pull request Apr 26, 2024
BUG: _qmc.py::_random_oa_lhs produces correlated samples
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.

2 participants