gpuarray 0.2.0__tar.gz → 0.4.0__tar.gz
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.
- {gpuarray-0.2.0 → gpuarray-0.4.0}/PKG-INFO +1 -1
- {gpuarray-0.2.0 → gpuarray-0.4.0}/gpuarray/__init__.py +8 -0
- {gpuarray-0.2.0 → gpuarray-0.4.0}/gpuarray/api.py +35 -1
- gpuarray-0.4.0/gpuarray/core.py +955 -0
- {gpuarray-0.2.0 → gpuarray-0.4.0}/gpuarray/shaders.py +507 -19
- {gpuarray-0.2.0 → gpuarray-0.4.0}/gpuarray.egg-info/PKG-INFO +1 -1
- {gpuarray-0.2.0 → gpuarray-0.4.0}/pyproject.toml +1 -1
- {gpuarray-0.2.0 → gpuarray-0.4.0}/tests/test_core.py +186 -1
- gpuarray-0.2.0/gpuarray/core.py +0 -501
- {gpuarray-0.2.0 → gpuarray-0.4.0}/README.md +0 -0
- {gpuarray-0.2.0 → gpuarray-0.4.0}/gpuarray/device.py +0 -0
- {gpuarray-0.2.0 → gpuarray-0.4.0}/gpuarray.egg-info/SOURCES.txt +0 -0
- {gpuarray-0.2.0 → gpuarray-0.4.0}/gpuarray.egg-info/dependency_links.txt +0 -0
- {gpuarray-0.2.0 → gpuarray-0.4.0}/gpuarray.egg-info/requires.txt +0 -0
- {gpuarray-0.2.0 → gpuarray-0.4.0}/gpuarray.egg-info/top_level.txt +0 -0
- {gpuarray-0.2.0 → gpuarray-0.4.0}/setup.cfg +0 -0
|
@@ -27,6 +27,10 @@ from .api import (
|
|
|
27
27
|
concatenate,
|
|
28
28
|
stack,
|
|
29
29
|
random,
|
|
30
|
+
fft,
|
|
31
|
+
ifft,
|
|
32
|
+
fft_freq,
|
|
33
|
+
fft_magnitude,
|
|
30
34
|
)
|
|
31
35
|
|
|
32
36
|
__version__ = "0.1.0"
|
|
@@ -58,4 +62,8 @@ __all__ = [
|
|
|
58
62
|
"concatenate",
|
|
59
63
|
"stack",
|
|
60
64
|
"random",
|
|
65
|
+
"fft",
|
|
66
|
+
"ifft",
|
|
67
|
+
"fft_freq",
|
|
68
|
+
"fft_magnitude",
|
|
61
69
|
]
|
|
@@ -6,7 +6,7 @@ from typing import Sequence
|
|
|
6
6
|
|
|
7
7
|
import numpy as np
|
|
8
8
|
|
|
9
|
-
from .core import GPUArray, _from_numpy, matmul as _matmul
|
|
9
|
+
from .core import GPUArray, _from_numpy, matmul as _matmul, _complex_magnitude
|
|
10
10
|
from . import shaders
|
|
11
11
|
|
|
12
12
|
|
|
@@ -180,3 +180,37 @@ class _Random:
|
|
|
180
180
|
|
|
181
181
|
|
|
182
182
|
random = _Random()
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
# ----- FFT functions -----
|
|
186
|
+
|
|
187
|
+
def fft(a) -> GPUArray:
|
|
188
|
+
"""1D FFT. Input is real or complex (interleaved). Returns complex GPUArray."""
|
|
189
|
+
if not isinstance(a, GPUArray):
|
|
190
|
+
a = array(a)
|
|
191
|
+
return a.fft()
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
def ifft(a) -> GPUArray:
|
|
195
|
+
"""1D inverse FFT. Input is complex interleaved. Returns complex GPUArray."""
|
|
196
|
+
if not isinstance(a, GPUArray):
|
|
197
|
+
a = array(a)
|
|
198
|
+
return a.ifft()
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
def fft_freq(n: int, d: float = 1.0) -> GPUArray:
|
|
202
|
+
"""Return the DFT sample frequencies (like numpy.fft.fftfreq)."""
|
|
203
|
+
results = np.empty(n, dtype=np.float32)
|
|
204
|
+
N = (n - 1) // 2 + 1
|
|
205
|
+
results[:N] = np.arange(0, N, dtype=np.float32)
|
|
206
|
+
results[N:] = np.arange(-(n // 2), 0, dtype=np.float32)
|
|
207
|
+
results /= (n * d)
|
|
208
|
+
return _from_numpy(results)
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
def fft_magnitude(a) -> GPUArray:
|
|
212
|
+
"""Compute magnitude spectrum |FFT(x)|. Returns real GPUArray."""
|
|
213
|
+
if not isinstance(a, GPUArray):
|
|
214
|
+
a = array(a)
|
|
215
|
+
fft_result = a.fft()
|
|
216
|
+
return _complex_magnitude(fft_result)
|