xbarray 0.0.1a1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of xbarray might be problematic. Click here for more details.
- array_api_typing/__init__.py +9 -0
- array_api_typing/typing_2024_12/__init__.py +12 -0
- array_api_typing/typing_2024_12/_api_constant.py +32 -0
- array_api_typing/typing_2024_12/_api_fft_typing.py +717 -0
- array_api_typing/typing_2024_12/_api_linalg_typing.py +897 -0
- array_api_typing/typing_2024_12/_api_return_typing.py +103 -0
- array_api_typing/typing_2024_12/_api_typing.py +5855 -0
- array_api_typing/typing_2024_12/_array_typing.py +1265 -0
- array_api_typing/typing_compat/__init__.py +12 -0
- array_api_typing/typing_compat/_api_typing.py +27 -0
- array_api_typing/typing_compat/_array_typing.py +36 -0
- array_api_typing/typing_extra/__init__.py +12 -0
- array_api_typing/typing_extra/_api_typing.py +651 -0
- array_api_typing/typing_extra/_at.py +87 -0
- xbarray/__init__.py +1 -0
- xbarray/base/__init__.py +1 -0
- xbarray/base/base.py +199 -0
- xbarray/common/implementations.py +61 -0
- xbarray/jax/__init__.py +25 -0
- xbarray/jax/_extra.py +98 -0
- xbarray/jax/_typing.py +15 -0
- xbarray/jax/random.py +116 -0
- xbarray/numpy/__init__.py +19 -0
- xbarray/numpy/_extra.py +83 -0
- xbarray/numpy/_typing.py +14 -0
- xbarray/numpy/random.py +106 -0
- xbarray/pytorch/__init__.py +20 -0
- xbarray/pytorch/_extra.py +109 -0
- xbarray/pytorch/_typing.py +13 -0
- xbarray/pytorch/random.py +102 -0
- xbarray-0.0.1a1.dist-info/METADATA +14 -0
- xbarray-0.0.1a1.dist-info/RECORD +35 -0
- xbarray-0.0.1a1.dist-info/WHEEL +5 -0
- xbarray-0.0.1a1.dist-info/licenses/LICENSE +21 -0
- xbarray-0.0.1a1.dist-info/top_level.txt +2 -0
xbarray/numpy/_extra.py
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
from typing import Any, Union, Optional
|
|
2
|
+
import numpy as np
|
|
3
|
+
from ._typing import ARRAY_TYPE, DTYPE_TYPE, DEVICE_TYPE, RNG_TYPE
|
|
4
|
+
from xbarray.base import ComputeBackend, SupportsDLPack
|
|
5
|
+
|
|
6
|
+
__all__ = [
|
|
7
|
+
"default_integer_dtype",
|
|
8
|
+
"default_floating_dtype",
|
|
9
|
+
"default_boolean_dtype",
|
|
10
|
+
"is_backendarray",
|
|
11
|
+
"from_numpy",
|
|
12
|
+
"from_other_backend",
|
|
13
|
+
"to_numpy",
|
|
14
|
+
"to_dlpack",
|
|
15
|
+
"dtype_is_real_integer",
|
|
16
|
+
"dtype_is_real_floating",
|
|
17
|
+
"dtype_is_boolean",
|
|
18
|
+
"abbreviate_array",
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
default_integer_dtype = int
|
|
22
|
+
default_floating_dtype = float
|
|
23
|
+
default_boolean_dtype = bool
|
|
24
|
+
|
|
25
|
+
def is_backendarray(data : Any) -> bool:
|
|
26
|
+
return isinstance(data, np.ndarray)
|
|
27
|
+
|
|
28
|
+
def from_numpy(
|
|
29
|
+
data : np.ndarray,
|
|
30
|
+
/,
|
|
31
|
+
*,
|
|
32
|
+
dtype : Optional[DTYPE_TYPE] = None,
|
|
33
|
+
device : Optional[DEVICE_TYPE] = None
|
|
34
|
+
) -> ARRAY_TYPE:
|
|
35
|
+
return data
|
|
36
|
+
|
|
37
|
+
def from_other_backend(
|
|
38
|
+
other_backend: ComputeBackend,
|
|
39
|
+
data: Any,
|
|
40
|
+
/,
|
|
41
|
+
) -> ARRAY_TYPE:
|
|
42
|
+
return other_backend.to_numpy(data)
|
|
43
|
+
|
|
44
|
+
def to_numpy(
|
|
45
|
+
data : ARRAY_TYPE
|
|
46
|
+
) -> np.ndarray:
|
|
47
|
+
return data
|
|
48
|
+
|
|
49
|
+
def to_dlpack(
|
|
50
|
+
self,
|
|
51
|
+
data: ARRAY_TYPE,
|
|
52
|
+
/,
|
|
53
|
+
) -> SupportsDLPack:
|
|
54
|
+
return data
|
|
55
|
+
|
|
56
|
+
def dtype_is_real_integer(
|
|
57
|
+
dtype: DTYPE_TYPE
|
|
58
|
+
) -> bool:
|
|
59
|
+
return np.issubdtype(dtype, np.integer)
|
|
60
|
+
|
|
61
|
+
def dtype_is_real_floating(
|
|
62
|
+
dtype: DTYPE_TYPE
|
|
63
|
+
) -> bool:
|
|
64
|
+
return np.issubdtype(dtype, np.floating)
|
|
65
|
+
|
|
66
|
+
def dtype_is_boolean(
|
|
67
|
+
dtype: DTYPE_TYPE
|
|
68
|
+
) -> bool:
|
|
69
|
+
return dtype == np.bool_ or dtype == bool
|
|
70
|
+
|
|
71
|
+
from xbarray.common.implementations import get_abbreviate_array_function, get_map_fn_over_arrays_function
|
|
72
|
+
from array_api_compat import numpy as compat_module
|
|
73
|
+
abbreviate_array = get_abbreviate_array_function(
|
|
74
|
+
backend=compat_module,
|
|
75
|
+
default_integer_dtype=default_integer_dtype,
|
|
76
|
+
func_dtype_is_real_floating=dtype_is_real_floating,
|
|
77
|
+
func_dtype_is_real_integer=dtype_is_real_integer,
|
|
78
|
+
func_dtype_is_boolean=dtype_is_boolean,
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
map_fn_over_arrays = get_map_fn_over_arrays_function(
|
|
82
|
+
is_backendarray=is_backendarray,
|
|
83
|
+
)
|
xbarray/numpy/_typing.py
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
from typing import Union, Any, Optional
|
|
2
|
+
import numpy as np
|
|
3
|
+
|
|
4
|
+
__all__ = [
|
|
5
|
+
'ARRAY_TYPE',
|
|
6
|
+
'DTYPE_TYPE',
|
|
7
|
+
'DEVICE_TYPE',
|
|
8
|
+
'RNG_TYPE',
|
|
9
|
+
]
|
|
10
|
+
|
|
11
|
+
ARRAY_TYPE = np.ndarray
|
|
12
|
+
DTYPE_TYPE = np.dtype
|
|
13
|
+
DEVICE_TYPE = Any
|
|
14
|
+
RNG_TYPE = np.random.Generator
|
xbarray/numpy/random.py
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
from typing import Union, Optional, Tuple, Any
|
|
2
|
+
from ._typing import ARRAY_TYPE, DTYPE_TYPE, DEVICE_TYPE, RNG_TYPE
|
|
3
|
+
import numpy as np
|
|
4
|
+
|
|
5
|
+
__all__ = [
|
|
6
|
+
"random_number_generator",
|
|
7
|
+
"random_discrete_uniform",
|
|
8
|
+
"random_uniform",
|
|
9
|
+
"random_exponential",
|
|
10
|
+
"random_normal",
|
|
11
|
+
"random_geometric",
|
|
12
|
+
"random_permutation"
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
def random_number_generator(
|
|
16
|
+
seed : Optional[int] = None,
|
|
17
|
+
*,
|
|
18
|
+
device : Optional[DEVICE_TYPE] = None
|
|
19
|
+
) -> RNG_TYPE:
|
|
20
|
+
return np.random.default_rng(seed)
|
|
21
|
+
|
|
22
|
+
def random_discrete_uniform(
|
|
23
|
+
shape : Union[int, Tuple[int, ...]],
|
|
24
|
+
from_num : int,
|
|
25
|
+
to_num : int,
|
|
26
|
+
/,
|
|
27
|
+
*,
|
|
28
|
+
rng : RNG_TYPE,
|
|
29
|
+
dtype : Optional[DTYPE_TYPE] = None,
|
|
30
|
+
device : Optional[DEVICE_TYPE] = None
|
|
31
|
+
) -> Tuple[RNG_TYPE, ARRAY_TYPE]:
|
|
32
|
+
t = rng.integers(int(from_num), int(to_num), size=shape)
|
|
33
|
+
if dtype is not None:
|
|
34
|
+
t = t.astype(dtype)
|
|
35
|
+
return rng, t
|
|
36
|
+
|
|
37
|
+
def random_uniform(
|
|
38
|
+
shape: Union[int, Tuple[int, ...]],
|
|
39
|
+
/,
|
|
40
|
+
*,
|
|
41
|
+
rng : RNG_TYPE,
|
|
42
|
+
low : float = 0.0, high : float = 1.0,
|
|
43
|
+
dtype : Optional[DTYPE_TYPE] = None,
|
|
44
|
+
device : Optional[DEVICE_TYPE] = None
|
|
45
|
+
) -> Tuple[RNG_TYPE, ARRAY_TYPE]:
|
|
46
|
+
t = rng.uniform(float(low), float(high), size=shape)
|
|
47
|
+
if dtype is not None:
|
|
48
|
+
t = t.astype(dtype)
|
|
49
|
+
return rng, t
|
|
50
|
+
|
|
51
|
+
def random_exponential(
|
|
52
|
+
shape: Union[int, Tuple[int, ...]],
|
|
53
|
+
/,
|
|
54
|
+
*,
|
|
55
|
+
rng : RNG_TYPE,
|
|
56
|
+
lambd : float = 1.0,
|
|
57
|
+
dtype : Optional[DTYPE_TYPE] = None,
|
|
58
|
+
device : Optional[DEVICE_TYPE] = None
|
|
59
|
+
) -> Tuple[RNG_TYPE, ARRAY_TYPE]:
|
|
60
|
+
t = rng.exponential(1.0 / float(lambd), size=shape)
|
|
61
|
+
if dtype is not None:
|
|
62
|
+
t = t.astype(dtype)
|
|
63
|
+
return rng, t
|
|
64
|
+
|
|
65
|
+
@classmethod
|
|
66
|
+
def random_normal(
|
|
67
|
+
shape: Union[int, Tuple[int, ...]],
|
|
68
|
+
/,
|
|
69
|
+
*,
|
|
70
|
+
rng : RNG_TYPE,
|
|
71
|
+
mean : float = 0.0, std : float = 1.0,
|
|
72
|
+
dtype : Optional[DTYPE_TYPE] = None,
|
|
73
|
+
device : Optional[Any] = None
|
|
74
|
+
) -> Tuple[RNG_TYPE, ARRAY_TYPE]:
|
|
75
|
+
t = rng.normal(mean, std, size=shape)
|
|
76
|
+
if dtype is not None:
|
|
77
|
+
t = t.astype(dtype)
|
|
78
|
+
return rng, t
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def random_geometric(
|
|
82
|
+
shape: Union[int, Tuple[int, ...]],
|
|
83
|
+
/,
|
|
84
|
+
*,
|
|
85
|
+
p: float,
|
|
86
|
+
rng: RNG_TYPE,
|
|
87
|
+
dtype: Optional[DTYPE_TYPE] = None,
|
|
88
|
+
device: Optional[Any] = None
|
|
89
|
+
) -> Tuple[RNG_TYPE, ARRAY_TYPE]:
|
|
90
|
+
t = rng.geometric(p, size=shape)
|
|
91
|
+
if dtype is not None:
|
|
92
|
+
t = t.astype(dtype)
|
|
93
|
+
return rng, t
|
|
94
|
+
|
|
95
|
+
def random_permutation(
|
|
96
|
+
n : int,
|
|
97
|
+
/,
|
|
98
|
+
*,
|
|
99
|
+
rng: RNG_TYPE,
|
|
100
|
+
dtype: Optional[DTYPE_TYPE] = None,
|
|
101
|
+
device: Optional[DEVICE_TYPE] = None
|
|
102
|
+
) -> Tuple[RNG_TYPE, ARRAY_TYPE]:
|
|
103
|
+
t = rng.permutation(n)
|
|
104
|
+
if dtype is not None:
|
|
105
|
+
t = t.astype(dtype)
|
|
106
|
+
return rng, t
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
from array_api_compat.torch import *
|
|
2
|
+
|
|
3
|
+
simplified_name = "pytorch"
|
|
4
|
+
|
|
5
|
+
from array_api_compat import torch as compat_module
|
|
6
|
+
|
|
7
|
+
# Import and bind all functions from array_api_extra before exposing them
|
|
8
|
+
import array_api_extra
|
|
9
|
+
from functools import partial
|
|
10
|
+
for api_name in dir(array_api_extra):
|
|
11
|
+
if api_name.startswith('_'):
|
|
12
|
+
continue
|
|
13
|
+
globals()[api_name] = partial(
|
|
14
|
+
getattr(array_api_extra, api_name),
|
|
15
|
+
xp=compat_module
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
from ._typing import *
|
|
19
|
+
from ._extra import *
|
|
20
|
+
__import__(__package__ + ".random")
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
from typing import Any, Union, Optional
|
|
2
|
+
import numpy as np
|
|
3
|
+
import torch
|
|
4
|
+
from ._typing import ARRAY_TYPE, DTYPE_TYPE, DEVICE_TYPE, RNG_TYPE
|
|
5
|
+
from xbarray.base import ComputeBackend, SupportsDLPack
|
|
6
|
+
|
|
7
|
+
PYTORCH_DTYPE_CAST_MAP = {
|
|
8
|
+
torch.uint16: torch.int16,
|
|
9
|
+
torch.uint32: torch.int32,
|
|
10
|
+
torch.uint64: torch.int64,
|
|
11
|
+
torch.float8_e4m3fn: torch.float16,
|
|
12
|
+
torch.float8_e5m2: torch.float16,
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
__all__ = [
|
|
16
|
+
"default_integer_dtype",
|
|
17
|
+
"default_floating_dtype",
|
|
18
|
+
"default_boolean_dtype",
|
|
19
|
+
"is_backendarray",
|
|
20
|
+
"from_numpy",
|
|
21
|
+
"from_other_backend",
|
|
22
|
+
"to_numpy",
|
|
23
|
+
"to_dlpack",
|
|
24
|
+
"dtype_is_real_integer",
|
|
25
|
+
"dtype_is_real_floating",
|
|
26
|
+
"dtype_is_boolean",
|
|
27
|
+
"abbreviate_array",
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
default_integer_dtype = torch.int32
|
|
31
|
+
default_floating_dtype = torch.float32
|
|
32
|
+
default_boolean_dtype = torch.bool
|
|
33
|
+
|
|
34
|
+
def is_backendarray(data : Any) -> bool:
|
|
35
|
+
return isinstance(data, torch.Tensor)
|
|
36
|
+
|
|
37
|
+
def from_numpy(
|
|
38
|
+
data : np.ndarray,
|
|
39
|
+
/,
|
|
40
|
+
*,
|
|
41
|
+
dtype : Optional[DTYPE_TYPE] = None,
|
|
42
|
+
device : Optional[DEVICE_TYPE] = None
|
|
43
|
+
) -> ARRAY_TYPE:
|
|
44
|
+
t = torch.from_numpy(data)
|
|
45
|
+
target_dtype = dtype if dtype is not None else PYTORCH_DTYPE_CAST_MAP.get(t.dtype, t.dtype)
|
|
46
|
+
if target_dtype is not None or device is not None:
|
|
47
|
+
t = t.to(device=device, dtype=target_dtype)
|
|
48
|
+
return t
|
|
49
|
+
|
|
50
|
+
def from_other_backend(
|
|
51
|
+
other_backend: ComputeBackend,
|
|
52
|
+
data: Any,
|
|
53
|
+
/,
|
|
54
|
+
) -> ARRAY_TYPE:
|
|
55
|
+
dat_dlpack = other_backend.to_dlpack(data)
|
|
56
|
+
return torch.from_dlpack(dat_dlpack)
|
|
57
|
+
|
|
58
|
+
def to_numpy(
|
|
59
|
+
data : ARRAY_TYPE
|
|
60
|
+
) -> np.ndarray:
|
|
61
|
+
# Torch bfloat16 is not supported by numpy
|
|
62
|
+
if data.dtype == torch.bfloat16:
|
|
63
|
+
data = data.to(torch.float32)
|
|
64
|
+
return data.cpu().numpy()
|
|
65
|
+
|
|
66
|
+
def to_dlpack(
|
|
67
|
+
self,
|
|
68
|
+
data: ARRAY_TYPE,
|
|
69
|
+
/,
|
|
70
|
+
) -> SupportsDLPack:
|
|
71
|
+
return data
|
|
72
|
+
|
|
73
|
+
def dtype_is_real_integer(
|
|
74
|
+
dtype: DTYPE_TYPE
|
|
75
|
+
) -> bool:
|
|
76
|
+
# https://pytorch.org/docs/stable/tensors.html#id12
|
|
77
|
+
return dtype in [
|
|
78
|
+
torch.int8, torch.int16, torch.int32, torch.int64,
|
|
79
|
+
torch.uint8,
|
|
80
|
+
torch.int,
|
|
81
|
+
torch.long
|
|
82
|
+
]
|
|
83
|
+
|
|
84
|
+
def dtype_is_real_floating(
|
|
85
|
+
dtype: DTYPE_TYPE
|
|
86
|
+
) -> bool:
|
|
87
|
+
return dtype in [
|
|
88
|
+
torch.float16, torch.float32, torch.float64,
|
|
89
|
+
torch.float, torch.double,
|
|
90
|
+
torch.bfloat16
|
|
91
|
+
]
|
|
92
|
+
|
|
93
|
+
def dtype_is_boolean(
|
|
94
|
+
dtype: DTYPE_TYPE
|
|
95
|
+
) -> bool:
|
|
96
|
+
return dtype == torch.bool
|
|
97
|
+
|
|
98
|
+
from xbarray.common.implementations import get_abbreviate_array_function, get_map_fn_over_arrays_function
|
|
99
|
+
from array_api_compat import torch as compat_module
|
|
100
|
+
abbreviate_array = get_abbreviate_array_function(
|
|
101
|
+
compat_module,
|
|
102
|
+
default_integer_dtype=default_integer_dtype,
|
|
103
|
+
func_dtype_is_real_floating=dtype_is_real_floating,
|
|
104
|
+
func_dtype_is_real_integer=dtype_is_real_integer,
|
|
105
|
+
func_dtype_is_boolean=dtype_is_boolean
|
|
106
|
+
)
|
|
107
|
+
map_fn_over_arrays = get_map_fn_over_arrays_function(
|
|
108
|
+
is_backendarray=is_backendarray,
|
|
109
|
+
)
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
from typing import Union, Optional, Tuple, Any
|
|
2
|
+
from ._typing import ARRAY_TYPE, DTYPE_TYPE, DEVICE_TYPE, RNG_TYPE
|
|
3
|
+
import torch
|
|
4
|
+
|
|
5
|
+
__all__ = [
|
|
6
|
+
"random_number_generator",
|
|
7
|
+
"random_discrete_uniform",
|
|
8
|
+
"random_uniform",
|
|
9
|
+
"random_exponential",
|
|
10
|
+
"random_normal",
|
|
11
|
+
"random_geometric",
|
|
12
|
+
"random_permutation"
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
def random_number_generator(
|
|
16
|
+
seed : Optional[int] = None,
|
|
17
|
+
*,
|
|
18
|
+
device : Optional[DEVICE_TYPE] = None
|
|
19
|
+
) -> RNG_TYPE:
|
|
20
|
+
rng = torch.Generator(
|
|
21
|
+
device=device
|
|
22
|
+
)
|
|
23
|
+
if seed is not None:
|
|
24
|
+
rng = rng.manual_seed(seed)
|
|
25
|
+
return rng
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def random_discrete_uniform(
|
|
29
|
+
shape : Union[int, Tuple[int, ...]],
|
|
30
|
+
from_num : int,
|
|
31
|
+
to_num : int,
|
|
32
|
+
/,
|
|
33
|
+
*,
|
|
34
|
+
rng : RNG_TYPE,
|
|
35
|
+
dtype : Optional[DTYPE_TYPE] = None,
|
|
36
|
+
device : Optional[DEVICE_TYPE] = None
|
|
37
|
+
) -> Tuple[RNG_TYPE, ARRAY_TYPE]:
|
|
38
|
+
t = torch.randint(int(from_num), int(to_num), shape, generator=rng, dtype=dtype, device=device)
|
|
39
|
+
return rng, t
|
|
40
|
+
|
|
41
|
+
def random_uniform(
|
|
42
|
+
shape: Union[int, Tuple[int, ...]],
|
|
43
|
+
/,
|
|
44
|
+
*,
|
|
45
|
+
rng : RNG_TYPE,
|
|
46
|
+
low : float = 0.0, high : float = 1.0,
|
|
47
|
+
dtype : Optional[DTYPE_TYPE] = None,
|
|
48
|
+
device : Optional[DEVICE_TYPE] = None
|
|
49
|
+
) -> Tuple[RNG_TYPE, ARRAY_TYPE]:
|
|
50
|
+
t = torch.rand(shape, generator=rng, dtype=dtype, device=device)
|
|
51
|
+
t = t * (high - low) + low
|
|
52
|
+
return rng, t
|
|
53
|
+
|
|
54
|
+
def random_exponential(
|
|
55
|
+
shape: Union[int, Tuple[int, ...]],
|
|
56
|
+
/,
|
|
57
|
+
*,
|
|
58
|
+
rng : RNG_TYPE,
|
|
59
|
+
lambd : float = 1.0,
|
|
60
|
+
dtype : Optional[DTYPE_TYPE] = None,
|
|
61
|
+
device : Optional[DEVICE_TYPE] = None
|
|
62
|
+
) -> Tuple[RNG_TYPE, ARRAY_TYPE]:
|
|
63
|
+
t = torch.empty(shape, dtype=dtype, device=device)
|
|
64
|
+
t = t.exponential_(lambd, generator=rng)
|
|
65
|
+
return rng, t
|
|
66
|
+
|
|
67
|
+
@classmethod
|
|
68
|
+
def random_normal(
|
|
69
|
+
shape: Union[int, Tuple[int, ...]],
|
|
70
|
+
/,
|
|
71
|
+
*,
|
|
72
|
+
rng : RNG_TYPE,
|
|
73
|
+
mean : float = 0.0, std : float = 1.0,
|
|
74
|
+
dtype : Optional[DTYPE_TYPE] = None,
|
|
75
|
+
device : Optional[Any] = None
|
|
76
|
+
) -> Tuple[RNG_TYPE, ARRAY_TYPE]:
|
|
77
|
+
t = torch.normal(mean, std, shape, generator=rng, dtype=dtype, device=device)
|
|
78
|
+
return rng, t
|
|
79
|
+
|
|
80
|
+
def random_geometric(
|
|
81
|
+
shape: Union[int, Tuple[int, ...]],
|
|
82
|
+
/,
|
|
83
|
+
*,
|
|
84
|
+
p: float,
|
|
85
|
+
rng: RNG_TYPE,
|
|
86
|
+
dtype: Optional[DTYPE_TYPE] = None,
|
|
87
|
+
device: Optional[Any] = None
|
|
88
|
+
) -> Tuple[RNG_TYPE, ARRAY_TYPE]:
|
|
89
|
+
t = torch.empty(shape, dtype=dtype, device=device)
|
|
90
|
+
t = t.geometric_(p, generator=rng)
|
|
91
|
+
return rng, t
|
|
92
|
+
|
|
93
|
+
def random_permutation(
|
|
94
|
+
n : int,
|
|
95
|
+
/,
|
|
96
|
+
*,
|
|
97
|
+
rng: RNG_TYPE,
|
|
98
|
+
dtype: Optional[DTYPE_TYPE] = None,
|
|
99
|
+
device: Optional[DEVICE_TYPE] = None
|
|
100
|
+
) -> Tuple[RNG_TYPE, ARRAY_TYPE]:
|
|
101
|
+
t = torch.randperm(n, generator=rng, dtype=dtype, device=device)
|
|
102
|
+
return rng, t
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: xbarray
|
|
3
|
+
Version: 0.0.1a1
|
|
4
|
+
Requires-Python: >=3.10
|
|
5
|
+
License-File: LICENSE
|
|
6
|
+
Requires-Dist: typing_extensions>=4.5
|
|
7
|
+
Requires-Dist: array_api_compat
|
|
8
|
+
Requires-Dist: array_api_extra
|
|
9
|
+
Requires-Dist: numpy
|
|
10
|
+
Provides-Extra: torch
|
|
11
|
+
Requires-Dist: torch; extra == "torch"
|
|
12
|
+
Provides-Extra: jax
|
|
13
|
+
Requires-Dist: jax; extra == "jax"
|
|
14
|
+
Dynamic: license-file
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
array_api_typing/__init__.py,sha256=5vcE63PsZ_utc7j2VmLK5evUhar-942p95HyjTiLOc0,179
|
|
2
|
+
array_api_typing/typing_2024_12/__init__.py,sha256=JuD2yojHl3eQI74U75tFhSX5rSy32TR5nKyi714ZfX4,347
|
|
3
|
+
array_api_typing/typing_2024_12/_api_constant.py,sha256=tahdzdi7vAZ3UnM8oDcUqvx2FFsMTAyUbuwgarU6K9U,676
|
|
4
|
+
array_api_typing/typing_2024_12/_api_fft_typing.py,sha256=i48S-9trw3s72xiCJmeCNGlJLwwOVq0kJC4lD9se_co,38641
|
|
5
|
+
array_api_typing/typing_2024_12/_api_linalg_typing.py,sha256=Dt5fDTwYb-GAmP7duajwPqH3zaJmwvxDEOOzdl5X0LE,48950
|
|
6
|
+
array_api_typing/typing_2024_12/_api_return_typing.py,sha256=7TxSBRv0H0uQ9VnixbyuEXJQnl1uESo102RsAloI9SA,2302
|
|
7
|
+
array_api_typing/typing_2024_12/_api_typing.py,sha256=rFuF7E6b2RrijzQBrZx6_dYEn9Yslq8FqI31L1Ccrf4,294255
|
|
8
|
+
array_api_typing/typing_2024_12/_array_typing.py,sha256=GMqs5LgshujRIh7i0mGtZy4Vt56FSXqBmNlBGidFRnc,57403
|
|
9
|
+
array_api_typing/typing_compat/__init__.py,sha256=JuD2yojHl3eQI74U75tFhSX5rSy32TR5nKyi714ZfX4,347
|
|
10
|
+
array_api_typing/typing_compat/_api_typing.py,sha256=RnGZFD8AEIqOCurcI68xyw7y9W9hm4yWUGf7NlJkNk0,930
|
|
11
|
+
array_api_typing/typing_compat/_array_typing.py,sha256=CVv91wDjjG-8kSofkqgA85qpM-3x34Zh_SNuBFegW9o,1182
|
|
12
|
+
array_api_typing/typing_extra/__init__.py,sha256=YfdhD-Sfk3SCfI9lHmA-PbVLzms1OFF5x0ekzI3aafk,323
|
|
13
|
+
array_api_typing/typing_extra/_api_typing.py,sha256=Jj_E61r35EgecWmBvAzpASV4qub5aQI_O4aL-ngEvQ8,23028
|
|
14
|
+
array_api_typing/typing_extra/_at.py,sha256=S7_YjOwR3a8olZWgwpLDFEfnekRufRqrtfiMLwrWjgo,2202
|
|
15
|
+
xbarray/__init__.py,sha256=GLdMGsm5_CnATyh19At20Hmb1MsXZvPxNvg70bHYChk,19
|
|
16
|
+
xbarray/base/__init__.py,sha256=ERmmOxz_9mUkIuccNbzUa5Y6gVLLVDdyc4cCxbCCUbY,20
|
|
17
|
+
xbarray/base/base.py,sha256=hqlizpZOJua9xJfPfc-RR6IAadp-OLPVnBO5cbVVHKQ,5929
|
|
18
|
+
xbarray/common/implementations.py,sha256=FyZaQZcVdSnH6CUA1LVbUJAK-EAlkz2fDfOOuVyku6Y,2655
|
|
19
|
+
xbarray/jax/__init__.py,sha256=J7yN6ytn1fm2qKHZVm9OTt30ItcKMnKnuTxbZgnGKaE,662
|
|
20
|
+
xbarray/jax/_extra.py,sha256=JHZBaGZUXPLCRFdaDBXUjwGD-D4DlLYI0NsxAlGs3FE,2504
|
|
21
|
+
xbarray/jax/_typing.py,sha256=U9BUxHNEjFB0LHF1KMrFLbh6E5kVvpAF8bZUbLNf25E,278
|
|
22
|
+
xbarray/jax/random.py,sha256=owIxqs67MOMXaMN8uwmCu9aLd1Yss24sl9rib4R5Qec,3325
|
|
23
|
+
xbarray/numpy/__init__.py,sha256=trZhNZYIHe0QkQYRB1ZJW-OlteYf_9RVUR3yks6S2iI,523
|
|
24
|
+
xbarray/numpy/_extra.py,sha256=wbzpcVL4UV5TVQlmO73sUwWcBgMiVXFvfCLlCuiB0Uk,1982
|
|
25
|
+
xbarray/numpy/_typing.py,sha256=pgjLLAipwFsIk0QdgrAA4PEvjF_ugHbzfSTbLpA__6o,241
|
|
26
|
+
xbarray/numpy/random.py,sha256=8BaxX_cpzvF7iG0yR0ws3IbG14OJPsX60Gv-1AStplA,2643
|
|
27
|
+
xbarray/pytorch/__init__.py,sha256=wfUkSyrJpDlO2Zggza7HM5SCdYKUBfySO3K71itOHkA,526
|
|
28
|
+
xbarray/pytorch/_extra.py,sha256=VawcjDe0dxiIzvTjIncGxwPPoTw7hWZAPOlZSdDSKl0,2867
|
|
29
|
+
xbarray/pytorch/_typing.py,sha256=qSnNZD3IpgSoOTl3TBRBv2ifSAHOw0aR9uyzfV5KYVw,204
|
|
30
|
+
xbarray/pytorch/random.py,sha256=OJ-YvS2owX5LWdsIzXW-N2YqPhN84Rroco7O5qIMmrg,2670
|
|
31
|
+
xbarray-0.0.1a1.dist-info/licenses/LICENSE,sha256=6P0HCOancSfch0dNycuDIe8_qwS0Id97Ih_8hjJ2PFI,1067
|
|
32
|
+
xbarray-0.0.1a1.dist-info/METADATA,sha256=u2-YoX051dU1Po1mFspLSuIEMmlPdhlWOlNwvbp-8PE,359
|
|
33
|
+
xbarray-0.0.1a1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
34
|
+
xbarray-0.0.1a1.dist-info/top_level.txt,sha256=VriXuFyU48Du4HQMzROSArhwqB6EZYY0n0mipgUqB9A,25
|
|
35
|
+
xbarray-0.0.1a1.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Yunhao Cao
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|