void LinearMechanism::create() { int i; lmfree(); i = 0; Object* o = *hoc_objgetarg(++i); if (strcmp(o->ctemplate->sym->name, "PythonObject") == 0) { f_callable_ = o; hoc_obj_ref(o); c_ = matrix_arg(++i); } else { f_callable_ = NULL; c_ = matrix_arg(1); } g_ = matrix_arg(++i); y_ = vector_arg(++i); if (ifarg(i + 2) && hoc_is_object_arg(i + 2) && is_vector_arg(i + 2)) { y0_ = vector_arg(++i); } b_ = vector_arg(++i); if (ifarg(++i)) { #if HAVE_IV Oc oc; #endif if (hoc_is_double_arg(i)) { nnode_ = 1; nodes_ = new Node*[1]; double x = chkarg(i, 0., 1.); Section* sec = chk_access(); nodes_[0] = node_exact(sec, x); nrn_notify_when_double_freed(&NODEV(nodes_[0]), this); }else{ Object* o = *hoc_objgetarg(i); check_obj_type(o, "SectionList"); SectionList* sl = new SectionList(o); sl->ref(); Vect* x = vector_arg(i+1); Section* sec; nnode_ = 0; nodes_ = new Node*[x->capacity()]; for (sec = sl->begin(); sec; sec = sl->next()) { nodes_[nnode_] = node_exact(sec, x->elem(nnode_)); nrn_notify_when_double_freed(&NODEV(nodes_[nnode_]), this); ++nnode_; } if (ifarg(i+2)) { elayer_ = vector_arg(i+2); } sl->unref(); } } model_ = new LinearModelAddition(c_, g_, y_, y0_, b_, nnode_, nodes_, elayer_, f_callable_); }
boolean special_pnt_call(Object* ob, Symbol* sym, int narg) { char* name = sym->name; if (strcmp(name, "loc") == 0) { int type = ob->ctemplate->symtable->last->subtype; int ptype = pnt_map[type]; if (narg != 1) { hoc_execerror("no argument", 0); } double x = hoc_look_inside_stack(narg-1, NUMBER)->val; Section* sec = chk_access(); Node* node = node_exact(sec, x); nrn_loc_point_process(ptype, ob2pntproc(ob), sec, node); hoc_pushx(x); return true; }else if (strcmp(name, "has_loc") == 0) { Point_process* p = ob2pntproc(ob); hoc_pushx(double(p != nil && p->sec != nil)); return true; }else if (strcmp(name, "get_loc") == 0) { hoc_pushx(get_loc_point_process(ob2pntproc(ob))); return true; }else{ return false; } }
void hoc_construct_point(Object* ob, int narg) { if (skip_) { //printf("skipped hoc_construct_point\n"); return; } //printf("%s is a pointprocess\n", hoc_object_name(ob)); int type = ob->ctemplate->symtable->last->subtype; int ptype = pnt_map[type]; Point_process* pnt = (Point_process*)create_point_process(ptype, ob); ob->u.dataspace[ob->ctemplate->dataspace_size - 1]._pvoid = (void*)pnt; assert(last_created_pp_ob_ == nil); last_created_pp_ob_ = ob; if (narg > 0) { double x = hoc_look_inside_stack(narg-1, NUMBER)->val; //printf("x=%g\n", x); Section* sec = chk_access(); Node* nd = node_exact(sec, x); //printf("ptype=%d pnt=%lx %s nd=%lx\n", ptype, (long)pnt, secname(sec), (long)nd); //printf("type=%d pointsym=%lx\n", type, pointsym[ptype]); //printf("type=%d from pointsym %s = %d\n", type, pointsym[ptype]->name, //pointsym[ptype]->subtype); nrn_loc_point_process(ptype, pnt, sec, nd); } }
static PyObject* seg_point_processes(NPySegObj* self) { Node* nd = node_exact(self->pysec_->sec_, self->x_); PyObject* result = PyList_New(0); for (Prop* p = nd->prop; p; p = p->next) { if (memb_func[p->type].is_point) { Point_process* pp = (Point_process*)p->dparam[1]._pvoid; PyObject* item = nrnpy_ho2po(pp->ob); assert(PyList_Append(result, item)==0); Py_XDECREF(item); } } return result; }
fmatrix() { if (ifarg(1)) { extern Node* node_exact(Section*, double); double x = chkarg(1, 0., 1.); int id = (int)chkarg(2, 1., 4.); Node* nd = node_exact(chk_access(), x); NrnThread* _nt = nd->_nt; switch (id) { case 1: ret(NODEA(nd)); break; case 2: ret(NODED(nd)); break; case 3: ret(NODEB(nd)); break; case 4: ret(NODERHS(nd)); break; } return; } nrn_print_matrix(nrn_threads); ret(1.); }
static PyObject* segment_iter(NPySegObj* self) { NPyMechObj* m = NULL; Node* nd = node_exact(self->pysec_->sec_, self->x_); Prop* p = nd->prop; m = PyObject_New(NPyMechObj, pmech_generic_type); for(;;) { if (!p) { break; } //printf("segment_iter %d %s\n", p->type, memb_func[p->type].sym->name); if (PyDict_GetItemString(pmech_types, memb_func[p->type].sym->name)){ //printf("segment_iter found\n"); break; } p = p->next; } m->pyseg_ = self; Py_INCREF(m->pyseg_); m->prop_ = p; m->first_iter_ = 1; return (PyObject*)m; }
static PyObject* segment_getattro(NPySegObj* self, PyObject* name) { Symbol* sym; Py_INCREF(name); char* n = PyString_AsString(name); //printf("segment_getattr %s\n", n); PyObject* result = 0; PyObject* otype; PyObject* rv; if (strcmp(n, "v") == 0) { Node* nd = node_exact(self->pysec_->sec_, self->x_); result = Py_BuildValue("d", NODEV(nd)); }else if ((otype = PyDict_GetItemString(pmech_types, n)) != NULL) { int type = PyInt_AsLong(otype); //printf("segment_getattr type=%d\n", type); Node* nd = node_exact(self->pysec_->sec_, self->x_); Prop* p = nrn_mechanism(type, nd); if (!p) { rv_noexist(self->pysec_->sec_, n, self->x_, 1); Py_DECREF(name); return NULL; } NPyMechObj* m = PyObject_New(NPyMechObj, pmech_generic_type); if (m == NULL) { Py_DECREF(name); return NULL; } m->pyseg_ = self; m->prop_ = p; Py_INCREF(m->pyseg_); result = (PyObject*)m; }else if ((rv = PyDict_GetItemString(rangevars_, n)) != NULL) { sym = ((NPyRangeVar*)rv)->sym_; if (ISARRAY(sym)) { NPyRangeVar* r = PyObject_New(NPyRangeVar, range_type); r->pyseg_ = self; Py_INCREF(r->pyseg_); r->sym_ = sym; r->isptr_ = 0; result = (PyObject*)r; }else{ int err; double* d = nrnpy_rangepointer(self->pysec_->sec_, sym, self->x_, &err); if (!d) { rv_noexist(self->pysec_->sec_, n, self->x_, err); result = NULL; }else{ result = Py_BuildValue("d", *d); } } }else if (strncmp(n, "_ref_", 5) == 0) { if (strcmp(n+5, "v") == 0) { Node* nd = node_exact(self->pysec_->sec_, self->x_); result = nrn_hocobj_ptr(&(NODEV(nd))); }else if ((sym = hoc_table_lookup(n+5, hoc_built_in_symlist)) != 0 && sym->type == RANGEVAR) { if (ISARRAY(sym)) { NPyRangeVar* r = PyObject_New(NPyRangeVar, range_type); r->pyseg_ = self; Py_INCREF(r->pyseg_); r->sym_ = sym; r->isptr_ = 1; result = (PyObject*)r; }else{ int err; double* d = nrnpy_rangepointer(self->pysec_->sec_, sym, self->x_, &err); if (!d) { rv_noexist(self->pysec_->sec_, n+5, self->x_, err); result = NULL; }else{ result = nrn_hocobj_ptr(d); } } }else{ rv_noexist(self->pysec_->sec_, n, self->x_, 2); result = NULL; } }else if (strcmp(n, "__dict__") == 0) { Node* nd = node_exact(self->pysec_->sec_, self->x_); result = PyDict_New(); assert(PyDict_SetItemString(result, "v", Py_None) == 0); assert(PyDict_SetItemString(result, "diam", Py_None) == 0); assert(PyDict_SetItemString(result, "cm", Py_None) == 0); for (Prop* p = nd->prop; p ; p = p->next) { if (p->type > CAP && !memb_func[p->type].is_point){ char* pn = memb_func[p->type].sym->name; assert(PyDict_SetItemString(result, pn, Py_None) == 0); } } }else{ result = PyObject_GenericGetAttr((PyObject*)self, name); } Py_DECREF(name); return result; }