array_creation
Array creation functions expected by the python array API. Although ODL has many ways to create a tensor, we have found useful during development and testing to be able to create arrays in a certain backend. We do not expect the users to work with these functions often but have still implemented them as we deemed useful during development.
- Notes:
-> the functions with name *_like take an array/ODL object as an input -> the other functions require impl, shape, dtype, device arguments.
Examples: >>> odl.arange(‘numpy’, 0,10,1, dtype=’float32’, device=’cuda:0’) Traceback (most recent call last): ValueError: Unsupported device for NumPy: ‘cuda:0’ >>> odl.arange(‘numpy’,start=0,stop=10,step=1, dtype=’float32’, device=’cpu’) array([ 0., 1., 2., 3., 4., 5., 6., 7., 8., 9.], dtype=float32) >>> odl.asarray(odl.rn(4).element([1,2,3,4])) array([ 1., 2., 3., 4.]) >>> odl.full(‘numpy’, (4,4), 4) == np.full((4,4),4) array([[ True, True, True, True],
[ True, True, True, True], [ True, True, True, True], [ True, True, True, True]], dtype=bool)
>>> odl.full_like(x = np.full((4,4),4), fill_value=4) == np.full((4,4),4)
array([[ True, True, True, True],
[ True, True, True, True],
[ True, True, True, True],
[ True, True, True, True]], dtype=bool)