示例#1
0
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_);
}
示例#2
0
JNIEXPORT jlong JNICALL Java_neuron_Neuron_vectorNew
  (JNIEnv *env, jclass, jint size){
	jnisave
	Vect* v = vector_new1(size);
	Object* ho = hoc_new_object(nrn_vec_sym, v);
	hoc_obj_ref(ho);
	jlong jc = (jlong)ho;
	jnirestore
	return jc;
}
示例#3
0
HocCommand::HocCommand(Object* pobj) {
	// must wrap a PyObject method or tuple of (method, arg1, ...)
	// hold a reference to the wrapped PyObject
	if (strcmp(pobj->ctemplate->sym->name, "PythonObject") != 0) {
		hoc_execerror(hoc_object_name(pobj), "not a PythonObject");
	}
	po_ = pobj;
	hoc_obj_ref(po_);
	s_ = NULL;
	obj_ = NULL;
}
示例#4
0
文件: cvodeobj.cpp 项目: nrnhines/nrn
static double extra_scatter_gather(void* v) {
	int direction = int(chkarg(1, 0, 1));
	Object* o = *hoc_objgetarg(2);
	check_obj_type(o, "PythonObject");
	ExtraScatterList* esl = extra_scatterlist[direction];
	if (!esl) {
		esl = new ExtraScatterList(2);
		extra_scatterlist[direction] = esl;
	}
	esl->append(o);
	hoc_obj_ref(o);
	return 0.;
}
示例#5
0
JNIEXPORT jlong JNICALL Java_neuron_Neuron_getNewHObject
  (JNIEnv *env, jclass, jstring name, jint narg){
	jnisave
	const char* cn = env->GetStringUTFChars(name, 0);
//	Symbol* s = hoc_table_lookup(cn, hoc_top_level_symlist);
	Symbol* s = hoc_lookup(cn);
if (!s || s->type != TEMPLATE) {
	printf("getNewHObject could not lookup %s or it is not a template.\n", cn);
	return 0;
}
	env->ReleaseStringUTFChars(name, cn);
	Object* o = hoc_newobj1(s, narg);
	hoc_obj_ref(o);
	jnirestore
	return (jlong)o;
}
示例#6
0
static jobject h2jObject(Object* o) {
	jobject jo;
	if (o == 0) {
		return 0;
	}
	hoc_obj_ref(o);
	// one of several possibilities here
	if (o->ctemplate->id < 0) { // a Java object
		jo = (jobject)o->u.this_pointer;
	}else if (o->ctemplate->sym == nrn_jobj_sym) {
		// an unregistered java object
		jo = (jobject)o->u.this_pointer;
	}else{ //encapsulate in HocObject, HocVector, etc.
		jo = nj_encapsulate(o);
	}
	return jo;
}
示例#7
0
文件: hocprax.c 项目: nrnhines/nrn
void fit_praxis(void) {
	extern Symbol* hoc_lookup();
	extern char* gargstr();
	char* after_quad;	
	int i;
	double err, fmin;
	double* px;
	/* allow nested calls to fit_praxis. I.e. store all the needed
	   statics specific to this invocation with proper reference
	   counting and then unref/destoy on exit from this invocation.
	   Before the prax call save the statics from earlier invocation
	   without increasing the
	   ref count and on exit restore without decreasing the ref count.
	*/
	   
	/* save before setting statics, restore after prax */
	double minerrsav, *minargsav, maxstepsizesav, tolerancesav;
	long int printmodesav, nvarsav;
	Symbol* efun_sym_sav;
	Object* efun_py_save, *efun_py_arg_save;
	void* vec_py_save_save;
	
	/* store statics specified by this invocation */
	/* will be copied just before calling prax */
	double minerr_, *minarg_;
	long int nvar_;
	Symbol* efun_sym_;
	Object* efun_py_, *efun_py_arg_;
	void* vec_py_save_;

	minerr_ = 0.0;
	nvar_ = 0;
	minarg_ = NULL;
	efun_sym_ = NULL;
	efun_py_ = NULL;
	efun_py_arg_ = NULL;
	vec_py_save_ = NULL;
	
	fmin = 0.;

    if (hoc_is_object_arg(1)) {
	assert(nrnpy_praxis_efun);
	efun_py_ = *hoc_objgetarg(1);
	hoc_obj_ref(efun_py_);
	efun_py_arg_ = *vector_pobj(vector_arg(2));
	hoc_obj_ref(efun_py_arg_);
	vec_py_save_ = vector_new2(efun_py_arg_->u.this_pointer);
	nvar_ = vector_capacity(vec_py_save_);
	px = vector_vec(vec_py_save_);
    }else{
	nvar_ = (int)chkarg(1, 0., 1e6);
	efun_sym_ = hoc_lookup(gargstr(2));
	if (!efun_sym_
	   || (efun_sym_->type != FUNCTION
	      && efun_sym_->type != FUN_BLTIN)) {
		hoc_execerror(gargstr(2), "not a function name");
	}
	
	if (!hoc_is_pdouble_arg(3)) {
		void* vec = vector_arg(3);
		if (vector_capacity(vec) != nvar_) {
			hoc_execerror("first arg not equal to size of Vector",0);
		}
		px = vector_vec(vec);
	}else{
		px = hoc_pgetarg(3);
	}
    }
	minarg_ = (double*)ecalloc(nvar_, sizeof(double));

	if (maxstepsize == 0.) {
		hoc_execerror("call attr_praxis first to set attributes", 0);
	}
	machep = 1e-15;
		
	if (ifarg(4)) {
		after_quad = gargstr(4);
	}else{
		after_quad = (char*)0;
	}

	/* save the values set by earlier invocation */
	minerrsav = minerr;
	minargsav = minarg;
	tolerancesav = tolerance;
	maxstepsizesav = maxstepsize;
	printmodesav = printmode;
	nvarsav = nvar;
	efun_sym_sav = hoc_efun_sym;
	efun_py_save = efun_py;
	efun_py_arg_save = efun_py_arg;
	vec_py_save_save = vec_py_save;


	/* copy this invocation values to the statics */
	minerr = minerr_;
	minarg = minarg_;
	nvar = nvar_;
	hoc_efun_sym = efun_sym_;
	efun_py = efun_py_;
	efun_py_arg = efun_py_arg_;
	vec_py_save = vec_py_save_;
	

	minerr=1e9;
	err = praxis(&tolerance, &machep, &maxstepsize,	nvar, &printmode,
		px, efun, &fmin, after_quad);
	err = minerr;
	if (minerr < 1e9) {
		for (i=0; i<nvar; ++i) { px[i] = minarg[i]; }
	}

	/* restore the values set by earlier invocation */
	minerr = minerrsav;
	minarg = minargsav;
	tolerance = tolerancesav;
	maxstepsize = maxstepsizesav;
	printmode = printmodesav;
	nvar = nvar_; /* in case one calls prax_pval */
	hoc_efun_sym = efun_sym_sav;
	efun_py = efun_py_save;
	efun_py_arg = efun_py_arg_save;
	vec_py_save = vec_py_save_save;

	if (efun_py_) {
		double* px = vector_vec(efun_py_arg_->u.this_pointer);
		for (i=0; i < nvar_; ++i) {
			px[i] = minarg_[i];
		}
		hoc_obj_unref(efun_py_);
		hoc_obj_unref(efun_py_arg_);
		vector_delete(vec_py_save_);
	}
	if (minarg_) {
		free(minarg_);
	}
	hoc_retpushx(err);
}