Add methods __bool__, __float__ and __int__ to usm_ndarray#578
Add methods __bool__, __float__ and __int__ to usm_ndarray#578oleksandr-pavlyk merged 9 commits intomasterfrom
Conversation
|
@densmirn can you also implement |
import dpctl.tensor as dpt
X = dpt.usm_ndarray(10, 'd')
float(X[:1]) # raises TypeErrorThis works with NumPy: import numpy as np
X = np.ndarray(10, 'd')
float(X[:1]) # produces a float It breaks with the current code because X = dpt.usm_ndarray(10, 'd')
X[:1].usm_data.copy_to_host().view('d').shape # outputs (10,)Thus instead of Ideally, in a future, we should avoid copying the entire underlying buffer. |
|
Actually slice of array can be different, e.g.: import numpy as np
X = np.arange(10)
float(X[:1]) # 0.0
float(X[2:3]) # 2.0So when we copy data to host we don't know the slice: Looks like it should be somehow handled on |
|
@oleksandr-pavlyk could you please look at last comment? |
|
This is affected by #583 |
np.number comprises np.integer and np.inexact, so replace issubdtype(dt.type, np.inexact) or issubdtype(dt.type, np.number) with more efficient issubdtype(dt.type, np.number). Also allowed dtype.type to be np.bool_, to accommodate dtype="|b1" Replaced single quotation marks with double quotation marks per linter's flavor.
1f50ed8 to
e32b395
Compare
|
This PR(tests) have uncovered another problem which I fixed. It was inability of memory objects to understand objects with Also added tests to cover new functionality. |
|
I also added |
Closes #545