0
# NumPy Integration
1
2
Distributed array computing with NumPy-compatible API. Xorbits numpy enables computation on large distributed arrays that exceed single-machine memory while maintaining full compatibility with the NumPy API.
3
4
## Capabilities
5
6
### Core Array Class
7
8
The fundamental distributed array class that mirrors numpy.ndarray functionality.
9
10
```python { .api }
11
class ndarray:
12
"""
13
Distributed array with numpy-compatible API.
14
15
N-dimensional array object that supports all NumPy operations
16
with automatic distribution across multiple workers for
17
scalable array computing.
18
"""
19
```
20
21
### Data Types
22
23
All NumPy data types are available for creating and working with distributed arrays.
24
25
```python { .api }
26
# Boolean types
27
bool_: type # Boolean type
28
29
# Integer types
30
int8: type # 8-bit signed integer
31
int16: type # 16-bit signed integer
32
int32: type # 32-bit signed integer
33
int64: type # 64-bit signed integer
34
int_: type # Default integer type
35
intc: type # C integer type
36
intp: type # Pointer-sized integer
37
38
uint8: type # 8-bit unsigned integer
39
uint16: type # 16-bit unsigned integer
40
uint32: type # 32-bit unsigned integer
41
uint64: type # 64-bit unsigned integer
42
uint: type # Unsigned integer
43
44
# Floating point types
45
float16: type # 16-bit floating point
46
float32: type # 32-bit floating point
47
float64: type # 64-bit floating point
48
double: type # Double precision floating point
49
floating: type # Floating point type
50
51
# Complex types
52
complex64: type # 64-bit complex type
53
complex128: type # 128-bit complex type
54
complexfloating: type # Complex floating point type
55
56
# String and character types
57
bytes_: type # Bytes type
58
str_: type # String type
59
character: type # Character type
60
61
# Date and time types
62
datetime64: type # 64-bit datetime type
63
timedelta64: type # Time delta type
64
65
# Other types
66
object_: type # Object type
67
void: type # Void type
68
flexible: type # Flexible type
69
generic: type # Generic numpy type
70
inexact: type # Inexact numeric type
71
number: type # Number type
72
signedinteger: type # Signed integer type
73
unsignedinteger: type # Unsigned integer type
74
75
# Type information classes
76
dtype: type # Data type class
77
finfo: type # Floating point type information
78
```
79
80
### Constants
81
82
Mathematical and special constants from NumPy.
83
84
```python { .api }
85
pi: float # Pi constant (3.14159...)
86
e: float # Euler's number (2.71828...)
87
inf: float # Positive infinity
88
nan: float # Not a Number
89
newaxis: object # New axis constant for array indexing
90
```
91
92
### Utility Classes
93
94
Classes for advanced array operations and error handling.
95
96
```python { .api }
97
class errstate:
98
"""Error state context manager for controlling floating-point error handling."""
99
100
class ndindex:
101
"""Multi-dimensional index iterator for arrays."""
102
103
# Exceptions
104
class AxisError(Exception):
105
"""Exception raised for axis-related errors."""
106
```
107
108
### Submodules
109
110
Specialized NumPy functionality through submodules.
111
112
```python { .api }
113
# Submodules providing specialized functionality
114
fft # Fast Fourier Transform functions
115
linalg # Linear algebra functions
116
random # Random number generation
117
special # Special mathematical functions
118
```
119
120
### Dynamic Function Access
121
122
All NumPy functions are available through dynamic import, including but not limited to:
123
124
```python { .api }
125
# Array creation functions
126
def array(object, dtype=None, **kwargs): ...
127
def zeros(shape, dtype=float, **kwargs): ...
128
def ones(shape, dtype=None, **kwargs): ...
129
def empty(shape, dtype=float, **kwargs): ...
130
def full(shape, fill_value, dtype=None, **kwargs): ...
131
def arange(start, stop=None, step=1, dtype=None, **kwargs): ...
132
def linspace(start, stop, num=50, **kwargs): ...
133
def logspace(start, stop, num=50, **kwargs): ...
134
def eye(N, M=None, k=0, dtype=float, **kwargs): ...
135
def identity(n, dtype=None, **kwargs): ...
136
137
# Array manipulation functions
138
def reshape(a, newshape, **kwargs): ...
139
def flatten(a, **kwargs): ...
140
def ravel(a, **kwargs): ...
141
def transpose(a, axes=None): ...
142
def concatenate(arrays, axis=0, **kwargs): ...
143
def stack(arrays, axis=0, **kwargs): ...
144
def split(ary, indices_or_sections, axis=0): ...
145
def squeeze(a, axis=None): ...
146
def expand_dims(a, axis): ...
147
148
# Mathematical functions
149
def add(x1, x2, **kwargs): ...
150
def subtract(x1, x2, **kwargs): ...
151
def multiply(x1, x2, **kwargs): ...
152
def divide(x1, x2, **kwargs): ...
153
def power(x1, x2, **kwargs): ...
154
def sqrt(x, **kwargs): ...
155
def exp(x, **kwargs): ...
156
def log(x, **kwargs): ...
157
def sin(x, **kwargs): ...
158
def cos(x, **kwargs): ...
159
def tan(x, **kwargs): ...
160
161
# Statistical functions
162
def mean(a, axis=None, **kwargs): ...
163
def median(a, axis=None, **kwargs): ...
164
def std(a, axis=None, **kwargs): ...
165
def var(a, axis=None, **kwargs): ...
166
def sum(a, axis=None, **kwargs): ...
167
def min(a, axis=None, **kwargs): ...
168
def max(a, axis=None, **kwargs): ...
169
def argmin(a, axis=None, **kwargs): ...
170
def argmax(a, axis=None, **kwargs): ...
171
172
# Logical functions
173
def all(a, axis=None, **kwargs): ...
174
def any(a, axis=None, **kwargs): ...
175
def logical_and(x1, x2, **kwargs): ...
176
def logical_or(x1, x2, **kwargs): ...
177
def logical_not(x, **kwargs): ...
178
def where(condition, x=None, y=None): ...
179
180
# Sorting and searching
181
def sort(a, axis=-1, **kwargs): ...
182
def argsort(a, axis=-1, **kwargs): ...
183
def searchsorted(a, v, **kwargs): ...
184
def unique(ar, **kwargs): ...
185
186
# Input/output functions
187
def save(file, arr, **kwargs): ...
188
def load(file, **kwargs): ...
189
def savetxt(fname, X, **kwargs): ...
190
def loadtxt(fname, **kwargs): ...
191
```
192
193
**Usage Examples:**
194
195
```python
196
import xorbits
197
import xorbits.numpy as np
198
199
xorbits.init()
200
201
# Array creation (same as NumPy)
202
arr = np.array([1, 2, 3, 4, 5])
203
zeros_arr = np.zeros((1000, 1000))
204
ones_arr = np.ones((500, 500))
205
random_arr = np.random.random((1000, 1000))
206
207
# Mathematical operations (same as NumPy)
208
result = np.sqrt(arr + 10)
209
matrix_mult = np.dot(zeros_arr, ones_arr)
210
211
# Statistical operations
212
mean_val = np.mean(random_arr)
213
std_val = np.std(random_arr, axis=0)
214
215
# Array manipulation
216
reshaped = np.reshape(arr, (5, 1))
217
transposed = np.transpose(matrix_mult)
218
219
# All NumPy operations work the same way
220
complex_result = np.fft.fft(np.sin(np.linspace(0, 2*np.pi, 1000)))
221
222
# Execute computation
223
computed = xorbits.run(complex_result)
224
225
xorbits.shutdown()
226
```
227
228
### Linear Algebra Examples
229
230
```python
231
import xorbits.numpy as np
232
import xorbits
233
234
xorbits.init()
235
236
# Matrix operations
237
A = np.random.random((1000, 1000))
238
B = np.random.random((1000, 1000))
239
240
# Linear algebra operations
241
dot_product = np.dot(A, B)
242
eigenvals = np.linalg.eigvals(A)
243
determinant = np.linalg.det(A)
244
inverse = np.linalg.inv(A)
245
246
# Execute computations
247
results = xorbits.run(dot_product, eigenvals, determinant)
248
249
xorbits.shutdown()
250
```
251
252
### FFT Examples
253
254
```python
255
import xorbits.numpy as np
256
import xorbits
257
258
xorbits.init()
259
260
# Signal processing with FFT
261
signal = np.sin(2 * np.pi * np.linspace(0, 1, 10000))
262
fft_result = np.fft.fft(signal)
263
frequencies = np.fft.fftfreq(len(signal))
264
265
# Execute computation
266
computed_fft = xorbits.run(fft_result)
267
268
xorbits.shutdown()
269
```