arkouda icon indicating copy to clipboard operation
arkouda copied to clipboard

Support binary operations on `ArrayView`s

Open milthorpe opened this issue 2 years ago • 1 comments

Given that an ArrayView is 'a multi-dimensional view of a pdarray [which] can be indexed', it seems like binary operations which support pdarray operands should also support ArrayView operands. However, such operations currently crash with an internal formatting error:

print(print(ak.get_config()))
x = ak.array((1,2,3))
y = ak.array((1,1,1))
x_t = x.reshape((len(x),1))
print(type(x_t))
bigger = ak.where(x > x_t,
                 x, x_t)
{'arkoudaVersion': 'v2022.04.15+266.g1f24d1f5.dirty', 'chplVersion': ' 1.28.0', 'ZMQVersion': '4.3.3', 'HDF5Version': '1.10.7', 'serverHostname': 'xxxx', 'ServerPort': 5555, 'numLocales': 1, 'numPUs': 20, 'maxTaskPar': 20, 'physicalMemory': 270182281216, 'distributionType': 'domain(1,int(64),false)', 'LocaleConfigs': [{'id': 0, 'name': 'xxxx', 'numPUs': 20, 'maxTaskPar': 20, 'physicalMemory': 270182281216}], 'authenticate': False, 'logLevel': 'INFO', 'regexMaxCaptures': 20, 'byteorder': 'little', 'ARROW_VERSION': '7.0.0'}
<class 'arkouda.array_view.ArrayView'>
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Input In [37], in <cell line: 6>()
      4 x_t = x.reshape((len(x),1))
      5 print(type(x_t))
----> 6 bigger = ak.where(x > x_t,
      7                  x, x_t)

File /noback/milthorpe/arkouda/arkouda/pdarrayclass.py:431, in pdarray.__gt__(self, other)
    430 def __gt__(self, other):
--> 431     return self._binop(other, ">")

File /noback/milthorpe/arkouda/arkouda/pdarrayclass.py:294, in pdarray._binop(self, other, op)
    290 if dt not in DTypes:
    291     raise TypeError(f"Unhandled scalar type: {other} ({type(other)})")
    292 repMsg = generic_msg(
    293     cmd="binopvs",
--> 294     args={"op": op, "a": self, "dtype": dt, "value": NUMBER_FORMAT_STRINGS[dt].format(other)},
    295 )
    296 return create_pdarray(repMsg)

TypeError: unsupported format string passed to numpy.ndarray.__format__

It seems like if either operand is an ArrayView, Arkouda calls the vector-scalar operation binopvs, rather than the vector-vector binopvv.

milthorpe avatar Sep 12 '22 11:09 milthorpe

Thanks for the issue @milthorpe!

This involves broadcasting the pdarray and ArrayView into compatible shapes. This is definitely something we want to be able to do, but it's a bit further out since a good deal of the base ArrayView functionality needs to be fleshed out first

Just dropping the expected output of this operation from numpy for future reference:

>>> x = np.array((1,2,3))
>>> x
array([1, 2, 3])

>>> x_t = x.reshape((len(x),1))
>>> x_t
array([[1],
       [2],
       [3]])

>>> x > x_t
array([[False,  True,  True],
       [False, False,  True],
       [False, False, False]])

>>> np.where(x > x_t, x, x_t)
array([[1, 2, 3],
       [2, 2, 3],
       [3, 3, 3]])

stress-tess avatar Sep 12 '22 18:09 stress-tess

ArrayView is being deprecated in favor of the Array API implementation.

Ethan-DeBandi99 avatar May 31 '23 16:05 Ethan-DeBandi99