Skip to content

Commit 014bde2

Browse files
author
Dilawar Singh
committed
Merge branch 'issue_397' into pybind11
2 parents 8f60899 + ad58dc5 commit 014bde2

File tree

7 files changed

+36
-298
lines changed

7 files changed

+36
-298
lines changed

biophysics/CompartmentBase.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,6 @@
1111
#ifndef _COMPARTMENT_BASE_H
1212
#define _COMPARTMENT_BASE_H
1313

14-
#ifdef CYMOOSE
15-
16-
template<typename A>
17-
class SrcFinfo1;
18-
19-
20-
#endif /* ----- CYMOOSE ----- */
21-
2214
/**
2315
* The CompartmentBase class sets up the interface for all the
2416
* derived Compartment classes, used in

kinetics/Pool.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
** See the file COPYING.LIB for the full notice.
88
**********************************************************************/
99

10+
#include <cmath>
11+
1012
#include "../basecode/header.h"
1113
#include "../basecode/ElementValueFinfo.h"
1214
#include "../utility/print_function.hpp"

pymoose/melement.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@
55
#include <Python.h>
66
#include <structmember.h>
77

8-
#ifdef USE_BOOST_ODE
9-
#include <boost/format.hpp>
10-
#endif
11-
128
#include <iostream>
139
#include <typeinfo>
1410
#include <cstring>

pymoose/moosemodule.cpp

Lines changed: 3 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -496,92 +496,44 @@ PyObject * to_pytuple(void * obj, char typecode)
496496
{
497497
vector< double > * vec = static_cast< vector < double >* >(obj);
498498
assert(vec != NULL);
499-
#ifndef USE_NUMPY
500-
ret = PyTuple_New((Py_ssize_t)vec->size());
501-
for (unsigned int ii = 0; ii < vec->size(); ++ii)
502-
{
503-
if (0 != PyTuple_SetItem(ret, ii, PyFloat_FromDouble(vec->at(ii))))
504-
{
505-
Py_DECREF(ret);
506-
return NULL;
507-
}
508-
}
509-
#else
510499
npy_intp size = (npy_intp)(vec->size());
511500
ret = PyArray_SimpleNew(1, &size, NPY_DOUBLE);
512501
assert(ret != NULL);
513502
char * ptr = PyArray_BYTES((PyArrayObject*)ret);
514503
memcpy(ptr, &(*vec)[0], vec->size() * sizeof(double));
515-
#endif
516504
return ret;
517505
}
518506
case 'i': // vector<int>
519507
{
520508
vector< int > * vec = static_cast< vector < int >* >(obj);
521509
assert(vec != NULL);
522-
#ifndef USE_NUMPY
523-
ret = PyTuple_New((Py_ssize_t)vec->size());
524-
for (unsigned int ii = 0; ii < vec->size(); ++ii)
525-
{
526-
if (0 != PyTuple_SetItem(ret, ii, PyInt_FromLong(vec->at(ii))))
527-
{
528-
Py_DECREF(ret);
529-
return NULL;
530-
}
531-
}
532-
#else
533510
npy_intp size = (npy_intp)(vec->size());
534511
ret = PyArray_SimpleNew(1, &size, NPY_INT);
535512
assert(ret != NULL);
536513
char * ptr = PyArray_BYTES((PyArrayObject*)ret);
537514
memcpy(ptr, &(*vec)[0], size * sizeof(int));
538-
#endif
539515
return ret;
540516
}
541517
case 'I': // vector<unsigned int>
542518
{
543519
vector< int > * vec = static_cast< vector < int >* >(obj);
544520
assert(vec != NULL);
545-
#ifndef USE_NUMPY
546-
ret = PyTuple_New((Py_ssize_t)vec->size());
547-
for (unsigned int ii = 0; ii < vec->size(); ++ii)
548-
{
549-
if (0 != PyTuple_SetItem(ret, ii, PyLong_FromLong(vec->at(ii))))
550-
{
551-
Py_DECREF(ret);
552-
return NULL;
553-
}
554-
}
555-
#else
556521
npy_intp size = (npy_intp)(vec->size());
557522
ret = PyArray_SimpleNew(1, &size, NPY_UINT);
558523
assert(ret != NULL);
559524
char * ptr = PyArray_BYTES((PyArrayObject*)ret);
560525
memcpy(ptr, &(*vec)[0], size * sizeof(unsigned int));
561-
#endif
562526
return ret;
563527
}
564528
case 'l': // vector<long>
565529
{
566530
vector< long > * vec = static_cast< vector < long >* >(obj);
567531
assert(vec != NULL);
568-
#ifndef USE_NUMPY
569-
ret = PyTuple_New((Py_ssize_t)vec->size());
570-
for (unsigned int ii = 0; ii < vec->size(); ++ii)
571-
{
572-
if (0 != PyTuple_SetItem(ret, ii, PyLong_FromLong(vec->at(ii))))
573-
{
574-
Py_DECREF(ret);
575-
return NULL;
576-
}
577-
}
578-
#else
579532
npy_intp size = (npy_intp)(vec->size());
580533
ret = PyArray_SimpleNew(1, &size, NPY_INT);
581534
assert(ret != NULL);
582535
char * ptr = PyArray_BYTES((PyArrayObject*)ret);
583536
memcpy(ptr, &(*vec)[0], size * sizeof(long));
584-
#endif
585537
return ret;
586538
}
587539
case 'x': // vector<Id>
@@ -648,92 +600,45 @@ PyObject * to_pytuple(void * obj, char typecode)
648600
{
649601
vector< unsigned int > * vec = static_cast< vector < unsigned int >* >(obj);
650602
assert(vec != NULL);
651-
#ifndef USE_NUMPY
652-
ret = PyTuple_New((Py_ssize_t)vec->size());
653-
for (unsigned int ii = 0; ii < vec->size(); ++ii)
654-
{
655-
if (0 != PyTuple_SetItem(ret, ii, PyLong_FromUnsignedLong(vec->at(ii))))
656-
{
657-
Py_DECREF(ret);
658-
return NULL;
659-
}
660-
}
661-
#else
662603
npy_intp size = (npy_intp)(vec->size());
663604
ret = PyArray_SimpleNew(1, &size, NPY_UINT);
664605
assert(ret != NULL);
665606
char * ptr = PyArray_BYTES((PyArrayObject*)ret);
666607
memcpy(ptr, &(*vec)[0], size * sizeof(unsigned int));
667-
#endif
668608
return ret;
669609
}
670610
case 'L': // vector<long long> - this is not used at present
671611
{
672612
vector< long long> * vec = static_cast< vector < long long>* >(obj);
673613
assert(vec != NULL);
674614
ret = PyTuple_New((Py_ssize_t)vec->size());
675-
#ifndef USE_NUMPY
676-
for (unsigned int ii = 0; ii < vec->size(); ++ii)
677-
{
678-
if (0 != PyTuple_SetItem(ret, ii, PyLong_FromLongLong(vec->at(ii))))
679-
{
680-
Py_DECREF(ret);
681-
return NULL;
682-
}
683-
}
684-
#else
685615
npy_intp size = (npy_intp)(vec->size());
686616
ret = PyArray_SimpleNew(1, &size, NPY_LONGLONG);
687617
assert(ret != NULL);
688618
char * ptr = PyArray_BYTES((PyArrayObject*)ret);
689619
memcpy(ptr, &(*vec)[0], size * sizeof(long long));
690-
#endif
691620
return ret;
692621
}
693622
case 'K': // vector<unsigned long long> - this is not used at present
694623
{
695624
vector< unsigned long long> * vec = static_cast< vector < unsigned long long>* >(obj);
696625
assert(vec != NULL);
697-
#ifndef USE_NUMPY
698-
ret = PyTuple_New((Py_ssize_t)vec->size());
699-
for (unsigned int ii = 0; ii < vec->size(); ++ii)
700-
{
701-
if (0 != PyTuple_SetItem(ret, ii, PyLong_FromUnsignedLongLong(vec->at(ii))))
702-
{
703-
Py_DECREF(ret);
704-
return NULL;
705-
}
706-
}
707-
#else
708626
npy_intp size = (npy_intp)(vec->size());
709627
ret = PyArray_SimpleNew(1, &size, NPY_ULONGLONG);
710628
assert(ret != NULL);
711629
char * ptr = PyArray_BYTES((PyArrayObject*)ret);
712630
memcpy(ptr, &(*vec)[0], size * sizeof(unsigned long long));
713-
#endif
714631
return ret;
715632
}
716633
case 'F': // vector<float>
717634
{
718635
vector< float > * vec = static_cast< vector < float >* >(obj);
719636
assert(vec != NULL);
720-
#ifndef USE_NUMPY
721-
ret = PyTuple_New((Py_ssize_t)vec->size());
722-
for (unsigned int ii = 0; ii < vec->size(); ++ii)
723-
{
724-
if (0 != PyTuple_SetItem(ret, ii, PyFloat_FromDouble(vec->at(ii))))
725-
{
726-
Py_DECREF(ret);
727-
return NULL;
728-
}
729-
}
730-
#else
731637
npy_intp size = (npy_intp)(vec->size());
732638
ret = PyArray_SimpleNew(1, &size, NPY_FLOAT);
733639
assert(ret != NULL);
734640
char * ptr = PyArray_BYTES((PyArrayObject*)ret);
735641
memcpy(ptr, &(*vec)[0], size * sizeof(float));
736-
#endif
737642
return ret;
738643
}
739644
case 's': // vector<string>
@@ -2842,9 +2747,8 @@ PyObject * moose_element(PyObject* dummy, PyObject * args)
28422747
Id id;
28432748
unsigned int numData = 0;
28442749

2845-
// Parse into str or bytes-like object. Using 's' parses into const char*
2846-
// which is portable with bytes often returned when working with python3.
2847-
if (PyArg_ParseTuple(args, "s*", &path))
2750+
// Don't use s* here: See https://github.com/BhallaLab/moose-core/issues/397
2751+
if (PyArg_ParseTuple(args, "s", &path))
28482752
{
28492753
oid = ObjId(path);
28502754
if ( oid.bad() )
@@ -3026,9 +2930,8 @@ PyMODINIT_FUNC MODINIT(_moose)
30262930
{
30272931
cerr << "Failed to register finalize() to be called at exit. " << endl;
30282932
}
3029-
#ifdef USE_NUMPY
30302933
import_array();
3031-
#endif
2934+
30322935
// Add Id type
30332936
// Py_TYPE(&IdType) = &PyType_Type; // unnecessary - filled in by PyType_Ready
30342937
IdType.tp_new = PyType_GenericNew;

0 commit comments

Comments
 (0)