use of maspack.util.FunctionTimer in project artisynth_core by artisynth.
the class SVDecompositionTest method checkTiming.
public void checkTiming(int nr, int nc) {
int nd = Math.min(nr, nc);
MatrixNd M1 = new MatrixNd(nr, nc);
M1.setRandom();
MatrixNd U = new MatrixNd(nr, nd);
MatrixNd V = new MatrixNd(nc, nd);
VectorNd s = new VectorNd(nd);
SVDecomposition svd = new SVDecomposition();
int cnt = 10000;
FunctionTimer timer = new FunctionTimer();
timer.start();
for (int i = 0; i < cnt; i++) {
svd.factor(M1);
svd.get(U, s, V);
}
timer.stop();
System.out.println("our svd: " + timer.result(cnt));
System.out.println(s);
// System.out.println ("U=\n" + U.toString("%9.5f"));
// System.out.println ("V=\n" + V.toString("%9.5f"));
// System.out.println ("s=" + s.toString("%9.5f"));
// javax.vecmath.GMatrix GM = new javax.vecmath.GMatrix(nr,nc);
// for (int i=0; i<nr; i++)
// { for (int j=0; j<nc; j++)
// { GM.setElement (i, j, M1.get(i,j));
// }
// }
// javax.vecmath.GMatrix GU = new javax.vecmath.GMatrix(nr,nd);
// javax.vecmath.GMatrix GV = new javax.vecmath.GMatrix(nc,nd);
// javax.vecmath.GMatrix GS = new javax.vecmath.GMatrix(nd,nd);
// timer.start();
// for (int i=0; i<cnt; i++)
// { GM.SVD (GU, GS, GV);
// }
// timer.stop();
// System.out.println ("vecmath svd: " + timer.result(cnt));
// System.out.println (GU);
// System.out.println (GV);
// System.out.println (GS);
// System.out.println (GM);
}
use of maspack.util.FunctionTimer in project artisynth_core by artisynth.
the class Matrix3x6Test method main.
public static void main(String[] args) {
Matrix3x6Test test = new Matrix3x6Test();
try {
test.execute();
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
System.out.println("\nPassed\n");
if (false) {
FunctionTimer timer = new FunctionTimer();
MatrixNd M1_3x3N = new MatrixNd(3, 3);
MatrixNd M2_3x6N = new MatrixNd(3, 6);
Matrix3d M1_3x3 = new Matrix3d();
Matrix3x6 M2_3x6 = new Matrix3x6();
M1_3x3N.setRandom();
M2_3x6N.setRandom();
M1_3x3.setRandom();
M2_3x6.setRandom();
Matrix3x6 MR = new Matrix3x6();
int cnt = 5000000;
for (int i = 0; i < cnt; i++) {
MR.setZero();
MR.mulAdd(M1_3x3, M2_3x6);
MR.mulAdd(M1_3x3N, M2_3x6N);
}
timer.start();
for (int i = 0; i < cnt; i++) {
MR.setZero();
MR.mulAdd(M1_3x3, M2_3x6);
}
timer.stop();
System.out.println("fixed matrices: " + timer.result(cnt));
timer.start();
for (int i = 0; i < cnt; i++) {
MR.setZero();
MR.mulAdd(M1_3x3N, M2_3x6N);
}
timer.stop();
System.out.println("general matrices: " + timer.result(cnt));
}
}
use of maspack.util.FunctionTimer in project artisynth_core by artisynth.
the class DicomReader method read.
/**
* Populates a DicomImage based on a given list of DICOM files.
*
* @param im
* image to populate (null to generate new image)
* @param files
* list of DICOM files
* @param temporalPosition
* temporal index
* @return the populated DICOM image
* @throws IOException
* if there is a read failure
*/
public DicomImage read(DicomImage im, List<File> files, int temporalPosition) throws IOException {
if (files.size() == 0) {
return null;
}
String imageName = files.get(0).getParentFile().getName();
int cpus = Runtime.getRuntime().availableProcessors();
ExecutorService executor = Executors.newFixedThreadPool(cpus, new NamedThreadFactory("dicom_reader"));
LinkedList<Future<DicomSlice[]>> sliceReaders = new LinkedList<Future<DicomSlice[]>>();
ExecutorCompletionService<DicomSlice[]> ecs = new ExecutorCompletionService<DicomSlice[]>(executor);
int nReaders = 0;
for (int i = 0; i < files.size(); i++) {
SliceReaderCallable reader = new SliceReaderCallable(files.get(i));
sliceReaders.add(ecs.submit(reader));
nReaders++;
}
executor.shutdown();
FunctionTimer timer = new FunctionTimer();
timer.start();
int nTimes = 0;
if (im != null) {
nTimes = im.getNumTimes();
}
// process futures as they come in
int nProcessed = 0;
while (nProcessed < nReaders) {
Future<DicomSlice[]> fut = null;
try {
fut = ecs.take();
} catch (InterruptedException e1) {
e1.printStackTrace();
return null;
}
if (fut.isDone()) {
nProcessed++;
// process
try {
DicomSlice[] slices = fut.get();
if (slices != null) {
// split up into frames
for (int i = 0; i < slices.length; i++) {
int stime = temporalPosition;
if (stime < 0) {
// attempt to read time from slice
int[] vals = slices[i].getHeader().getMultiIntValue(DicomTag.TEMPORAL_POSITON_IDENTIFIER);
if (vals != null) {
stime = vals[0];
} else {
// set unknown time?
stime = nTimes;
}
}
slices[i].info.temporalPosition = stime;
if (im == null) {
im = new DicomImage(imageName, slices[i]);
} else {
im.addSlice(slices[i]);
}
}
}
} catch (ExecutionException e) {
if (e.getCause() instanceof IOException) {
throw (IOException) (e.getCause());
} else {
e.printStackTrace();
}
}// end try-catching errors
catch (InterruptedException e) {
e.printStackTrace();
}
}
// end checking if future complete
}
// end main loop
timer.stop();
double usec = timer.getTimeUsec();
System.out.println("Read took " + usec * 1e-6 + " seconds");
if (im == null) {
return null;
}
if (im.title == null) {
im.title = imageName;
}
return im;
}
use of maspack.util.FunctionTimer in project artisynth_core by artisynth.
the class LUDecompositionTest method timingTests.
private void timingTests() {
// Random rand = RandomGenerator.get();
int baseTimingCnt = 100000;
int numTrials = 10;
int[] matsizes = new int[] { 4, 8, 16, 32, 4, 8, 16, 32, 64 };
NumberFormat ifmt = new NumberFormat("%3d");
NumberFormat ffmt = new NumberFormat("%7.2f");
System.out.println("matsize time");
for (int k = 0; k < matsizes.length; k++) {
int n = matsizes[k];
int timingCnt = baseTimingCnt / (n * n);
MatrixNd M = new MatrixNd(n, n);
LUDecomposition lu = new LUDecomposition(n);
FunctionTimer timer = new FunctionTimer();
double ludTime = 0;
for (int cnt = 0; cnt < numTrials; cnt++) {
M.setRandom();
timer.start();
for (int i = 0; i < timingCnt; i++) {
lu.factor(M);
}
timer.stop();
ludTime += timer.getTimeUsec() / timingCnt;
}
ludTime /= numTrials;
System.out.println(" " + ifmt.format(n) + " " + ffmt.format(ludTime));
}
}
Aggregations