Skip to content

Commit

Permalink
Merge pull request #21 from fruzsinaagocs/windows-testwq
Browse files Browse the repository at this point in the history
Windows CI
  • Loading branch information
fruzsinaagocs committed Feb 3, 2023
2 parents 4fdffb3 + ea651e4 commit afe1731
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 28 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/python-package.yml
Expand Up @@ -8,10 +8,16 @@ on:
jobs:
build:

runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}
strategy:
matrix:
python-version: [3.7, 3.8, 3.9]
os: ["ubuntu-latest"]
include:
- python-version: "3.9"
os: "macos-latest"
- python-version: "3.9"
os: "windows-latest"

steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 2 additions & 0 deletions README.rst
Expand Up @@ -259,6 +259,8 @@ devs of `exhale <https://pypi.org/project/exhale/>`__ for making the beautiful C
Changelog
---------

- 1.1.1:
- Support for mac and Windows OS at CI.
- 1.1.0:
- Users can now define w, g as functions in Python (pyoscode) and call the solver via pyoscode.solve_fn(...)
- 1.0.6:
Expand Down
28 changes: 14 additions & 14 deletions include/solver.hpp
Expand Up @@ -109,7 +109,7 @@ a_tol, double h_0, const char* full_output){

// Determine direction of integration, fend>0 and integration ends when
// it crosses zero
if((t>=tf) and h0<0){
if((t>=tf) && h0<0){
// backwards
fend = t-tf;
fnext = fend;
Expand All @@ -121,7 +121,7 @@ a_tol, double h_0, const char* full_output){
sign = 0;

}
else if((t<=tf) and h0>0){
else if((t<=tf) && h0>0){
// forward
fend = tf-t;
fnext = fend;
Expand Down Expand Up @@ -196,7 +196,7 @@ a_tol, double h_0, const char* full_output){

// Determine direction of integration, fend>0 and integration ends when
// it crosses zero
if((t>=tf) and h0<0){
if((t>=tf) && h0<0){
// backwards
fend = t-tf;
fnext = fend;
Expand All @@ -207,7 +207,7 @@ a_tol, double h_0, const char* full_output){
else
sign = 0;
}
else if((t<=tf) and h0>0){
else if((t<=tf) && h0>0){
// forward
fend = tf-t;
fnext = fend;
Expand Down Expand Up @@ -239,7 +239,7 @@ a_tol, double h_0, const char* full_output){
dotimes.sort();

// Reverse if necessary
if((de_sys_->is_interpolated == 1 and de_sys_->Winterp.sign_ == 0) or (de_sys_->is_interpolated == 0 and sign == 0)){
if((de_sys_->is_interpolated == 1 && de_sys_->Winterp.sign_ == 0) || (de_sys_->is_interpolated == 0 && sign == 0)){
dotimes.reverse();
}

Expand Down Expand Up @@ -307,7 +307,7 @@ void Solution::solve(){
if(fnext < 0){
h = tf - t;
tnext = tf;
};
}

// Keep updating stepsize until step is accepted
while(true){
Expand Down Expand Up @@ -372,7 +372,7 @@ void Solution::solve(){
xnext = rkx(0);
dxnext = rkx(1);
hnext = hrk;
};
}
totsteps += 1;
// Checking for too many steps and low acceptance ratio:
if(totsteps % 5000 == 0){
Expand All @@ -387,7 +387,7 @@ void Solution::solve(){
// std::cout << "All dense output points: " << std::endl;
if(dotit!=dotimes.end()){
// std::cout << *dotit << std::endl;
while((*dotit-t>=0 && tnext-*dotit>=0) or (*dotit-t<=0 && tnext-*dotit<=0)){
while((*dotit-t>=0 && tnext-*dotit>=0) || (*dotit-t<=0 && tnext-*dotit<=0)){
inner_dotimes.push_back(*dotit);
dotit++;
}
Expand Down Expand Up @@ -447,7 +447,7 @@ void Solution::solve(){
else{
fend=t-tf;
fnext=tnext-tf;
};
}
ssteps +=1;
// Update interpolation bounds
if(de_sys_->is_interpolated == 1){
Expand Down Expand Up @@ -477,13 +477,13 @@ void Solution::solve(){
}
else{
fnext=tnext-tf;
};
};
};
};
}
}
}
}

// Write output to file if prompted
if(not (*fo==0)){
if(!(*fo==0)){
std::string output(fo);
std::ofstream f;
f.open(output);
Expand Down
24 changes: 12 additions & 12 deletions pyoscode/_pyoscode.cpp
Expand Up @@ -39,7 +39,7 @@ static std::complex<double> wfun(double t){
if(py_result == NULL)
return NULL;
// Check if return value was the correct type (complex)
if(PyComplex_Check(py_result) or PyFloat_Check(py_result)){
if(PyComplex_Check(py_result) || PyFloat_Check(py_result)){
result = std::complex<double>(PyComplex_RealAsDouble(py_result), PyComplex_ImagAsDouble(py_result));
}
Py_DECREF(py_result);
Expand All @@ -57,7 +57,7 @@ static std::complex<double> gfun(double t){
if(py_result == NULL)
return NULL;
// Check if return value was the correct type (complex)
if(PyComplex_Check(py_result) or PyFloat_Check(py_result))
if(PyComplex_Check(py_result) || PyFloat_Check(py_result))
result = std::complex<double>(PyComplex_RealAsDouble(py_result), PyComplex_ImagAsDouble(py_result));
Py_DECREF(py_result);
return result;
Expand Down Expand Up @@ -118,15 +118,15 @@ static PyObject *_pyoscode_solve_fn(PyObject *self, PyObject *args, PyObject *kw
if(t_evalsize!=0){
if(std::is_sorted(t_evallist.begin(), t_evallist.end()) == false)
throw "The points at which dense output is requested are not in ascending order.";
else if(h0>0 and (t_evallist.front() < ti or t_evallist.back() > tf)){
else if(h0>0 && (t_evallist.front() < ti || t_evallist.back() > tf)){
throw "The point at which dense output is requested must lie in the integration range (between ti, tf).";
}
else if(h0<0 and (t_evallist.front() < tf or t_evallist.back() > ti)){
else if(h0<0 && (t_evallist.front() < tf || t_evallist.back() > ti)){
throw "The point at which dense output is requested must lie in the integration range (between ti, tf).";
}
}
// Check: direction of integration must match initial stepsize sign
if( ((tf-ti)>0 and h0<0) or ((tf-ti)<0 and h0>0) )
if( ((tf-ti)>0 && h0<0) || ((tf-ti)<0 && h0>0) )
throw "Direction of integration ( tf-ti ) in conflict with sign of initial step (h).";
}
catch(const char* errormsg){
Expand Down Expand Up @@ -245,7 +245,7 @@ static PyObject *_pyoscode_solve(PyObject *self, PyObject *args, PyObject *kwarg
t_evalarray = PyArray_FROM_OTF(t_evalobj, NPY_DOUBLE, NPY_ARRAY_IN_ARRAY);
}
// If that didn't work, throw an exception
if(tsarray==NULL or wsarray==NULL or gsarray==NULL){
if(tsarray==NULL || wsarray==NULL || gsarray==NULL){
Py_XDECREF(tsarray);
Py_XDECREF(wsarray);
Py_XDECREF(gsarray);
Expand Down Expand Up @@ -284,7 +284,7 @@ static PyObject *_pyoscode_solve(PyObject *self, PyObject *args, PyObject *kwarg

try{
// Check 1: same size arrays, large enough arrays
if(tssize != wssize or wssize != gssize or tssize != gssize)
if(tssize != wssize || wssize != gssize || tssize != gssize)
throw "The sizes of the input arrays (ts, ws, gs) do not match. Please supply arrays of the same size.";
else if(tssize < 2)
throw "The input arrays (ts, ws, gs) have to have at least size 2.";
Expand All @@ -302,25 +302,25 @@ static PyObject *_pyoscode_solve(PyObject *self, PyObject *args, PyObject *kwarg
}

// Check 3: integration limits ti, tf must lie inside ts
if(ti < ts[0] or ti > ts[tssize-1])
if(ti < ts[0] || ti > ts[tssize-1])
throw "The start of integration, ti, must lie inside the array ts.";
else if(tf < ts[0] or tf > ts[tssize-1])
else if(tf < ts[0] || tf > ts[tssize-1])
throw "The end of integration, tf, must lie inside of the array ts.";

// Check 4: dense output points must be inside integration range, and
// monotonic
if(t_evalsize!=0){
if(std::is_sorted(t_evallist.begin(), t_evallist.end()) == false)
throw "The points at which dense output is requested are not in ascending order.";
else if(h0>0 and (t_evallist.front() < ti or t_evallist.back() > tf)){
else if(h0>0 && (t_evallist.front() < ti || t_evallist.back() > tf)){
throw "The point at which dense output is requested must lie in the integration range (between ti, tf).";
}
else if(h0<0 and (t_evallist.front() < tf or t_evallist.back() > ti)){
else if(h0<0 && (t_evallist.front() < tf || t_evallist.back() > ti)){
throw "The point at which dense output is requested must lie in the integration range (between ti, tf).";
}
}
// Check 5: direction of integration must match initial stepsize sign
if( ((tf-ti)>0 and h0<0) or ((tf-ti)<0 and h0>0) )
if( ((tf-ti)>0 && h0<0) || ((tf-ti)<0 && h0>0) )
throw "Direction of integration ( tf-ti ) in conflict with sign of initial step (h).";

}
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -20,7 +20,7 @@ def readme(short=False):

setup(
name="pyoscode",
version="1.1.0",
version="1.1.1",
description=readme(short=True),
long_description=readme(),
url="https://github.com/fruzsinaagocs/oscode",
Expand Down

0 comments on commit afe1731

Please sign in to comment.