cupyx.scipy.sparse.safely_cast_index_arrays#
- cupyx.scipy.sparse.safely_cast_index_arrays(A, idx_dtype=<class 'numpy.int32'>, msg='')[source]#
Safely cast sparse array indices to
idx_dtype.Check the shape of A to determine if it is safe to cast its index arrays to dtype idx_dtype. If any dimension in shape is larger than fits in the dtype, casting is unsafe so raise
ValueError. If safe, cast the index arrays toidx_dtypeand return the result without changing the input A. The caller can assign the results to A’s attributes if desired or use the recast index arrays directly.Unless downcasting is needed, the original index arrays are returned. You can test e.g.
A.indptr is new_indptrto see if downcasting occurred.- Parameters:
A (cupyx.scipy.sparse) – The array for which index arrays should be (potentially) downcast.
idx_dtype (dtype) – Desired index dtype. Defaults to
numpy.int32.msg (str, optional) – String appended to the
ValueErrormessage whenA.shapeis too big to fit inidx_dtype.
- Returns:
For CSR/CSC,
(indices, indptr). For COO,(row, col)– CuPy exposes the two coordinate arrays rather than SciPy’s n-Dcoordstuple, and a 1-D COO array carries an all-zerorow. For DIA,offsets.- Return type:
- Raises:
ValueError – When the dtype cannot represent
A’s shape or existing index values.