Comments (4)
cc @mrocklin @nils-werner Your thoughts would be welcome here.
from sparse.
The docs say about inplace modification of immutable vs mutable types:
x += y
is equivalent tox = operator.iadd(x, y)
and
For immutable targets such as strings, numbers, and tuples, the updated value is computed, but not assigned back to the input variable:
from operator import iadd a = 'hello' # hello iadd(a, ' world') # hello world a # hello
For mutable targets such as lists and dictionaries, the inplace method will perform the update, so no subsequent assignment is necessary:
s = list('hello') # hello iadd(s, list(' world')) # hello world s # hello world
To me, that sounds like solution 1. would be acceptable behaviour.
Another solution that comes to mind would be to keep self
as it is and only replace shape
, coords
and data
.
from sparse.
Another solution that comes to mind would be to keep self as it is and only replace
shape
,coords
anddata
.
coords
and data
I agree on. shape
, I'm not so sure about. Take the following simple example using Numpy (they don't support assigning when the shape isn't broadcastable to the output shape):
>>> import numpy as np
>>> x = np.zeros((1, 5))
>>> y = np.ones((5, 5))
>>> x += y
Traceback (most recent call last):
File "<input>", line 1, in <module>
ValueError: non-broadcastable output operand with shape (1,5) doesn't match the broadcast shape (5,5)
from sparse.
Option 1 seems fine with me with a couple of small comments:
- We should continue to fail when we would have failed before, like in
x += 1
(because this would densify) - We might consider operating genuinely in place when it's convenient. This is often the case when operating with scalars like
x *= 2
orx /= 2
from sparse.
Related Issues (20)
- Difference in sparse.einsum and np.einsum behaviour HOT 10
- Dump gcxs to file HOT 4
- Numba dependency incompatible with Py3.11. HOT 5
- Unexpected warning when adding arrays with non-matching coordinates HOT 3
- Multiplicative assignment warning HOT 2
- Unable to install shap on python 3.11 doubt to numba cannot install on Python version 3.11.2 HOT 1
- `einsum` doesn't handle `dtype` and `optimize` kwargs HOT 2
- Proper usage of sparse 3D array: initialization, assignment of values and use in calculations HOT 2
- np.diff equivalent HOT 2
- DeprecationWarning: coords should be an ndarray. This will raise a ValueError in the future. HOT 1
- Test failures in test_tensordot HOT 14
- Correct type hint for sparse COO matrix? HOT 1
- numpy ufuncs can change the compression of a gcxs array HOT 12
- Support `arr.size >= 2 ** 64` as long as each dimension is `< 2 ** 64` HOT 1
- Constructing GCXS from non-canonical `scipy.sparse.csr_matrix` results in wrong results HOT 5
- Support for Fortran order in COO.flatten() HOT 1
- Consider MatRepr for `__repr__` and `_repr_html_` HOT 9
- `GCXS` matmul => slice leads to incorrect results HOT 4
- `TypeError` when accessing `.real` and `.imag` attribute on sparse array of string type
- Installing directly from GitHub fails on Python 3.12 HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sparse.