cohere-core 4.3__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.
@@ -0,0 +1,361 @@
1
+ # #########################################################################
2
+ # Copyright (c) , UChicago Argonne, LLC. All rights reserved. #
3
+ # #
4
+ # See LICENSE file. #
5
+ # #########################################################################
6
+
7
+ from cohere_core.lib.cohlib import cohlib
8
+ import numpy as np
9
+ import scipy.fft as fft
10
+ import scipy.ndimage as ndi
11
+ import scipy.signal as sig
12
+ import scipy.stats as stats
13
+
14
+ class nplib(cohlib):
15
+ @staticmethod
16
+ def array(obj):
17
+ return np.array(obj)
18
+
19
+ @staticmethod
20
+ def dot(arr1, arr2):
21
+ return np.dot(arr1, arr2)
22
+
23
+ @staticmethod
24
+ def cross(arr1, arr2):
25
+ return np.cross(arr1, arr2)
26
+
27
+ @staticmethod
28
+ def set_device(dev_id):
29
+ pass
30
+
31
+ @staticmethod
32
+ def set_backend(proc):
33
+ pass
34
+
35
+ @staticmethod
36
+ def to_numpy(arr):
37
+ return arr
38
+
39
+ @staticmethod
40
+ def load(filename):
41
+ return np.load(filename)
42
+
43
+ @staticmethod
44
+ def from_numpy(arr):
45
+ return arr
46
+
47
+ @staticmethod
48
+ def save(filename, arr):
49
+ np.save(filename, arr)
50
+
51
+ @staticmethod
52
+ def dtype(arr):
53
+ return arr.dtype
54
+
55
+ @staticmethod
56
+ def astype(arr, dtype):
57
+ return arr.astype(dtype=dtype)
58
+
59
+ @staticmethod
60
+ def reshape(arr, shape):
61
+ return np.reshape(arr, shape)
62
+
63
+ @staticmethod
64
+ def size(arr):
65
+ return arr.size
66
+
67
+ @staticmethod
68
+ def next_fast_len(target):
69
+ return fft.next_fast_len(target)
70
+
71
+ @staticmethod
72
+ def nan_to_num(arr, **kwargs):
73
+ return np.nan_to_num(arr, **kwargs)
74
+
75
+ @staticmethod
76
+ def hasnan(arr):
77
+ return np.any(np.isnan(arr))
78
+
79
+ @staticmethod
80
+ def copy(arr):
81
+ return np.copy(arr)
82
+
83
+ @staticmethod
84
+ def random(shape, **kwargs):
85
+ import time
86
+ import os
87
+
88
+ # return np.random.rand(*shape)
89
+ #rng = np.random.default_rng((int(time.time()* 10000000) + os.getpid()))
90
+ np.random.seed((int(time.time() * os.getpid()) + os.getpid()) % 2**31)
91
+ r = np.random.rand(*shape)
92
+ return r
93
+ #return rng.random(*shape).astype(float)
94
+
95
+ @staticmethod
96
+ def roll(arr, sft, axis=None):
97
+ if type(sft) != list:
98
+ sft = [sft]
99
+ if axis is None:
100
+ axis = list(range(len(sft)))
101
+ sft = [int(s) for s in sft]
102
+ return np.roll(arr, sft, axis=axis)
103
+
104
+ @staticmethod
105
+ def shift(arr, sft):
106
+ return ndi.shift(arr, sft)
107
+
108
+ @staticmethod
109
+ def fftshift(arr):
110
+ return np.fft.fftshift(arr)
111
+
112
+ @staticmethod
113
+ def ifftshift(arr):
114
+ return np.fft.ifftshift(arr)
115
+
116
+ @staticmethod
117
+ def fft(arr):
118
+ return fft.fftn(arr, norm='forward')
119
+
120
+ @staticmethod
121
+ def ifft(arr):
122
+ return fft.ifftn(arr, norm='forward')
123
+
124
+ @staticmethod
125
+ def fftconvolve(arr1, kernel):
126
+ return sig.fftconvolve(arr1, kernel, mode='same')
127
+
128
+ @staticmethod
129
+ def correlate(arr1, arr2, mode='same', method='auto'):
130
+ return sig.correlate(arr1, arr2, mode, method)
131
+
132
+ @staticmethod
133
+ def where(cond, x, y):
134
+ return np.where(cond, x, y)
135
+
136
+ @staticmethod
137
+ def dims(arr):
138
+ # get array dimensions
139
+ return arr.shape
140
+
141
+ @staticmethod
142
+ def absolute(arr):
143
+ return np.absolute(arr)
144
+
145
+ @staticmethod
146
+ def sqrt(arr):
147
+ return np.sqrt(arr)
148
+
149
+ @staticmethod
150
+ def square(arr):
151
+ return np.square(arr)
152
+
153
+ @staticmethod
154
+ def sum(arr, axis=None):
155
+ return np.sum(arr, axis)
156
+
157
+ @staticmethod
158
+ def real(arr):
159
+ return np.real(arr)
160
+
161
+ @staticmethod
162
+ def imag(arr):
163
+ return np.imag(arr)
164
+
165
+ @staticmethod
166
+ def amax(arr):
167
+ return np.amax(arr)
168
+
169
+ @staticmethod
170
+ def unravel_index(indices, shape):
171
+ return np.unravel_index(indices, shape)
172
+
173
+ @staticmethod
174
+ def ravel(arr):
175
+ return np.ravel(arr)
176
+
177
+ @staticmethod
178
+ def maximum(arr1, arr2):
179
+ return np.maximum(arr1, arr2)
180
+
181
+ @staticmethod
182
+ def argmax(arr, axis=None):
183
+ return np.argmax(arr, axis)
184
+
185
+ @staticmethod
186
+ def ceil(arr):
187
+ return np.ceil(arr)
188
+
189
+ @staticmethod
190
+ def fix(arr):
191
+ return np.fix(arr)
192
+
193
+ @staticmethod
194
+ def round(val):
195
+ return np.round(val)
196
+
197
+ @staticmethod
198
+ def print(arr, **kwargs):
199
+ print(arr)
200
+
201
+ @staticmethod
202
+ def angle(arr):
203
+ return np.angle(arr)
204
+
205
+ @staticmethod
206
+ def flip(arr, axis=None):
207
+ return np.flip(arr, axis)
208
+
209
+ @staticmethod
210
+ def tile(arr, rep):
211
+ return np.tile(arr, rep)
212
+
213
+ @staticmethod
214
+ def full(shape, fill_value, **kwargs):
215
+ return np.full(shape, fill_value)
216
+
217
+ @staticmethod
218
+ def expand_dims(arr, axis):
219
+ return np.expand_dims(arr, axis)
220
+
221
+ @staticmethod
222
+ def squeeze(arr):
223
+ return np.squeeze(arr)
224
+
225
+ @staticmethod
226
+ def entropy(arr):
227
+ return stats.entropy(arr)
228
+
229
+ @staticmethod
230
+ def gaussian_filter(arr, sigma, **kwargs):
231
+ return ndi.gaussian_filter(arr, sigma, **kwargs)
232
+
233
+ @staticmethod
234
+ def median_filter(arr, size, **kwargs):
235
+ return ndi.median_filter(arr, size)
236
+
237
+ @staticmethod
238
+ def uniform_filter(arr, size, **kwargs):
239
+ return ndi.uniform_filter(arr, size)
240
+
241
+ @staticmethod
242
+ def binary_erosion(arr, **kwargs):
243
+ return ndi.binary_erosion(arr, iterations=1)
244
+
245
+ @staticmethod
246
+ def center_of_mass(inarr):
247
+ return ndi.center_of_mass(np.absolute(inarr))
248
+
249
+ @staticmethod
250
+ def meshgrid(*xi):
251
+ return np.meshgrid(*xi)
252
+
253
+ @staticmethod
254
+ def exp(arr):
255
+ return np.exp(arr)
256
+
257
+ @staticmethod
258
+ def conj(arr):
259
+ return np.conj(arr)
260
+
261
+ @staticmethod
262
+ def array_equal(arr1, arr2):
263
+ return np.array_equal(arr1, arr2)
264
+
265
+ @staticmethod
266
+ def cos(arr):
267
+ return np.cos(arr)
268
+
269
+ @staticmethod
270
+ def linspace(start, stop, num):
271
+ return np.linspace(start, stop, num)
272
+
273
+ @staticmethod
274
+ def geomspace(start, stop, num):
275
+ return np.geomspace(start, stop, num)
276
+
277
+ @staticmethod
278
+ def clip(arr, min, max=None):
279
+ return np.clip(arr, min, max)
280
+
281
+ @staticmethod
282
+ def diff(arr, axis=None, prepend=0):
283
+ return np.diff(arr, axis=axis, prepend=prepend)
284
+
285
+ @staticmethod
286
+ def gradient(arr, dx=1):
287
+ return np.gradient(arr, dx)
288
+
289
+ @staticmethod
290
+ def argmin(arr, axis=None):
291
+ return np.argmin(arr, axis)
292
+
293
+ @staticmethod
294
+ def take_along_axis(a, indices, axis):
295
+ return np.take_along_axis(a, indices, axis)
296
+
297
+ @staticmethod
298
+ def moveaxis(arr, source, dest):
299
+ return np.moveaxis(arr, source, dest)
300
+
301
+ @staticmethod
302
+ def lstsq(A, B):
303
+ return np.linalg.lstsq(A, B, rcond=None)
304
+
305
+ @staticmethod
306
+ def zeros(shape):
307
+ return np.zeros(shape)
308
+
309
+ @staticmethod
310
+ def indices(dims):
311
+ return np.indices(dims)
312
+
313
+ @staticmethod
314
+ def concatenate(tup, axis=0):
315
+ return np.concatenate(tup, axis)
316
+
317
+ @staticmethod
318
+ def stack(tup):
319
+ return np.stack(tup)
320
+
321
+ @staticmethod
322
+ def amin(arr):
323
+ return np.amin(arr)
324
+
325
+ @staticmethod
326
+ def affine_transform(arr, matrix, order=3, offset=0):
327
+ return ndi.affine_transform(arr, matrix, order=order, offset=offset, prefilter=True)
328
+
329
+ @staticmethod
330
+ def pad(arr, padding):
331
+ return np.pad(arr, padding)
332
+
333
+ @staticmethod
334
+ def histogram2d(arr1, arr2, bins):
335
+ return np.histogram2d(np.ravel(arr1), np.ravel(arr2), bins)[0]
336
+
337
+ @staticmethod
338
+ def log(arr):
339
+ return np.log(arr)
340
+
341
+ @staticmethod
342
+ def log10(arr):
343
+ return np.log10(arr)
344
+
345
+ @staticmethod
346
+ def xlogy(x, y=None):
347
+ if y is None:
348
+ y = x
349
+ return np.xlogy(x, y)
350
+
351
+ @staticmethod
352
+ def mean(arr):
353
+ return np.mean(arr)
354
+
355
+ @staticmethod
356
+ def median(arr):
357
+ return np.median(arr)
358
+
359
+ @staticmethod
360
+ def clean_default_mem():
361
+ pass