Giter Club home page Giter Club logo

Comments (4)

hameerabbasi avatar hameerabbasi commented on May 27, 2024

cc @mrocklin @nils-werner Your thoughts would be welcome here.

from sparse.

nils-werner avatar nils-werner commented on May 27, 2024

The docs say about inplace modification of immutable vs mutable types:

x += y is equivalent to x = 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.

hameerabbasi avatar hameerabbasi commented on May 27, 2024

Another solution that comes to mind would be to keep self as it is and only replace shape, coords and data.

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.

mrocklin avatar mrocklin commented on May 27, 2024

Option 1 seems fine with me with a couple of small comments:

  1. We should continue to fail when we would have failed before, like in x += 1 (because this would densify)
  2. We might consider operating genuinely in place when it's convenient. This is often the case when operating with scalars like x *= 2 or x /= 2

from sparse.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.