MCPcopy Create free account
hub / github.com/numpy/numpy / ones

Function ones

numpy/array_api/_creation_functions.py:256–272  ·  view source on GitHub ↗

Array API compatible wrapper for :py:func:`np.ones `. See its docstring for more information.

(
    shape: Union[int, Tuple[int, ...]],
    *,
    dtype: Optional[Dtype] = None,
    device: Optional[Device] = None,
)

Source from the content-addressed store, hash-verified

254
255
256def ones(
257 shape: Union[int, Tuple[int, ...]],
258 *,
259 dtype: Optional[Dtype] = None,
260 device: Optional[Device] = None,
261) -> Array:
262 """
263 Array API compatible wrapper for :py:func:`np.ones <numpy.ones>`.
264
265 See its docstring for more information.
266 """
267 from ._array_object import Array
268
269 _check_valid_dtype(dtype)
270 if device not in ["cpu", None]:
271 raise ValueError(f"Unsupported device {device!r}")
272 return Array._new(np.ones(shape, dtype=dtype))
273
274
275def ones_like(

Callers 13

test_ones_errorsFunction · 0.50
test_validate_indexFunction · 0.50
_matmul_array_valsFunction · 0.50
test_device_propertyFunction · 0.50
test_array_propertiesFunction · 0.50
test___array__Function · 0.50
test_allow_newaxisFunction · 0.50

Calls 2

_check_valid_dtypeFunction · 0.85
_newMethod · 0.80

Tested by 13

test_ones_errorsFunction · 0.40
test_validate_indexFunction · 0.40
_matmul_array_valsFunction · 0.40
test_device_propertyFunction · 0.40
test_array_propertiesFunction · 0.40
test___array__Function · 0.40
test_allow_newaxisFunction · 0.40