5
5
_real_numeric_dtypes ,
6
6
_floating_dtypes ,
7
7
_numeric_dtypes ,
8
- _integer_dtypes
9
8
)
10
- from . import _dtypes
11
- from . import _info
12
9
from ._array_object import Array
13
10
from ._dtypes import float32 , complex64
14
11
from ._flags import requires_api_version , get_array_api_strict_flags
15
- from ._creation_functions import zeros
12
+ from ._creation_functions import zeros , ones
16
13
from ._manipulation_functions import concat
17
14
18
15
from typing import TYPE_CHECKING
@@ -65,23 +62,8 @@ def cumulative_prod(
65
62
if x .ndim == 0 :
66
63
raise ValueError ("Only ndim >= 1 arrays are allowed in cumulative_prod" )
67
64
68
- # TODO: either all this is done by numpy's cumprod (?), or cumulative_sum should follow the same dance.
69
- if dtype is None :
70
- if x .dtype in _integer_dtypes :
71
- default_int = _info .__array_namespace_info__ ().default_dtypes ()["integral" ]
72
- if _dtypes ._bit_width (x .dtype ) < _dtypes ._bit_width (default_int ):
73
- if x .dtype in _dtypes ._unsigned_integer_dtypes :
74
- # find the unsigned integer of the same width as `default_int`
75
- dtype = _dtypes ._get_unsigned_from_signed (default_int )
76
- else :
77
- dtype = default_int
78
- else :
79
- dtype = x .dtype
80
- else :
81
- dtype = x .dtype
82
- else :
83
- if x .dtype != dtype :
84
- x = xp .astype (dtype )
65
+ if dtype is not None :
66
+ dtype = dtype ._np_dtype
85
67
86
68
if axis is None :
87
69
if x .ndim > 1 :
@@ -92,8 +74,8 @@ def cumulative_prod(
92
74
if include_initial :
93
75
if axis < 0 :
94
76
axis += x .ndim
95
- x = concat ([ones (x .shape [:axis ] + (1 ,) + x .shape [axis + 1 :], dtype = dtype ), x ], axis = axis )
96
- return Array ._new (np .cumprod (x ._array , axis = axis , dtype = dtype . _np_dtype ), device = x .device )
77
+ x = concat ([ones (x .shape [:axis ] + (1 ,) + x .shape [axis + 1 :], dtype = x . dtype ), x ], axis = axis )
78
+ return Array ._new (np .cumprod (x ._array , axis = axis , dtype = dtype ), device = x .device )
97
79
98
80
99
81
def max (
0 commit comments