Example #1
0
JNIEXPORT jobject JNICALL Java_neuron_Neuron_oGet
  (JNIEnv *env, jclass, jstring js){
	const char* s = env->GetStringUTFChars(js, 0);
	Symbol* sym = hoc_table_lookup(s, hoc_top_level_symlist);
	assert(sym && sym->type == OBJECTVAR);
	Object** po = hoc_top_level_data[sym->u.oboff].pobj;
	env->ReleaseStringUTFChars(js, s);
	jobject jo = h2jObject(*po);
	hoc_obj_unref(*po);
	return jo;
}
Example #2
0
HocCommand::~HocCommand() {
	if (obj_) {
		nrn_notify_pointer_disconnect(this);
	}
	if (s_) {
		delete s_;
	}
	if (po_) {
		hoc_obj_unref(po_);
	}
}
Example #3
0
JNIEXPORT jobject JNICALL Java_neuron_Neuron_hGetObjectField
  (JNIEnv *env, jclass, jlong v, jstring js){
	const char* s = env->GetStringUTFChars(js, 0);
	Object* o = (Object*)v;
	Symbol* sym = hoc_table_lookup(s, o->ctemplate->symtable);
	assert(sym && sym->type == OBJECTVAR);
	Object** po = o->u.dataspace[sym->u.oboff].pobj;
	env->ReleaseStringUTFChars(js, s);
	jobject jo = h2jObject(*po);
	hoc_obj_unref(*po);
	return jo;
}
Example #4
0
static double extra_scatter_gather_remove(void* v) {
	Object* o = *hoc_objgetarg(1);
	for (int direction=0; direction < 2; ++direction) {
		ExtraScatterList* esl = extra_scatterlist[direction];
		if (esl) for (int i = esl->count()-1; i >= 0; --i) {
			Object* o1 = esl->item(i);
			// if esl exists then python exists
			if ((*nrnpy_pysame)(o, o1)) {
				esl->remove(i);
				hoc_obj_unref(o1);
			}
		}
	}
	return 0.;
}
Example #5
0
JNIEXPORT void JNICALL Java_neuron_Neuron_hSetObjectField__Ljava_lang_String_2Ljava_lang_Object_2I
  (JNIEnv *env, jclass, jstring js, jobject joval, jint type){
	jnisave
	const char* s = env->GetStringUTFChars(js, 0);
	Symbol* sym = hoc_table_lookup(s, hoc_top_level_symlist);
	assert(sym && sym->type == OBJECTVAR);
	Object** po = hoc_top_level_data[sym->u.oboff].pobj;
	Object** poval = nj_j2hObject(joval, type);
	Object* old = *po;
	*po = *poval;
	(*po)->refcount++;
	hoc_obj_unref(old);
	env->ReleaseStringUTFChars(js, s);
	jnirestore
}
Example #6
0
void LinearMechanism::lmfree() {
    if (f_callable_) {
        hoc_obj_unref(f_callable_);
        f_callable_ = NULL;
    }
	if (model_) {
		delete model_;
		model_ = NULL;
	}
	if (nodes_) {
		nrn_notify_pointer_disconnect(this);
		nnode_ = 0;
		delete [] nodes_;
		nodes_ = NULL;
		elayer_ = NULL;
	}
}
Example #7
0
JNIEXPORT void JNICALL Java_neuron_Neuron_hocObjectUnref
    (JNIEnv *, jclass, jlong i) {
	Object* o = (Object*)i;
//printf("hocObjectUnref %d %s\n", (long)i, hoc_object_name(o));
	hoc_obj_unref(o);
}
Example #8
0
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);
}