Search in sources :

Example 16 with FunctionTimer

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);
}
Also used : FunctionTimer(maspack.util.FunctionTimer)

Example 17 with FunctionTimer

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));
    }
}
Also used : FunctionTimer(maspack.util.FunctionTimer) TestException(maspack.util.TestException)

Example 18 with FunctionTimer

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;
}
Also used : NamedThreadFactory(maspack.concurrency.NamedThreadFactory) ExecutorCompletionService(java.util.concurrent.ExecutorCompletionService) FunctionTimer(maspack.util.FunctionTimer) IOException(java.io.IOException) LinkedList(java.util.LinkedList) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) ExecutionException(java.util.concurrent.ExecutionException)

Example 19 with FunctionTimer

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));
    }
}
Also used : FunctionTimer(maspack.util.FunctionTimer) NumberFormat(maspack.util.NumberFormat)

Aggregations

FunctionTimer (maspack.util.FunctionTimer)19 RigidTransform3d (maspack.matrix.RigidTransform3d)4 Point3d (maspack.matrix.Point3d)3 NumberFormat (maspack.util.NumberFormat)3 Point (artisynth.core.mechmodels.Point)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 Random (java.util.Random)1 ExecutionException (java.util.concurrent.ExecutionException)1 ExecutorCompletionService (java.util.concurrent.ExecutorCompletionService)1 ExecutorService (java.util.concurrent.ExecutorService)1 Future (java.util.concurrent.Future)1 NamedThreadFactory (maspack.concurrency.NamedThreadFactory)1 AABBTree (maspack.geometry.AABBTree)1 InsideQuery (maspack.geometry.BVFeatureQuery.InsideQuery)1 PolygonalMesh (maspack.geometry.PolygonalMesh)1 Vertex3d (maspack.geometry.Vertex3d)1 Vector2d (maspack.matrix.Vector2d)1