D
dd
Hi, all,
I found many limitation of C in the process of porting some matlab
files to C, but I'm going to stick to it this time. One problem is the
variadic function. C doesn't have overload
mechanism, right? And to use va_list and va_arg, etc. to realize the
variable
number of inputs to a function is OK, but I don't know how to express
the
missing variables in the function like below . Thank you very much if
anyone could help me out!
The matlab part is like below
function [output_firing_time, x,
y]=calculate_neuron(input_firing_times,delays,weights,tau,threshold,sim_time)
disp_fire_info=0;
%Activation Threshold
if nargin < 5 || threshold==-1
threshold=2;
end
%Time constant for spike response function
if nargin < 4 || tau==-1
tau=2;
end
%Delays
if nargin < 3 || min(delays==-1)
delays=[1 1 1];
end
%Weights
if nargin < 2 || ~iscell(weights)
weights=[1 1 1];
end
%Input Firing Times
if nargin < 1 || min(input_firing_times==-1)
input_firing_times=[0 1 2];
end
output_firing_time=sim_time(3)+1;
The c part
/*********************************************************/
*calculate_neuron(float *num_var,...)
{
va_list ap;
int count = 0;
float temp=numinputvar;
// to calculate the number of inputs
float x;
float ***y;
float output_firing_time;
float t_begin, t_interval,t_end;
float t_index[1000]=0;
float current_delay;
// int num_var=0;
int max=0;
int start_index=0;
// int num_inputs=0;
int j=1,i,k,n;
int indexdelay,index_input_firing;
int disp_fire_info=0;
va_start(ap,num_var);
//need to change, for input_firing times might be bigger than 100
// Basic Spiking Neural Network
while( temp != -10000.00000000000000 )
{
count++;
temp = va_arg( ap, float);
}
va_end( ap );
//Activation Threshold
if (num_var<5 || *threshold==-1)
*threshold=2;
//Time constant for spike response function
if (num_var<4 || *tau==-1)
*tau=2;
//delays
if (*delays==-1||*(delays+1)==-1||*(delays+2)==-1)
indexdelay=1;
if (num_var<3 ||indexdelay==1) // ||delays)
min(delays==-1) how to
port?
*delays=[1 1 1];
//weights
if (num_var<2 ) //~iscell(weights) ??
*weights=[1 1 1];
//Input Firing Times
if(*input_firing_times==-1||*(input_firing_times+1)==-1||*(input_firing_time
s+2)==-1)
index_input_firing=1;
if (num_var<1 || index_input_firing==1)
input_firing_times=[0 1 2];
I found many limitation of C in the process of porting some matlab
files to C, but I'm going to stick to it this time. One problem is the
variadic function. C doesn't have overload
mechanism, right? And to use va_list and va_arg, etc. to realize the
variable
number of inputs to a function is OK, but I don't know how to express
the
missing variables in the function like below . Thank you very much if
anyone could help me out!
The matlab part is like below
function [output_firing_time, x,
y]=calculate_neuron(input_firing_times,delays,weights,tau,threshold,sim_time)
disp_fire_info=0;
%Activation Threshold
if nargin < 5 || threshold==-1
threshold=2;
end
%Time constant for spike response function
if nargin < 4 || tau==-1
tau=2;
end
%Delays
if nargin < 3 || min(delays==-1)
delays=[1 1 1];
end
%Weights
if nargin < 2 || ~iscell(weights)
weights=[1 1 1];
end
%Input Firing Times
if nargin < 1 || min(input_firing_times==-1)
input_firing_times=[0 1 2];
end
output_firing_time=sim_time(3)+1;
The c part
/*********************************************************/
*calculate_neuron(float *num_var,...)
{
va_list ap;
int count = 0;
float temp=numinputvar;
// to calculate the number of inputs
float x;
float ***y;
float output_firing_time;
float t_begin, t_interval,t_end;
float t_index[1000]=0;
float current_delay;
// int num_var=0;
int max=0;
int start_index=0;
// int num_inputs=0;
int j=1,i,k,n;
int indexdelay,index_input_firing;
int disp_fire_info=0;
va_start(ap,num_var);
//need to change, for input_firing times might be bigger than 100
// Basic Spiking Neural Network
while( temp != -10000.00000000000000 )
{
count++;
temp = va_arg( ap, float);
}
va_end( ap );
//Activation Threshold
if (num_var<5 || *threshold==-1)
*threshold=2;
//Time constant for spike response function
if (num_var<4 || *tau==-1)
*tau=2;
//delays
if (*delays==-1||*(delays+1)==-1||*(delays+2)==-1)
indexdelay=1;
if (num_var<3 ||indexdelay==1) // ||delays)
min(delays==-1) how to
port?
*delays=[1 1 1];
//weights
if (num_var<2 ) //~iscell(weights) ??
*weights=[1 1 1];
//Input Firing Times
if(*input_firing_times==-1||*(input_firing_times+1)==-1||*(input_firing_time
s+2)==-1)
index_input_firing=1;
if (num_var<1 || index_input_firing==1)
input_firing_times=[0 1 2];