-
Notifications
You must be signed in to change notification settings - Fork 5
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
1 parent
29d7ded
commit 5cb7329
Showing
5 changed files
with
107 additions
and
163 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
This file was deleted.
Oops, something went wrong.
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,45 @@ | ||
#ifndef BACKLASH_GUFUNC_H | ||
#define BACKLASH_GUFUNC_H | ||
|
||
#define PY_SSIZE_T_CLEAN | ||
#include "Python.h" | ||
|
||
#define NPY_NO_DEPRECATED_API NPY_API_VERSION | ||
#include "numpy/ndarraytypes.h" | ||
|
||
#include "../src/util/strided.hpp" | ||
|
||
|
||
template<typename T> | ||
static void | ||
backlash_core( | ||
npy_intp n, // core dimension n | ||
T *p_x, // pointer to first element of x, a strided 1-d array with shape (n,) | ||
const npy_intp x_stride, // stride (in bytes) of x | ||
T *p_deadband, // pointer to deadband | ||
T *p_initial, // pointer to initial | ||
T *p_out, // pointer to out, a strided 1-d array with shape (n,) | ||
const npy_intp out_stride // stride (in bytes) of out | ||
) | ||
{ | ||
T deadband = *p_deadband; | ||
T initial = *p_initial; | ||
T halfband = deadband/2; | ||
T current_y = initial; | ||
for (npy_intp k = 0; k < n; ++k) { | ||
T current_x = get(p_x, x_stride, k); | ||
T xminus = current_x - halfband; | ||
if (xminus > current_y) { | ||
current_y = xminus; | ||
} | ||
else { | ||
T xplus = current_x + halfband; | ||
if (xplus < current_y) { | ||
current_y = xplus; | ||
} | ||
} | ||
set(p_out, out_stride, k, current_y); | ||
} | ||
} | ||
|
||
#endif |
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,55 @@ | ||
|
||
|
||
from ufunc_config_types import UFuncExtMod, UFunc, UFuncSource | ||
|
||
|
||
BACKLASH_DOCSTRING = """\ | ||
backlash(x, deadband, initial, /, ...) | ||
Compute the backlash signal of the input signal x. | ||
Parameters | ||
---------- | ||
x : array_like | ||
Input signal | ||
deadband : scalar | ||
Width of the deadband of the backlash process. | ||
initial : scalar | ||
Initial state of the output. | ||
Returns | ||
------- | ||
out : ndarray | ||
Output of the backlash process. | ||
Examples | ||
-------- | ||
>>> x = np.array([0, 1, 1.1, 1.0, 1.5, 1.4, 1.2, 0.5]) | ||
>>> backlash(x, 0.4, 0.0) | ||
array([0. , 0.8, 0.9, 0.9, 1.3, 1.3, 1.3, 0.7]) | ||
""" | ||
|
||
|
||
backlash_core_source = UFuncSource( | ||
funcname='backlash_core', | ||
typesignatures=['fff->f', 'ddd->d', 'ggg->g'], | ||
) | ||
|
||
backlash_gufunc = UFunc( | ||
name='backlash', | ||
docstring=BACKLASH_DOCSTRING, | ||
header='backlash_gufunc.h', | ||
signature='(n),(),() -> (n)', | ||
sources=[backlash_core_source], | ||
) | ||
|
||
|
||
MODULE_DOCSTRING = """\ | ||
This module defines the backlash function. | ||
""" | ||
|
||
extmod = UFuncExtMod( | ||
module='_backlash', | ||
docstring=MODULE_DOCSTRING, | ||
ufuncs=[backlash_gufunc], | ||
) |
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