Giter Club home page Giter Club logo

Comments (2)

drhagen avatar drhagen commented on May 27, 2024

This feature would be useful to me. My use case is a large array of sympy expressions, most of which are 0, that would benefit from being represented as a sparse array with appropriate mathematical operations behaving sanely. Right now, the implementation of broadcasting object arrays tries to subscript the fill value and dies:

import sparse
from sympy.abc import a, b
aa = sparse.COO([[0],[0],[0]], [a], shape=(1,1,1))
bb = sparse.COO([[0],[0],[0]], [b], shape=(1,1,1))
aa + bb

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-37-6b05462dc5e0> in <module>
----> 1 aa + bb

~/anaconda/envs/symengine/lib/python3.7/site-packages/numpy/lib/mixins.py in func(self, other)
     23         if _disables_array_ufunc(other):
     24             return NotImplemented
---> 25         return ufunc(self, other)
     26     func.__name__ = '__{}__'.format(name)
     27     return func

~/anaconda/envs/symengine/lib/python3.7/site-packages/sparse/coo/core.py in __array_ufunc__(self, ufunc, method, *inputs, **kwargs)
   1439 
   1440         if method == '__call__':
-> 1441             result = elemwise(ufunc, *inputs, **kwargs)
   1442         elif method == 'reduce':
   1443             result = COO._reduce(ufunc, *inputs, **kwargs)

~/anaconda/envs/symengine/lib/python3.7/site-packages/sparse/coo/umath.py in elemwise(func, *args, **kwargs)
     45     """
     46 
---> 47     return _Elemwise(func, *args, **kwargs).get_result()
     48 
     49 

~/anaconda/envs/symengine/lib/python3.7/site-packages/sparse/coo/umath.py in __init__(self, func, *args, **kwargs)
    420         self.cache = {}
    421 
--> 422         self._get_fill_value()
    423         self._check_broadcast()
    424 

~/anaconda/envs/symengine/lib/python3.7/site-packages/sparse/coo/umath.py in _get_fill_value(self)
    465         from .core import COO
    466 
--> 467         zero_args = tuple(arg.fill_value[...] if isinstance(arg, COO) else arg for arg in self.args)
    468 
    469         # Some elemwise functions require a dtype argument, some abhorr it.

~/anaconda/envs/symengine/lib/python3.7/site-packages/sparse/coo/umath.py in <genexpr>(.0)
    465         from .core import COO
    466 
--> 467         zero_args = tuple(arg.fill_value[...] if isinstance(arg, COO) else arg for arg in self.args)
    468 
    469         # Some elemwise functions require a dtype argument, some abhorr it.

TypeError: 'int' object is not subscriptable

from sparse.

hameerabbasi avatar hameerabbasi commented on May 27, 2024

I would be highly surprised if that's the only issue you run into... There are a lot of places in the code where we assume things are NumPy arrays/scalars.

Weeding those out can be done with #163 which will make it easier to test things for multiple dtypes at once.

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.