This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
egcs 1.1 bug
- To: gcc-bugs at gcc dot gnu dot org
- Subject: egcs 1.1 bug
- From: Mark van Rossum <vrossum at swallow dot bio dot brandeis dot edu>
- Date: Wed, 13 Oct 1999 15:19:12 -0400 (EDT)
Hi,
I discovered a bug with egcs 1.1.
I'm sure something is screwed up in my code, but I just follow the
message: "please submit bug report".
Btw, thanks for all your beautifull programs !
g++ -Wall -O3 -g -c pw.cc -o pw.o
histogram.hh: In method `void Histogram::filter(int = 3)':
In file included from pw.cc:19:
histogram.hh:161: warning: comparison between signed and unsigned
pw.cc: In function `void do_sim_step(class Histogram &)':
pw.cc:110: Internal compiler error 390.
pw.cc:110: Please submit a full bug report to `egcs-bugs@egcs.cygnus.com'.
pw.cc:110: See <URL:http://egcs.cygnus.com/faq.html#bugreport> for
details.
make: *** [pw.o] Error 1
see also attachments
System: redhat 6.1, PII-400
Mark van Rossum
==== vrossum@swallow.bio.brandeis.edu =====
phone:(781)-736-2319; home:(617)-864-1802; fax:(617)-736-3107
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66/specs
gcc version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)
/usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66/cpp -lang-c++ -v -undef -D__GNUC__=2 -D__GNUG__=2 -D__cplusplus -D__GNUC_MINOR__=91 -D__ELF__ -Dunix -Di386 -D__i386__ -Dlinux -D__ELF__ -D__unix__ -D__i386__ -D__i386__ -D__linux__ -D__unix -D__i386 -D__linux -Asystem(posix) -D__EXCEPTIONS -D__OPTIMIZE__ -g -Wall -Asystem(unix) -Acpu(i386) -Amachine(i386) -Di386 -D__i386 -D__i386__ -D__tune_i386__ pw.cc pw.ii
GNU CPP version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release) (i386 Linux/ELF)
#include "..." search starts here:
#include <...> search starts here:
/usr/include/g++-2
/usr/local/include
/usr/i386-redhat-linux/include
/usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66/include
/usr/include
End of search list.
/usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66/cc1plus pw.ii -quiet -dumpbase pw.cc -g -O3 -Wall -version -o pw.s
GNU C++ version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release) (i386-redhat-linux) compiled by GNU C version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release).
histogram.hh: In method `void Histogram::filter(int = 3)':
In file included from pw.cc:19:
histogram.hh:161: warning: comparison between signed and unsigned
pw.cc: In function `void do_sim_step(class Histogram &)':
pw.cc:110: Internal compiler error 390.
pw.cc:110: Please submit a full bug report to `egcs-bugs@egcs.cygnus.com'.
pw.cc:110: See <URL:http://egcs.cygnus.com/faq.html#bugreport> for details.
/*
The distribution of synaptic weights
Using Bi&Poo fig 5.
Numerically look for stability contition
*/
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <fstream>
#include <vector>
#include <string>
#include <nr.hh>
#include <nrutil.hh>
long glob_idum = -1;
#include "histogram.hh"
#include "trace.hh"
double ltp_chance_nonorm(double w){
// should be >= ltd_chance_nonorm....
//return 0.2 + w/200; // w;
return 0.6;
//return 0.3*log10(w+1);
}
double ltd_chance_nonorm(double w){
return 1.0;
// we can keep this fixed
}
double ltp_chance(double w){
// normalized chances
// should not matter ?
return ltp_chance_nonorm(w)/(ltp_chance_nonorm(w)+ltd_chance_nonorm(w));
}
double ltd_chance(double w){
return ltd_chance_nonorm(w)/(ltp_chance_nonorm(w)+ltd_chance_nonorm(w));
}
double dw_ltp(double w){
const double c = 1;
const double w_max = 800;
const double eps = 1; // to prevent singul. at w=0
const bool addnoiseQ = true;
const double sd = 0.1;
double dw;
dw = -w*c*log10((w+eps)/w_max);
if (addnoiseQ){
dw *= (1.0 + sd*gasdev(&glob_idum));
}
return dw;
}
double dw_ltd(double w){
const bool addnoiseQ = true;
const double sd = 0.1;
double dw0 = -0.2;
if (addnoiseQ){
dw0 *= (1.0 + sd*gasdev(&glob_idum));
}
return w*dw0;
}
void do_sim_step(Histogram& histo){
int i;
double w, new_w;
double delta_p; // amount of LTP/ LTD
double pw; // current histogram value =P(w)
double dist;
const double rate = 0.1;
const bool printQ = false;
const int div = 10;
// copy w -> new_w // probably very slow now
static Histogram histo_new = histo;
for (i=0; i< histo.size(); i++){
w = histo.get_x(i);
pw = histo.getpoint_i(i);
// LTD
delta_p = ltd_chance_nonorm(w)*pw *rate;
// delta_p = ltd_chance(w)*pw *rate;
new_w = w + dw_ltd(w)/div;
if (printQ)
cout << "LTD w= " << w << " => " << new_w << endl;
histo_new.add( new_w, delta_p);
histo_new.add( w, -delta_p);
// LTP
delta_p = ltp_chance_nonorm(w)*pw *rate;
new_w = w + dw_ltp(w)/div;
if (printQ)
cout << "LTP w= " << w << " => " << new_w << endl;
histo_new.add( new_w, delta_p);
histo_new.add( w, -delta_p);
}
histo_new.check_norm();
dist = histo.getdist(histo_new);
cout << distance << endl;
histo = histo_new;
}
void make_bi_poo_plot(){
double w_step =5;
Trace tdw_ltp(w_step);
Trace tdw_ltd(w_step);
for (double w= 1; w< 1000; w+= w_step){
tdw_ltp.appendpoint( dw_ltp(w)/w+1 );
tdw_ltd.appendpoint( dw_ltd(w)/w+1 );
}
tdw_ltd.plot("dw_ltd");
tdw_ltp.plot("dw_ltp");
}
int main(){
double time;
const double timestep =1;
const double endtime =1000;
const int wmax =1000;
//make_bi_poo_plot();
Histogram histo(wmax,1);
histo.set_one();
histo.check_norm();
for (time=1; time <= endtime ; time += timestep){
do_sim_step(histo);
// histo.plot();
// exit(1);
}
histo.plot();
exit(0);
}
#include <string>
class Histogram{
/* this class contains normalized histogram
based on Trace.hh */
public:
/* Histogram (){
cout << "empty Histogram constructor called" << endl;
}
*/
Histogram (int thenbins, double thexscale){
nbins = thenbins;
ndata = 0;
hist.insert(0, nbins, 0.0);
xscale = thexscale;
xmin = 0.0;
xmax = xscale * nbins;
};
~Histogram(){};
void setscale(double thexscale){
xscale = thexscale;
};
int size(){
return hist.size();
}
double getpoint_i(int index){
if (index >= 0 && index < nbins )
return (hist[index]);
else{
cerr << "Subscription error in Histogram "<< endl;
cerr << "nbins = " << nbins << endl;
return(-1);
}
};
double getpoint(double x){
return (getpoint_i( get_index(x) ));
};
int get_index(double x){
unsigned int index;
index = (int) (x/xscale);
if (index > hist.size() ) {
cerr << "Out of range subscript in Histogram::get_index. \n index = "<< index
<< " x= " << x << ", xscale= " << xscale
<< "size = " << hist.size() << endl;
exit(1);
};
return(index);
};
double get_x(int index){
return(index*xscale);
};
void add(double x, double add){
hist[get_index(x)] += add;
ndata ++;
};
void set_one(){
unsigned int i;
for (i= 0; i< hist.size(); i++){
hist[i] = 1;
}
normalize();
};
void normalize(){
double norm ;
unsigned int i;
norm = getarea(xmin, xmax);
if (norm != 0.0){
for (i= 0; i< hist.size(); i++){
hist[i] /= norm;
}
}
else { // assume everything was zero
cout << "Warning:Norm -> init " << endl;
for (i= 0; i< hist.size(); i++){
hist[i] = 1;
}
normalize();
}
}
void check_norm(){
double norm ;
double eps = 1e-6;
norm = getarea(xmin, xmax);
if (fabs(norm -1.0) > eps ){
cerr << "Normalization gone " << endl;
}
}
double getarea(){
return(getarea(xmin, xmax));
};
double getarea(double x_start , double x_end ){
double area = 0 ;
int i,imin, imax;
imin = get_index(x_start);
imax = get_index(x_end);
for (i= imin; i<= imax; i++){
area += hist[i];
}
return(area);
};
double getmax(){
return(getmax(xmin, xmax));
};
// max in restricted region
double getmax(double x_start , double x_end ){
double max;
int i,imin, imax;
imin = get_index(x_start);
imax = get_index(x_end);
max = hist[imin];
for (i= imin; i<= imax; i++){
if (hist[i] > max) max = hist[i];
}
return(max);
};
void filter(int filterlen =3){
// boxcar filter
unsigned int i,j;
vector <double> temp(nbins+1);
if (filterlen==1) return;
if (filterlen % 2 != 1){
cout << "histogram.filter Filterlen should be odd" << endl;
filterlen ++;
}
for (i = 0+(filterlen-1)/2; i <= hist.size()-(filterlen-1)/2; i++){
temp[i]=0.0;
for (j = i - (filterlen-1)/2; j<= i + (filterlen-1)/2; i++){
temp[i]+= hist[j];
}
temp[i] /= filterlen;
}
for (i = 0 + (filterlen-1)/2; i <= nbins-(filterlen-1)/2; i++){
hist[i] = temp[i];
}
};
double getdist(Histogram that){
double dist = 0.0;
unsigned int i;
// usr abs norm, faster
for (i=0; i< hist.size(); i++){
dist += fabs(this->hist[i] - that.hist[i]);
}
return dist / hist.size();
}
void plot(string plotname= "plot.dat"){
unsigned int i;
char cmdstring[100];
string options = " -noask" ;
ofstream plot_stream(plotname.c_str());
for (i= 0; i < hist.size(); i++){
plot_stream << get_x(i) << " "
<< hist[i] << endl;
}
sprintf(cmdstring, "xmgr %s %s &", options.c_str(), plotname.c_str() );
system(cmdstring );
};
// variables
double xscale;
double xmin, xmax;
int nbins;
long ndata; // # measured events, only update with add
vector <double> hist;
};
#include <vector>
class Trace{
/* this class contains (time, y) arrays
useful for all kinds of simulation output */
public:
Trace(double thetimestep){
starttime = 0.0; // other values not implemented
timestep = thetimestep; //default value...
endtime = 0;
};
~Trace(){};
void clear(){
values.clear();
};
// to implement: filter, max/min, area, average,
// plot, add two traces, noise trace
//
void settimestep(double thetimestep){
timestep = thetimestep;
};
void appendpoint(double thevalue){
values.push_back(thevalue);
endtime += timestep;
}
double getpoint_i(int index){
return (values[index]);
}
double getpoint(double time){
return (getpoint_i( get_index(time) ));
};
int get_index(double time){
unsigned int index;
index = (int) (time/timestep);
if (index > values.size() ) {
cerr << "Out of range subscript in Trace::get_index index = "<< index
<< endl;
};
return(index);
};
double get_time(int index){
return(index*timestep);
};
double getarea(){
return(getarea(starttime, endtime));
};
double getarea(double t_start , double t_end ){
double area = 0 ;
int i,imin, imax;
imin = get_index(t_start);
imax = get_index(t_end);
for (i= imin; i<= imax; i++){
area += values[i];
}
return(area * timestep);
};
double getmax(){
return(getmax(starttime, endtime));
};
// max in restricted region
double getmax(double t_start , double t_end ){
double max;
int i,imin, imax;
imin = get_index(t_start);
imax = get_index(t_end);
max = values[imin];
for (i= imin; i<= imax; i++){
if (values[i] > max) max = values[i];
}
return(max);
};
void set_zero(){
unsigned int i;
for (i= 0; i < values.size(); i++){
values[i] =0.0;
}
};
void plot(string plotname= "plot.dat"){
unsigned int i;
char cmdstring[100];
string options = " -noask" ;
ofstream plot_stream(plotname.c_str());
for (i= 0; i < values.size(); i++){
plot_stream << get_time(i) << " "
<< values[i] << endl;
}
sprintf(cmdstring, "xmgr %s %s &", options.c_str(), plotname.c_str() );
system(cmdstring );
};
void add_Gauss_noise(double std_dev){
unsigned int i;
// update, filtered noise is usefull as well
for (i= 0; i < values.size(); i++){
values[i] += std_dev * gasdev(&glob_idum);
}
};
int size(){
return(values.size() );
};
// variables
double timestep;
double starttime;
double endtime;
vector <double> values;
};