Skip to content

Commit

Permalink
add samplingPoints
Browse files Browse the repository at this point in the history
  • Loading branch information
feihoo87 committed Jul 9, 2021
1 parent 9564c7f commit 676a4fe
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
4 changes: 2 additions & 2 deletions waveforms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
from .version import __version__
from .waveform import (D, Waveform, const, cos, cosPulse, exp, function,
gaussian, interp, mixing, one, poly, registerBaseFunc,
registerDerivative, sign, sin, sinc, square, step,
wave_eval, zero)
registerDerivative, samplingPoints, sign, sin, sinc,
square, step, wave_eval, zero)
2 changes: 1 addition & 1 deletion waveforms/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
"""Define version number here and read it from setup.py automatically"""
__version__ = "0.12.22"
__version__ = "0.12.23"
22 changes: 19 additions & 3 deletions waveforms/waveform.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from bisect import bisect_left
from functools import lru_cache
from itertools import chain, product

import pickle
import numpy as np
import ply.lex as lex
import ply.yacc as yacc
Expand Down Expand Up @@ -417,6 +417,14 @@ def registerBaseFunc(func):
return Type


def packBaseFunc():
return pickle.dumps(_baseFunc)


def updateBaseFunc(buf):
_baseFunc.update(pickle.loads(buf))


def registerDerivative(Type, dFunc):
_derivativeBaseFunc[Type] = dFunc

Expand All @@ -428,6 +436,8 @@ def registerDerivative(Type, dFunc):
COS = registerBaseFunc(lambda t, w: np.cos(w * t))
SINC = registerBaseFunc(lambda t, bw: np.sinc(bw * t))
EXP = registerBaseFunc(lambda t, alpha: np.exp(alpha * t))
INTERP = registerBaseFunc(lambda t, start, stop, points: np.interp(
t, np.linspace(start, stop, len(points)), points))

# register derivative
registerDerivative(LINEAR, lambda shift, *args: _one)
Expand Down Expand Up @@ -622,6 +632,12 @@ def function(fun, *args, start=None, stop=None):
return wav


def samplingPoints(start, stop, points):
return Waveform(bounds=(start, stop, inf),
seq=(_zero, _basic_wave(INTERP, start, stop,
tuple(points)), _zero))


def mixing(I,
Q=None,
*,
Expand Down Expand Up @@ -923,6 +939,6 @@ def wave_eval(expr: str) -> Waveform:
__all__ = [
'D', 'Waveform', 'const', 'cos', 'cosPulse', 'exp', 'function', 'gaussian',
'interp', 'mixing', 'one', 'poly', 'registerBaseFunc',
'registerDerivative', 'sign', 'sin', 'sinc', 'square', 'step', 'wave_eval',
'zero'
'registerDerivative', 'samplingPoints', 'sign', 'sin', 'sinc', 'square',
'step', 'wave_eval', 'zero'
]

0 comments on commit 676a4fe

Please sign in to comment.