MOOSE - Multiscale Object Oriented Simulation Environment
|
#include <Python.h>
#include <structmember.h>
#include "../utility/simple_logger.hpp"
#include <iostream>
#include <typeinfo>
#include <cstring>
#include <map>
#include <ctime>
#include "../basecode/header.h"
#include "../basecode/global.h"
#include "../basecode/Id.h"
#include "../basecode/ObjId.h"
#include "../utility/utility.h"
#include "../shell/Shell.h"
#include "../shell/Wildcard.h"
#include "moosemodule.h"
Go to the source code of this file.
Macros | |
#define | SLICE_OBJ(x) ((PySliceObject*)(x)) |
Functions | |
Id | create_Id_from_path (string path, unsigned int numData, unsigned int isGlobal, string type) |
PyObject * | deleteObjId (ObjId oid) |
PyObject * | get_Id_attr (_Id *id, string attribute) |
int | moose_Id_contains (_Id *self, PyObject *obj) |
PyObject * | moose_Id_delete (_Id *self) |
static PyObject * | moose_Id_fillSlice (_Id *self, Py_ssize_t start, Py_ssize_t end, Py_ssize_t step, Py_ssize_t slicelength) |
PyObject * | moose_Id_getattro (_Id *self, PyObject *attr) |
PyObject * | moose_Id_getItem (_Id *self, Py_ssize_t index) |
Py_ssize_t | moose_Id_getLength (_Id *self) |
PyObject * | moose_Id_getPath (_Id *self) |
PyObject * | moose_Id_getShape (_Id *self) |
PyObject * | moose_Id_getSlice (_Id *self, Py_ssize_t start, Py_ssize_t end) |
PyObject * | moose_Id_getValue (_Id *self) |
long | moose_Id_hash (_Id *self) |
int | moose_Id_init (_Id *self, PyObject *args, PyObject *kwargs) |
PyObject * | moose_Id_repr (_Id *self) |
PyObject * | moose_Id_richCompare (_Id *self, PyObject *other, int op) |
int | moose_Id_setattro (_Id *self, PyObject *attr, PyObject *value) |
PyObject * | moose_Id_setField (_Id *self, PyObject *args) |
PyObject * | moose_Id_str (_Id *self) |
PyObject * | moose_Id_subscript (_Id *self, PyObject *op) |
PyDoc_STRVAR (moose_Id_delete_doc,"vec.delete() -> None""\n""\nDelete the underlying moose object. This will invalidate all""\nreferences to this object and any attempt to access it will raise a""\nValueError.""\n Example""\n--------""\n >>>iaf.delete()""\n >>>print iaf.path""\n \\ ""\n") | |
PyDoc_STRVAR (moose_Id_setField_doc,"setField(fieldname, value_vector) -> None\n""\n""Set the value of `fieldname` in all elements under this vec.\n""\n""Parameters\n""----------\n""fieldname: str\n"" field to be set.\n""value: sequence of values\n"" sequence of values corresponding to individual elements"" under this vec.\n""\n Example""\n--------""\n >>> iaf.setField('Vm', 20)""\n >>> print iaf.Vm""\n [ 20. 20. 20. 20. 20. 20. 20. 20. 20. 20.]""\n >>> iaf.setField('Vm', (1, 2, 3, 4, 5, 6, 7, 8, 9, 10))""\n >>> print iaf.Vm""\n [ 1. 2. 3. 4. 5. 6. 7. 8. 9. 10.]""Notes\n""-----\n"" This is an interface to SetGet::setVec""\n") | |
PyDoc_STRVAR (moose_Id_doc,"An object uniquely identifying a moose array-element.\n""\n""array-elements are array-like objects which can have one or more"" single-elements within them."" vec can be traversed like a Python sequence and its each item is an"" element identifying single-objects contained in the array element.\n""\n""you can create multiple references to the same MOOSE object in Python."" As long as they have the same path/id value, they all point to"" the same entity in MOOSE.\n""\n""Field access are vectorized. For example, if `comp` is a vec of"" Compartments (of size 10), which has a field called `Vm` as membrane voltage, then"" `comp.Vm` returns a"" tuple containing the `Vm` value of all 10 single-elements in this"" vec. There are a few special fields that are unique for vec and are not"" vectorized. These are `path`, `name`, `value`, `shape` and `className`."" There are two ways an vec can be initialized, \n""(1) create a new array element or \n""(2) create a reference to an existing object.\n""\n""\n Constructor:""\n""\n vec(self, path=path, n=size, g=isGlobal, dtype=className)""\n ""\n ""\n Parameters""\n ----------""\n path : str/vec/int ""\n Path of an existing array element or for creating a new one. This has""\n the same format as unix file path: /{element1}/{element2} ... ""\n If there is no object with the specified path, moose attempts to create ""\n a new array element. For that to succeed everything until the last `/`""\n character must exist or an error is raised""\n""\n Alternatively, path can be vec or integer value of the Id of an""\n existing vec object. The new object will be another reference to""\n the existing object.""\n ""\n n : positive int""\n This is a positive integers specifying the size of the array element""\n to be created. Thus n=2 will create an vec with 2 elements.""\n ""\n g : int""\n Specify if this is a global or local element. Global elements are""\n shared between nodes in a computing cluster.""\n ""\n dtype: string""\n The vector will be of this moose-class.""\n ""\n Attributes:""\n -----------""\n path : str""\n Path of the vec. In moose vecs are organized in a tree structure"" like unix file system and the paths follow the same convention.""\n""\n name : str""\n Name of the vec.""\n""\n value : int/long""\n Numeric identifier of the vec. This is unique within a single"" execution. vec comparison is based on this value and its hash is also"" this. So you can compare and sort vecs and use them as dict keys.""\n""\n shape : tuple of ints""\n Dimensions of the vec (as shape in numpy.ndarray). Currently only"" one-dimensional vecs are implemented.""\n""\n className: str""\n The class of the moose object this vec contains. MOOSE core"" implements its own class system independent of Python. pymoose creates"" thin wrappers around them. This field provides you the moose class"" name as defined in C++""\n""\n ""\n Examples""\n ---------""\n >>> iaf = moose.vec('/iaf', n=10, dtype='IntFire')""\n >>> iaf.Vm = range(10)""\n >>> print iaf[5].Vm""\n 5.0""\n >>> print iaf.Vm""\n array([ 0., 1., 2., 3., 4., 5., 6., 7., 8., 9.])") | |
Variables | |
static PyMappingMethods | IdMappingMethods |
static PyMethodDef | IdMethods [] |
static PySequenceMethods | IdSequenceMethods |
PyTypeObject | IdType |
PyTypeObject | ObjIdType |
int | verbosity |
#define SLICE_OBJ | ( | x | ) | ((PySliceObject*)(x)) |
Definition at line 724 of file vec.cpp.
Referenced by moose_Id_subscript().
Id create_Id_from_path | ( | string | path, |
unsigned int | numData, | ||
unsigned int | isGlobal, | ||
string | type | ||
) |
Utility function to create objects from full path, dimensions and classname.
Definition at line 358 of file vec.cpp.
References ObjId::bad(), name, SHELLPTR, and moose::trim().
Referenced by moose_Id_init().
PyObject* deleteObjId | ( | ObjId | oid | ) |
Definition at line 522 of file vec.cpp.
References SHELLPTR, and verbosity.
Referenced by moose_delete(), and moose_Id_delete().
PyObject* get_Id_attr | ( | _Id * | id, |
string | attribute | ||
) |
Definition at line 312 of file vec.cpp.
References Field< A >::get(), _Id::id_, moose_Id_getPath(), moose_Id_getShape(), moose_Id_getValue(), and name.
Referenced by moose_Id_getattro().
int moose_Id_contains | ( | _Id * | self, |
PyObject * | obj | ||
) |
Definition at line 799 of file vec.cpp.
References ObjId_SubtypeCheck, and ObjIdType.
PyObject* moose_Id_delete | ( | _Id * | self | ) |
Definition at line 534 of file vec.cpp.
References deleteObjId(), Id::isValid(), and RAISE_INVALID_ID.
|
static |
Definition at line 678 of file vec.cpp.
References oid_to_element(), and value.
Referenced by moose_Id_getSlice(), and moose_Id_subscript().
PyObject* moose_Id_getattro | ( | _Id * | self, |
PyObject * | attr | ||
) |
Definition at line 810 of file vec.cpp.
References Field< A >::get(), get_field_alias(), get_Id_attr(), getFieldType(), Field< A >::getVec(), Id::isValid(), RAISE_INVALID_ID, shortType(), and to_pytuple().
PyObject* moose_Id_getItem | ( | _Id * | self, |
Py_ssize_t | index | ||
) |
Definition at line 649 of file vec.cpp.
References Id::isValid(), moose_Id_getLength(), oid_to_element(), and RAISE_INVALID_ID.
Referenced by moose_Id_subscript().
Py_ssize_t moose_Id_getLength | ( | _Id * | self | ) |
Definition at line 607 of file vec.cpp.
References Id::isValid(), and RAISE_INVALID_ID.
Referenced by moose_Id_getItem(), moose_Id_getSlice(), moose_Id_setattro(), and moose_Id_subscript().
PyObject* moose_Id_getPath | ( | _Id * | self | ) |
Not to be redone. 2011-03-23 14:42:48 (+0530)
Definition at line 588 of file vec.cpp.
References moose::endswith(), Id::isValid(), path, and RAISE_INVALID_ID.
Referenced by get_Id_attr().
PyObject* moose_Id_getShape | ( | _Id * | self | ) |
Definition at line 623 of file vec.cpp.
References Id::isValid(), and RAISE_INVALID_ID.
Referenced by get_Id_attr().
PyObject* moose_Id_getSlice | ( | _Id * | self, |
Py_ssize_t | start, | ||
Py_ssize_t | end | ||
) |
Definition at line 702 of file vec.cpp.
References Id::isValid(), moose_Id_fillSlice(), moose_Id_getLength(), and RAISE_INVALID_ID.
PyObject* moose_Id_getValue | ( | _Id * | self | ) |
Definition at line 578 of file vec.cpp.
Referenced by get_Id_attr().
long moose_Id_hash | ( | _Id * | self | ) |
int moose_Id_init | ( | _Id * | self, |
PyObject * | args, | ||
PyObject * | kwargs | ||
) |
Definition at line 416 of file vec.cpp.
References create_Id_from_path(), Id_SubtypeCheck, IdType, ObjId_SubtypeCheck, path, and moose::trim().
PyObject* moose_Id_repr | ( | _Id * | self | ) |
Definition at line 551 of file vec.cpp.
References Field< A >::get(), Id::isValid(), and RAISE_INVALID_ID.
PyObject* moose_Id_richCompare | ( | _Id * | self, |
PyObject * | other, | ||
int | op | ||
) |
Definition at line 755 of file vec.cpp.
References Id::id_, and IdType.
int moose_Id_setattro | ( | _Id * | self, |
PyObject * | attr, | ||
PyObject * | value | ||
) |
Definition at line 977 of file vec.cpp.
References Field< A >::get(), getFieldType(), Id::isValid(), moose_Id_getLength(), RAISE_INVALID_ID, Field< A >::setVec(), shortType(), and value.
Referenced by moose_Id_setField().
PyObject* moose_Id_setField | ( | _Id * | self, |
PyObject * | args | ||
) |
Definition at line 958 of file vec.cpp.
References Id::isValid(), moose_Id_setattro(), RAISE_INVALID_ID, and value.
PyObject* moose_Id_str | ( | _Id * | self | ) |
Definition at line 566 of file vec.cpp.
References Id::isValid(), and RAISE_INVALID_ID.
PyObject* moose_Id_subscript | ( | _Id * | self, |
PyObject * | op | ||
) |
Definition at line 730 of file vec.cpp.
References moose_Id_fillSlice(), moose_Id_getItem(), moose_Id_getLength(), SLICE_OBJ, and value.
PyDoc_STRVAR | ( | moose_Id_delete_doc | , |
"vec.delete() -> None""\n""\nDelete the underlying moose object. This will invalidate all""\nreferences to this object and any attempt to access it will raise a""\nValueError.""\n Example""\n--------""\n >> | , | ||
iaf.delete()""\n >> | , | ||
print iaf.path""\n\\""\n" | |||
) |
PyDoc_STRVAR | ( | moose_Id_setField_doc | , |
"setField(fieldname, value_vector) -> None\n""\n""Set the value of `fieldname` in all elements under this vec.\n""\n""Parameters\n""----------\n""fieldname: str\n"" field to be set.\n""value: sequence of values\n"" sequence of values corresponding to individual elements"" under this vec.\n""\n Example""\n--------""\n >> | , | ||
iaf.setField('Vm', 20)""\n >> | , | ||
print iaf.Vm""\n""\n >> | [20.20.20.20.20.20.20.20.20.20.], | ||
iaf.setField('Vm',(1, 2, 3, 4, 5, 6, 7, 8, 9, 10))""\n >> | , | ||
print iaf.Vm""\n""Notes\n""-----\n""This is an interface to SetGet::setVec""\n" | [1.2.3.4.5.6.7.8.9.10.] | ||
) |
PyDoc_STRVAR | ( | moose_Id_doc | , |
"An object uniquely identifying a moose array-element.\n""\n""array-elements are array-like objects which can have one or more"" single-elements within them."" vec can be traversed like a Python sequence and its each item is an"" element identifying single-objects contained in the array element.\n""\n""you can create multiple references to the same MOOSE object in Python."" As long as they have the same path/id | value, | ||
they all point to""the same entity in MOOSE.\n""\n""Field access are vectorized.For | example, | ||
if`comp`is a vec of"" | Compartmentsof size 10, | ||
which has a field called`Vm`as membrane | voltage, | ||
then""`comp.Vm`returns a""tuple containing the`Vm`value of all 10 single-elements in this""vec.There are a few special fields that are unique for vec and are not""vectorized.These are`path` | , | ||
`name` | , | ||
`value` | , | ||
`shape`and`className`.""There are two ways an vec can be | initialized, | ||
\n""(1) create a new array element or\n""(2) create a reference to an existing object.\n""\n""\n Constructor:""\n""\n vec(self, path=path, n=size, g=isGlobal, dtype=className)""\n""\n""\n Parameters""\n----------""\n path:str/vec/int""\n Path of an existing array element or for creating a new one.This has""\n the same format as unix file path:/{element1}/{element2}...""\n If there is no object with the specified | path, | ||
moose attempts to create""\n a new array element.For that to succeed everything until the last`/`""\n character must exist or an error is raised""\n""\n | Alternatively, | ||
path can be vec or integer value of the Id of an""\n existing vec object.The new object will be another reference to""\n the existing object.""\n""\n n:positive int""\n This is a positive integers specifying the size of the array element""\n to be created.Thus | n = 2 will create an vec with 2 elements.""\n ""\n g : int""\n Specify if this is a global or local element. Global elements are""\n shared between nodes in a computing cluster.""\n ""\n dtype: string""\n The vector will be of this moose-class.""\n ""\n Attributes:""\n -----------""\n path : str""\n Path of the vec. In moose vecs are organized in a tree structure"" like unix file system and the paths follow the same convention.""\n""\n name : str""\n Name of the vec.""\n""\n value : int/long""\n Numeric identifier of the vec. This is unique within a single"" execution. vec comparison is based on this value and its hash is also"" this. So you can compare and sort vecs and use them as dict keys.""\n""\n shape : tuple of ints""\n Dimensions of the vec (as shape in numpy.ndarray). Currently only"" one-dimensional vecs are implemented.""\n""\n className: str""\n The class of the moose object this vec contains. MOOSE core"" implements its own class system independent of Python. pymoose creates"" thin wrappers around them. This field provides you the moose class"" name as defined in C++""\n""\n ""\n Examples""\n ---------""\n >> , |
||
iaf | = moose.vec('/iaf', n=10, dtype='IntFire')""\n >> , |
||
iaf. | Vm = range(10)""\n >> , |
||
print iaf.Vm""\n 5.0""\n >> | [5], | ||
print iaf.Vm""\n array([0., 1., 2., 3., 4., 5., 6., 7., 8., 9.])" | |||
) |
|
static |
|
static |
|
static |
PyTypeObject IdType |
Definition at line 262 of file vec.cpp.
Referenced by MODINIT(), moose_copy(), moose_delete(), moose_element(), moose_ElementField_getId(), moose_getField(), moose_Id_init(), moose_Id_richCompare(), moose_loadModel(), moose_move(), moose_ObjId_getId(), moose_ObjId_getNeighbors(), moose_setCwe(), and to_py().
PyTypeObject ObjIdType |
Referenced by moose_Id_contains().
int verbosity |
Definition at line 163 of file moosemodule.cpp.
Referenced by convert_and_set_tuple_entry(), defineAllClasses(), defineClass(), defineDestFinfos(), defineElementFinfos(), defineLookupFinfos(), deleteObjId(), moose::getArgMap(), getFieldType(), and setup_runtime_env().