-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
325 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
from google_benchmark import State | ||
import google_benchmark as benchmark | ||
import numpy as np | ||
|
||
from pyfftconv import oaconvolve, oaconvolve_, convolve, convolve_, hilbert, hilbert_ | ||
|
||
ARGS_FIR = [[2304, 4352], [165]] | ||
|
||
|
||
def BM_conv(fn, state: State, x, k, mode: str): | ||
fn(x, k, mode) | ||
while state: | ||
fn(x, k, mode) | ||
state.items_processed = state.iterations * x.size | ||
state.bytes_processed = state.items_processed * x.itemsize | ||
|
||
|
||
def BM_conv_out(fn, state: State, x, k, out, mode: str): | ||
fn(x, k, out, mode) | ||
while state: | ||
fn(x, k, out, mode) | ||
state.items_processed = state.iterations * x.size | ||
state.bytes_processed = state.items_processed * x.itemsize | ||
|
||
|
||
def BM_hilbert(fn, state: State, x): | ||
fn(x) | ||
while state: | ||
fn(x) | ||
state.items_processed = state.iterations * x.size | ||
state.bytes_processed = state.items_processed * x.itemsize | ||
|
||
|
||
def BM_hilbert_out(fn, state: State, x, out): | ||
fn(x, out) | ||
while state: | ||
fn(x, out) | ||
state.items_processed = state.iterations * x.size | ||
state.bytes_processed = state.items_processed * x.itemsize | ||
|
||
|
||
@benchmark.register | ||
@benchmark.option.args_product(ARGS_FIR) | ||
def BM_oaconvolve_same_double(state: State): | ||
x = np.random.random(state.range(0)).astype(np.float64) | ||
k = np.random.random(state.range(1)).astype(np.float64) | ||
BM_conv(oaconvolve, state, x, k, "same") | ||
|
||
|
||
@benchmark.register | ||
@benchmark.option.args_product(ARGS_FIR) | ||
def BM_oaconvolve_same_float(state: State): | ||
x = np.random.random(state.range(0)).astype(np.float32) | ||
k = np.random.random(state.range(1)).astype(np.float32) | ||
BM_conv(oaconvolve, state, x, k, "same") | ||
|
||
|
||
@benchmark.register | ||
@benchmark.option.args_product(ARGS_FIR) | ||
def BM_oaconvolve_same_out_double(state: State): | ||
x = np.random.random(state.range(0)).astype(np.float64) | ||
k = np.random.random(state.range(1)).astype(np.float64) | ||
out = np.zeros_like(x) | ||
BM_conv_out(oaconvolve_, state, x, k, out, "same") | ||
|
||
|
||
@benchmark.register | ||
@benchmark.option.args_product(ARGS_FIR) | ||
def BM_oaconvolve_same_out_float(state: State): | ||
x = np.random.random(state.range(0)).astype(np.float32) | ||
k = np.random.random(state.range(1)).astype(np.float32) | ||
out = np.zeros_like(x) | ||
BM_conv_out(oaconvolve_, state, x, k, out, "same") | ||
|
||
|
||
@benchmark.register | ||
@benchmark.option.dense_range(2048, 6144, 1024) | ||
def BM_hilbert_float(state: State): | ||
x = np.random.random(state.range(0)).astype(np.float32) | ||
BM_hilbert(hilbert, state, x) | ||
|
||
|
||
@benchmark.register | ||
@benchmark.option.dense_range(2048, 6144, 1024) | ||
def BM_hilbert_double(state: State): | ||
x = np.random.random(state.range(0)).astype(np.float64) | ||
BM_hilbert(hilbert, state, x) | ||
|
||
|
||
@benchmark.register | ||
@benchmark.option.dense_range(2048, 6144, 1024) | ||
def BM_hilbert_out_float(state: State): | ||
x = np.random.random(state.range(0)).astype(np.float32) | ||
out = np.zeros_like(x) | ||
BM_hilbert_out(hilbert_, state, x, out) | ||
|
||
|
||
@benchmark.register | ||
@benchmark.option.dense_range(2048, 6144, 1024) | ||
def BM_hilbert_out_double(state: State): | ||
x = np.random.random(state.range(0)).astype(np.float64) | ||
out = np.zeros_like(x) | ||
BM_hilbert_out(hilbert_, state, x, out) | ||
|
||
|
||
if __name__ == "__main__": | ||
benchmark.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,10 @@ | ||
from ._pyfftconv import __doc__, __version__, oaconvolve, oaconvolve_, hilbert, hilbert_ | ||
from ._pyfftconv import ( | ||
__doc__, | ||
__version__, | ||
convolve, | ||
convolve_, | ||
oaconvolve, | ||
oaconvolve_, | ||
hilbert, | ||
hilbert_, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
""" | ||
Python wrapper for fftconv | ||
""" | ||
from __future__ import annotations | ||
from pyfftconv._pyfftconv import convolve | ||
from pyfftconv._pyfftconv import convolve_ | ||
from pyfftconv._pyfftconv import hilbert | ||
from pyfftconv._pyfftconv import hilbert_ | ||
from pyfftconv._pyfftconv import oaconvolve | ||
from pyfftconv._pyfftconv import oaconvolve_ | ||
from . import _pyfftconv | ||
__all__ = ['convolve', 'convolve_', 'hilbert', 'hilbert_', 'oaconvolve', 'oaconvolve_'] | ||
__version__: str = '0.5.1' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
""" | ||
Python wrapper for fftconv | ||
""" | ||
from __future__ import annotations | ||
import numpy | ||
import typing | ||
__all__ = ['convolve', 'convolve_', 'hilbert', 'hilbert_', 'oaconvolve', 'oaconvolve_'] | ||
@typing.overload | ||
def convolve(a: numpy.ndarray[numpy.float64], k: numpy.ndarray[numpy.float64], mode: str = 'full') -> numpy.ndarray[numpy.float64]: | ||
""" | ||
Performs convolution using FFTW. API compatible with np.convolve | ||
""" | ||
@typing.overload | ||
def convolve(a: numpy.ndarray[numpy.float32], k: numpy.ndarray[numpy.float32], mode: str = 'full') -> numpy.ndarray[numpy.float32]: | ||
""" | ||
Performs convolution using FFTW. API compatible with np.convolve | ||
""" | ||
@typing.overload | ||
def convolve_(a: numpy.ndarray[numpy.float64], k: numpy.ndarray[numpy.float64], out: numpy.ndarray[numpy.float64], mode: str = 'full') -> None: | ||
""" | ||
Performs convolution using FFTW. API compatible with np.convolve | ||
""" | ||
@typing.overload | ||
def convolve_(a: numpy.ndarray[numpy.float32], k: numpy.ndarray[numpy.float32], out: numpy.ndarray[numpy.float32], mode: str = 'full') -> None: | ||
""" | ||
Performs convolution using FFTW. API compatible with np.convolve | ||
""" | ||
@typing.overload | ||
def hilbert(a: numpy.ndarray[numpy.float64]) -> numpy.ndarray[numpy.float64]: | ||
""" | ||
Performs envelope detection using the Hilbert transform. | ||
Equivalent to `np.abs(signal.hilbert(a))` | ||
""" | ||
@typing.overload | ||
def hilbert(a: numpy.ndarray[numpy.float32]) -> numpy.ndarray[numpy.float32]: | ||
""" | ||
Performs envelope detection using the Hilbert transform. | ||
Equivalent to `np.abs(signal.hilbert(a))` | ||
""" | ||
@typing.overload | ||
def hilbert_(a: numpy.ndarray[numpy.float64], out: numpy.ndarray[numpy.float64]) -> None: | ||
""" | ||
Performs envelope detection using the Hilbert transform. | ||
Equivalent to `np.abs(signal.hilbert(a))` | ||
""" | ||
@typing.overload | ||
def hilbert_(a: numpy.ndarray[numpy.float32], out: numpy.ndarray[numpy.float32]) -> None: | ||
""" | ||
Performs envelope detection using the Hilbert transform. | ||
Equivalent to `np.abs(signal.hilbert(a))` | ||
""" | ||
@typing.overload | ||
def oaconvolve(a: numpy.ndarray[numpy.float64], k: numpy.ndarray[numpy.float64], mode: str = 'full') -> numpy.ndarray[numpy.float64]: | ||
""" | ||
Performs overlap-add convolution using FFTW. API compatible with np.convolve | ||
""" | ||
@typing.overload | ||
def oaconvolve(a: numpy.ndarray[numpy.float32], k: numpy.ndarray[numpy.float32], mode: str = 'full') -> numpy.ndarray[numpy.float32]: | ||
""" | ||
Performs overlap-add convolution using FFTW. API compatible with np.convolve | ||
""" | ||
@typing.overload | ||
def oaconvolve_(a: numpy.ndarray[numpy.float64], k: numpy.ndarray[numpy.float64], out: numpy.ndarray[numpy.float64], mode: str = 'full') -> None: | ||
""" | ||
Performs overlap-add convolution using FFTW. API compatible with np.convolve | ||
""" | ||
@typing.overload | ||
def oaconvolve_(a: numpy.ndarray[numpy.float32], k: numpy.ndarray[numpy.float32], out: numpy.ndarray[numpy.float32], mode: str = 'full') -> None: | ||
""" | ||
Performs overlap-add convolution using FFTW. API compatible with np.convolve | ||
""" | ||
__version__: str = '0.5.1' |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.