Commit 6b0d02ac authored by Jorn Baayen's avatar Jorn Baayen

Drop Cython in favour of numba

parent 72936b00
# cython: embedsignature=True
import sys
import numpy as np
from datetime import datetime
......
# cython: embedsignature=True
from casadi import if_else, logic_and
from abc import ABCMeta
......
# cython: embedsignature=True
import numpy as np
from casadi import if_else, logic_and, Function, nlpsol, SX, vertcat, inf, sum2
from .bspline import BSpline
......
# cython: embedsignature=True
from casadi import if_else, logic_and
from .bspline import BSpline
......
# cython: embedsignature=True
import xml.etree.ElementTree as ET
import numpy as np
import datetime
......
# cython: embedsignature=True
import xml.etree.ElementTree as ET
import numpy as np
import logging
......
# cython: embedsignature=True
from casadi import MX, Function, rootfinder, vertcat, horzcat, jacobian, vec, substitute, sum1, sum2, transpose, repmat, depends_on, reshape, veccat
from abc import ABCMeta, abstractmethod
import numpy as np
......
# cython: embedsignature=True
import numpy as np
import logging
import sys
......
# cython: embedsignature=True
from rtctools.data.interpolation.bspline1d import BSpline1D
from rtctools.data.interpolation.bspline2d import BSpline2D
import rtctools.data.csv as csv
......
# cython: embedsignature=True
from datetime import datetime, timedelta
from casadi import MX
import numpy as np
......
# cython: embedsignature=True
from casadi import MX, Function, sum1, vertcat, transpose, substitute, constpow, if_else
from abc import ABCMeta, abstractmethod
import numpy as np
......
# cython: embedsignature=True
import itertools
import logging
......
# cython: embedsignature=True
from .goal_programming_mixin import GoalProgrammingMixin, Goal
......
# cython: embedsignature=True
import logging
from .optimization_problem import OptimizationProblem
......
# cython: embedsignature=True
from casadi import MX, substitute, repmat, vertcat, depends_on, veccat
from pymola.backends.casadi.api import transfer_model
from collections import OrderedDict
......
# cython: embedsignature=True
from casadi import Function, nlpsol, MX, vertcat
from abc import ABCMeta, abstractmethod, abstractproperty
from numba import jit
import numpy as np
import itertools
import logging
#import cython
from .timeseries import Timeseries
from .alias_tools import AliasDict
......@@ -562,8 +560,6 @@ class OptimizationProblem(metaclass = ABCMeta):
INTERPOLATION_PIECEWISE_CONSTANT_FORWARD = 1
INTERPOLATION_PIECEWISE_CONSTANT_BACKWARD = 2
#@cython.boundscheck(False)
#np.ndarray ts
def interpolate(self, t, ts, fs, f_left=np.nan, f_right=np.nan, mode=INTERPOLATION_LINEAR):
"""
Linear interpolation over time.
......@@ -580,9 +576,28 @@ class OptimizationProblem(metaclass = ABCMeta):
:returns: The interpolated value.
"""
if hasattr(t, '__iter__'):
f = np.vectorize(lambda t_: self.interpolate(
f = np.vectorize(lambda t_: self._interpolate(
t_, ts, fs, f_left, f_right))
return f(t)
else:
return self._interpolate(t, ts, fs, f_left, f_right, mode)
@jit
def _interpolate(self, t, ts, fs, f_left=np.nan, f_right=np.nan, mode=INTERPOLATION_LINEAR):
"""
Linear interpolation over time.
:param t: Time at which to evaluate the interpolant.
:type t: float or vector of floats
:param ts: Time stamps.
:type ts: numpy array
:param fs: Function values at time stamps ts.
:param f_left: Function value left of leftmost time stamp.
:param f_right: Function value right of rightmost time stamp.
:param mode: Interpolation mode.
:returns: The interpolated value.
"""
if t < ts[0]:
if f_left != None:
......
# cython: embedsignature=True
from datetime import timedelta
from casadi import MX
import numpy as np
......
# cython: embedsignature=True
import numpy as np
......
# cython: embedsignature=True
from datetime import timedelta
import numpy as np
import logging
......
# cython: embedsignature=True
from datetime import timedelta
import numpy as np
import logging
......
# cython: embedsignature=True
import os
import logging
import numpy as np
......
# cython: embedsignature=True
"""
Commonly used utility functions.
......
from setuptools import setup
from Cython.Build import cythonize
import numpy as np
import rtctools
import sys
if sys.version_info[0] == 2 and sys.version_info[1] < 7:
sys.exit("Sorry, Python 2.7 or newer is required.")
if sys.version_info[0] == 3 and sys.version_info[1] < 6:
sys.exit("Sorry, Python 3.6 or newer is required.")
setup(
name = 'rtctools',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment