Changeset 27

Show
Ignore:
Timestamp:
05/22/07 11:42:51 (2 years ago)
Author:
emuller
Message:

neuron.hoc.test_numpy function added, fixed problems with build process wrt numpy

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/pygetsetcall/src/nrnpython/Makefile.am

    r17 r27  
    22 
    33nsrc=$(top_srcdir)/src 
     4DEFS = @DEFS@ @NRNPYTHON_DEFINES@ 
    45NRNPYTHON_INCLUDES = @NRNPYTHON_INCLUDES@ 
    56IV_INCLUDES = @IV_INCLUDE@ $(X_CFLAGS) 
  • branches/pygetsetcall/src/nrnpython/nrnpy_hoc.cpp

    r26 r27  
    7777} 
    7878 
     79 
     80static PyObject* test_numpy(PyObject* self, PyObject* args) { 
     81 
     82        if (!PyArg_ParseTuple(args, "")) { 
     83                return NULL; 
     84        } 
     85 
     86        #ifdef WITH_NUMPY 
     87 
     88        PyArrayObject *po = NULL; 
     89        int dims = 1; 
     90 
     91        po = (PyArrayObject*)PyArray_FromDims(1,&dims,PyArray_DOUBLE); 
     92        *(double*)(po->data) = 0.0; 
     93        return Py_BuildValue("N",po); 
     94 
     95        #else 
     96 
     97        // return None 
     98        return Py_BuildValue(""); 
     99 
     100        #endif // WITH_NUMPY 
     101 
     102 
     103 
     104} 
     105 
     106 
     107 
    79108static PyMethodDef HocMethods[] = { 
    80109        {"execute", nrnexec, METH_VARARGS, "Execute a hoc command, return 1 on success, 0 on failure." }, 
    81110        {"hoc_ac", hoc_ac, METH_VARARGS, "Get (or set) the scalar hoc_ac_." }, 
     111 
     112        {"test_numpy", test_numpy, METH_VARARGS, "If numpy support is available, returns an array containing 1 zero, otherwize None." }, 
     113 
     114 
    82115        {NULL, NULL, 0, NULL} 
    83116}; 
     
    741774}; 
    742775 
     776  /* 
    743777#ifdef WITH_NUMPY 
    744778 
     
    928962 
    929963#endif //WITH_NUMPY 
     964 
     965  */ 
    930966 
    931967static PyMemberDef hocobj_members[] = { 
     
    962998    0,                         /* tp_iter */ 
    963999    0,                         /* tp_iternext */ 
    964     hocobj_methods,             /* tp_methods */ 
     1000    0,//hocobj_methods,             /* tp_methods */ 
    9651001    0,//hocobj_members,             /* tp_members */ 
    9661002    0,                         /* tp_getset */ 
  • branches/pygetsetcall/src/nrnpython/setup.py.in

    r25 r27  
    22from distutils.core import setup, Extension 
    33 
     4import sys 
    45 
    5 defines = [] 
     6# NRNPYTHON_DEFINES which were enabled at configure time 
     7extern_defines = "@NRNPYTHON_DEFINES@" 
    68 
     9ldefs = extern_defines.split('-D') 
    710 
    811# check for numpy+version 
     12 
     13with_numpy = False 
    914 
    1015try: 
    1116    import numpy 
    1217except ImportError: 
    13     print "Fatal rror: numpy not installed or not in import path
     18    print "Warning: numpy not installed or not in import path.
    1419 
    1520else: 
     
    1924    if version[0] < '1' or (len(version[1]) > 1 and version[1] < '0rc1'): 
    2025        print "Warning: Old numpy found and not being used.  Please upgrade your version of numpy to > 1.0rc1" 
     26         
    2127    else: 
    22         numpy_include_path = numpy.__path__[0]+'/core/include' 
     28        with_numpy = True 
     29 
     30 
     31include_dirs = [] 
     32defines = [] 
     33 
     34 
     35# check that options at configure time match the detected options now 
     36 
     37if 'WITH_NUMPY' in ldefs: 
     38    if with_numpy: 
     39        # Good, support was enabled in nrnpython.la at build time 
     40        # we can enable support here 
     41 
     42        include_dirs.append(numpy.__path__[0]+'/core/include') 
    2343        defines.append(('WITH_NUMPY',None)) 
    2444 
     45    else: 
     46        print "Error: NEURON was build with support for numpy but" 
     47        print "no suitable installation of numpy could be found." 
     48        print "1) Check that your numpy version is at least 1.0rc1" 
     49        print "2) Check that you are using the same python executable" 
     50        print "to run this setup.py script as specified at configure time:" 
     51        print "--with-nrnpython[=python_bin] (defaults to 'python' in path)." 
     52        sys.exit(1) 
     53 
     54else: 
     55    if with_numpy: 
     56        print "Warning: NEURON was build without support for numpy." 
     57        print "A suitable installation for numpy was found, but cannot be used."  
    2558 
    2659 
     
    4679        "readline" 
    4780      ], 
    48       include_dirs = [numpy_include_path]
     81      include_dirs = include_dirs
    4982      define_macros=defines 
    5083    )