* extractMoments
* =============================================================================
*/
- public float[]
+ public static float[]
extractMoments (float []data, int num_elts, int num_moments)
{
float[] moments = new float[num_moments];
+ float mzero=0.0f;
for (int i = 0; i < num_elts; i++) {
- moments[0] += data[i];
+ mzero += data[i];
}
- moments[0] = moments[0] / num_elts;
+ moments[0] = mzero / num_elts;
for (int j = 1; j < num_moments; j++) {
moments[j] = 0;
for (int i = 0; i < num_elts; i++) {
- moments[j] += Math.pow((data[i]-moments[0]), j+1);
+ moments[j] += (float) Math.pow((data[i]-moments[0]), j+1);
}
moments[j] = moments[j] / num_elts;
}
* zscoreTransform
* =============================================================================
*/
- public void
+ public static void
zscoreTransform (float[][] data, /* in & out: [numObjects][numAttributes] */
int numObjects,
int numAttributes)
* cluster_exec
* =============================================================================
*/
- public void
+ public static void
cluster_exec (
int nthreads, /* in: number of threads*/
int numObjects, /* number of input objects */
int itime;
int nclusters;
- float[][] tmp_cluster_centres = null;
+ float[][] tmp_cluster_centres;
int[] membership = new int[numObjects];
Random randomPtr = new Random();
- randomPtr = randomPtr.random_alloc(randomPtr);
+ randomPtr.random_alloc();
if (kms.use_zscore_transform == 1) {
zscoreTransform(attributes, numObjects, numAttributes);
*/
for (nclusters = kms.min_nclusters; nclusters <= kms.max_nclusters; nclusters++) {
- randomPtr.random_seed(randomPtr, 7);
+ randomPtr.random_seed(7);
args.nclusters = nclusters;
Normal norm = new Normal();
itime++;
} /* nclusters */
-
- randomPtr = null;
}
}
common_euclidDist2 (float[] pt1, float[] pt2, int numdims)
{
int i;
- float ans = 0.0;
+ float ans = 0.0f;
for (i = 0; i < numdims; i++) {
ans += (pt1[i] - pt2[i]) * (pt1[i] - pt2[i]);
int index = -1;
int i;
//double max_dist = FLT_MAX;
- float max_dist = 3.40282347e+38;
- float limit = 0.99999;
+ float max_dist = (float)3.40282347e+38;
+ float limit = (float) 0.99999;
/* Find the cluster center id with min distance to pt */
for (i = 0; i < npts; i++) {
min_nclusters = 4;
isBinaryFile = 0;
use_zscore_transform = 1;
- threshold = 0.001;
+ threshold = (float) 0.001;
best_nclusters = 0;
}
}
}
- Cluster clus = new Cluster();
- clus.cluster_exec(nthreads,
+ Cluster.cluster_exec(nthreads,
numObjects,
numAttributes,
attributes, // [numObjects][numAttributes]
for(int ii=0;ii<x;ii++)
newbytes[ii+oldbytes.length]=b[ii];
x++; //skip past space
- if (j>=0)
- buf[i][j]=ByteToFloat(newbytes, 0, newbytes.length);
+ if (j>=0) {
+ buf[i][j]=(float)Double.parseDouble(new String(newbytes, 0, newbytes.length));
+ }
j++;
oldbytes=null;
}
}
//otherwise x is beginning of character string, y is end
- if (j>=0)
- buf[i][j]= ByteToFloat(b, x, y-x);
+ if (j>=0) {
+
+ buf[i][j]=(float)Double.parseDouble(new String(b,x,y-x));
+ }
x=y;//skip to end of number
x++;//skip past space
j++;
}
inputFile.close();
}
-
- /**
- * Convert a string into float
- **/
- public static float ByteToFloat (byte[] str, int offset, int length) {
- float left=0.0d;
- float right=0.0d;
- int i;
- for(i=0;i<length;i++) {
- if (str[i+offset]=='.')
- break;
- left=left*10+(str[i+offset]-'0');
- }
- i++; //skip past decimal point
- float multiplier=0.1d;
- for(;i<length;i++) {
- right+=multiplier*(str[i+offset]-'0');
- multiplier*=0.1d;
- }
- return left+right;
- }
}
/* =============================================================================
float[][] clusters = args.clusters;
intwrapper[] new_centers_len = args.new_centers_len;
float[][] new_centers = args.new_centers;
- float delta = 0.0;
+ float delta = 0.0f;
int index, start, stop;
start = myId * CHUNK;
* membership[i] cannot be changed by other threads
*/
if (membership[i] != index) {
- delta += 1.0;
+ delta += 1.0f;
}
/* Assign the membership to object i */
/* Randomly pick cluster centers */
for (int i = 0; i < nclusters; i++) {
- int n = (int)(randomPtr.random_generate(randomPtr) % npoints);
+ int n = (int)(randomPtr.random_generate() % npoints);
for (int j = 0; j < nfeatures; j++) {
clusters[i][j] = feature[n][j];
}
int loop = 0;
do {
- delta = 0.0d;
+ delta = (float) 0.0;
args.feature = feature;
args.nfeatures = nfeatures;
if (new_centers_len[i] > 0) {
clusters[i][j] = new_centers[i][j] / new_centers_len[i];
}
- new_centers[i][j] = 0.0; /* set back to 0 */
+ new_centers[i][j] = (float)0.0; /* set back to 0 */
}
new_centers_len[i] = 0; /* set back to 0 */
}
/**
* Work done by primary thread in parallel with other threads
**/
- thread_work(GlobalArgs args) {
+ void thread_work(GlobalArgs args) {
Barrier.enterBarrier();
Normal.work(0, args); //threadId = 0 because primary thread
Barrier.enterBarrier();
N = 624;
M = 397;
mt = new long[N];
- mti = 0;
+ mti = N;
MATRIX_A = 0x9908b0dfL; /* constant vector a */
UPPER_MASK = 0x80000000L; /* most significant w-r bits */
LOWER_MASK = 0x7fffffffL; /* least significant r bits */
}
- public Random random_alloc(Random rand) {
- init_genrand(rand, rand.RANDOM_DEFAULT_SEED);
- return rand;
+ public void random_alloc() {
+ init_genrand(this.RANDOM_DEFAULT_SEED);
}
/* initializes mt[N] with a seed */
- public void init_genrand(Random rand, long s) {
+ public void init_genrand(long s) {
int mti;
-
- rand.mt[0]= s & 0xFFFFFFFFL;
- for (mti=1; mti<rand.N; mti++) {
- rand.mt[mti] = (1812433253L * (rand.mt[mti-1] ^ (rand.mt[mti-1] >> 30)) + mti);
+ mt[0]= s & 0xFFFFFFFFL;
+ for (mti=1; mti<N; mti++) {
+ mt[mti] = (1812433253L * (mt[mti-1] ^ (mt[mti-1] >> 30)) + mti);
/* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */
/* In the previous versions, MSBs of the seed affect */
/* only MSBs of the array mt[]. */
/* 2002/01/09 modified by Makoto Matsumoto */
- rand.mt[mti] &= 0xFFFFFFFFL;
+ mt[mti] &= 0xFFFFFFFFL;
/* for >32 bit machines */
}
-
- rand.mti = mti;
+ this.mti=mti;
}
- public void random_seed(Random rand, long seed) {
- init_genrand(rand, seed);
+ public void random_seed(long seed) {
+ init_genrand(seed);
}
- public long random_generate(Random rand) {
- return genrand_int32(rand);
+ public long random_generate() {
+ return genrand_int32();
}
//public static long genrand_int32(long[] mt, long mtiPtr) {
- public long genrand_int32(Random rand) {
+ public long genrand_int32() {
long y;
long[] mag01= new long[2];
mag01[0] = 0x0L;
- mag01[1] = rand.MATRIX_A;
- int mti = rand.mti;
+ mag01[1] = MATRIX_A;
+ int mti = this.mti;
/* mag01[x] = x * MATRIX_A for x=0,1 */
- if (mti >= rand.N) { /* generate N words at one time */
+ if (mti >= N) { /* generate N words at one time */
int kk;
- if (mti == rand.N+1) /* if init_genrand() has not been called, */
- init_genrand(rand, 5489L); /* a default initial seed is used */
+ if (mti == N+1) /* if init_genrand() has not been called, */
+ init_genrand(5489L); /* a default initial seed is used */
- for (kk=0;kk<rand.N-rand.M;kk++) {
- y = (rand.mt[kk]&rand.UPPER_MASK)|(rand.mt[kk+1]&LOWER_MASK);
- rand.mt[kk] = rand.mt[kk+M] ^ (y >> 1) ^ mag01[(int)(y & 0x1L)];
+ for (kk=0;kk<N-M;kk++) {
+ y = (mt[kk]&UPPER_MASK)|(mt[kk+1]&LOWER_MASK);
+ mt[kk] = mt[kk+M] ^ (y >> 1) ^ mag01[(int)(y & 0x1L)];
}
- for (;kk<rand.N-1;kk++) {
- y = (rand.mt[kk]&rand.UPPER_MASK)|(rand.mt[kk+1]&LOWER_MASK);
- rand.mt[kk] = rand.mt[kk+(M-N)] ^ (y >> 1) ^ mag01[(int)(y & 0x1L)];
+ for (;kk<N-1;kk++) {
+ y = (mt[kk]&UPPER_MASK)|(mt[kk+1]&LOWER_MASK);
+ mt[kk] = mt[kk+(M-N)] ^ (y >> 1) ^ mag01[(int)(y & 0x1L)];
}
- y = (rand.mt[N-1]&rand.UPPER_MASK)|(rand.mt[0]&LOWER_MASK);
- rand.mt[N-1] = rand.mt[M-1] ^ (y >> 1) ^ mag01[(int)(y & 0x1L)];
+ y = (mt[N-1]&UPPER_MASK)|(mt[0]&LOWER_MASK);
+ mt[N-1] = mt[M-1] ^ (y >> 1) ^ mag01[(int)(y & 0x1L)];
mti = 0;
}
- y = rand.mt[mti++];
+ y = mt[mti++];
/* Tempering */
y ^= (y >> 11);
y ^= (y << 15) & 0xefc60000L;
y ^= (y >> 18);
- rand.mti = mti;
+ this.mti = mti;
return y;
}
GlobalArgs.java \
../../../ClassLibrary/JavaSTM/Barrier.java
FLAGS=-mainclass ${MAINCLASS} -singleTM -optimize -debug -dcopts -joptimize -stmstats -fastmemcpy
-FLAGS2=-mainclass ${MAINCLASS} -singleTM -optimize -debug -joptimize -dcopts -fastmemcpy
+FLAGS2=-mainclass ${MAINCLASS} -singleTM -optimize -debug -joptimize -dcopts -fastmemcpy -abcclose
FLAGS3=-mainclass ${MAINCLASS} -optimize -debug -joptimize -thread
}
public static String valueOf(double val) {
- int i = 0, j = 0, k = 0;
- long nodecimal = 0;
- double decimal = 1.0d, valueA = 0.0d;
- StringBuffer output = new StringBuffer();
-
- for(i = 0; decimal != nodecimal; i++) {
- long basePower = 1;
- for(int x=0; x<i; x++) {
- basePower*= 10;
- }
- nodecimal = (long) (val*basePower);
- decimal = val*basePower;
- } //i = place counted from right that decimal point appears
-
- valueA = nodecimal; //valueA = val with no decimal point (val*10^i)
-
- for(j = 0; decimal >= 0; j++) {
- long basePower = 1;
- for(int x=0; x<j; x++) {
- basePower*= 10;
- }
- nodecimal = (long) (valueA - basePower);
- decimal = (double) nodecimal;
- } //j-1 = number of digits
-
- i--;
- j--;
- decimal = 0;
-
- for(k = j; k > 0; k--) {
- if(k == i) { //if a decimal point was previously found
- //insert it where its meant to be
- output.append((char)46);
- }
- long basePower = 1;
- for(int x=0; x<(k-1); x++) {
- basePower*= 10;
- }
- nodecimal = ((long) (valueA - decimal) / basePower);
- decimal += nodecimal*basePower;
- output.append((char)(48 + nodecimal));
- }
-
- return output.toString();
- }
-
- public static long basePower(int x, int y) {
- long t = 1;
- for(int i=0; i<y; i++) {
- t *= x;
- }
- return t;
- }
+ char[] chararray=new char[10];
+ String s=new String();
+ s.offset=0;
+ s.count=convertdoubletochar(val, chararray);
+ s.value=chararray;
+ return s;
+ }
+
+ public static native int convertdoubletochar(double val, char [] chararray);
public static String valueOf(long x) {
int length=0;
#endif
}
+#ifdef D___Double______nativeparsedouble____L___String___
+double CALL01(___Double______nativeparsedouble____L___String___,struct ___String___ * ___str___) {
+ int length=VAR(___str___)->___count___;
+ int maxlength=(length>60)?60:length;
+ char str[maxlength+1];
+ struct ArrayObject * chararray=VAR(___str___)->___value___;
+ int i;
+ int offset=VAR(___str___)->___offset___;
+ for(i=0; i<maxlength; i++) {
+ str[i]=((short *)(((char *)&chararray->___length___)+sizeof(int)))[i+offset];
+ }
+ str[i]=0;
+ double d=atof(str);
+ return d;
+}
+#endif
+
+#ifdef D___String______convertdoubletochar____D__AR_C
+int CALL12(___String______convertdoubletochar____D__AR_C, double ___val___, double ___val___, struct ArrayObject ___chararray___) {
+ int length=VAR(___chararray___)->___length___;
+ char str[length];
+ int i;
+ int num=snprintf(str, length, "%f",___val___);
+ if (num>=length)
+ num=length-1;
+ for(i=0; i<length; i++) {
+ ((short *)(((char *)&VAR(___chararray___)->___length___)+sizeof(int)))[i]=(short)str[i];
+ }
+ return num;
+}
+#endif
+
void CALL11(___System______exit____I,int ___status___, int ___status___) {
#ifdef TRANSSTATS
printf("numTransCommit = %d\n", numTransCommit);
#endif
#endif
-
/* Converts C character arrays into Java strings */
#ifdef PRECISE_GC
__attribute__((malloc)) struct ___String___ * NewString(void * ptr, const char *str,int length) {