Skip to content

usm_ndarray must support array asignment #546

Closed

Description

@oleksandr-pavlyk

usm_ndarray must defined __setitem__.

Activity

  1. oleksandr-pavlyk commented on Sep 23, 2021

    @oleksandr-pavlyk
    ContributorAuthor

    This has been closed with merge of #586 :

    In [1]: import dpctl.tensor as dpt, numpy as np
    
    In [2]: X = dpt.usm_ndarray((3, 4), dtype="d")
    
    In [3]: for i0 in range(3):
       ...:     for i1 in range(4):
       ...:         X[i0, i1] = 2.0/(i1 + i0 + 1.0)  # assign Python scalars
       ...:
    
    In [4]: dpt.to_numpy(X)
    Out[4]:
    array([[2.        , 1.        , 0.66666667, 0.5       ],
           [1.        , 0.66666667, 0.5       , 0.4       ],
           [0.66666667, 0.5       , 0.4       , 0.33333333]])
    
    In [5]: Y = dpt.usm_ndarray((3, 4), dtype="f")
    
    In [6]: Y[:] = X  # from usm_ndarray to usm_ndarray with type coercion
    
    In [7]: dpt.to_numpy(Y)
    Out[7]:
    array([[2.        , 1.        , 0.6666667 , 0.5       ],
           [1.        , 0.6666667 , 0.5       , 0.4       ],
           [0.6666667 , 0.5       , 0.4       , 0.33333334]], dtype=float32)
    
    In [8]: Y[:] = np.full((3,4), 2)  # from numpy array
    
    In [9]: dpt.to_numpy(Y)
    Out[9]:
    array([[2., 2., 2., 2.],
           [2., 2., 2., 2.],
           [2., 2., 2., 2.]], dtype=float32)
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions