Search in sources :

Example 6 with NumberFormat

use of maspack.util.NumberFormat in project artisynth_core by artisynth.

the class VectorBase method setDefaultFormat.

/**
 * Sets the default format string used in {@link #toString() toString}. For
 * a description of the format string syntax, see {@link
 * maspack.util.NumberFormat NumberFormat}.
 *
 * @param fmtStr
 * new format string
 * @throws IllegalArgumentException
 * if the format string is invalid
 * @see #getDefaultFormat
 */
public static void setDefaultFormat(String fmtStr) {
    NumberFormat fmt = new NumberFormat(fmtStr);
    myDefaultFmt = fmt;
}
Also used : NumberFormat(maspack.util.NumberFormat)

Example 7 with NumberFormat

use of maspack.util.NumberFormat in project artisynth_core by artisynth.

the class VectorTest method checkResult.

void checkResult(Vector vr, Vector vc, Exception eactual, Exception eexpected, double epsilon) {
    MatrixTest.checkExceptions(eactual, eexpected);
    double tol = 0;
    if (epsilon != 0) {
        tol = vr.infinityNorm() * epsilon;
    }
    if (!vr.epsilonEquals(vc, tol)) {
        VectorNd ME = new VectorNd(vr);
        VectorNd v1 = new VectorNd(vc);
        ME.sub(v1);
        ME.absolute();
        throw new TestException("Expected result:\n" + vc.toString(new NumberFormat("%9.4f")) + "\n" + "Actual result:\n" + vr.toString(new NumberFormat("%9.4f")) + "\n" + "max err: " + ME.maxElement() + ", tol=" + tol);
    }
}
Also used : TestException(maspack.util.TestException) NumberFormat(maspack.util.NumberFormat)

Example 8 with NumberFormat

use of maspack.util.NumberFormat in project artisynth_core by artisynth.

the class VectorTest method doScanWrite.

void doScanWrite(Vector vr, String fmt, boolean withBrackets) {
    StringWriter sw = new StringWriter();
    try {
        vr.write(new PrintWriter(sw), new NumberFormat(fmt), withBrackets);
        vr.scan(new ReaderTokenizer(new StringReader(sw.toString())));
    } catch (Exception e) {
        throw new TestException("scan/write error: " + e.getMessage());
    }
}
Also used : TestException(maspack.util.TestException) ReaderTokenizer(maspack.util.ReaderTokenizer) TestException(maspack.util.TestException) NumberFormat(maspack.util.NumberFormat)

Example 9 with NumberFormat

use of maspack.util.NumberFormat in project artisynth_core by artisynth.

the class QRDecompositionTest method timingTests.

private void timingTests() {
    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);
        QRDecomposition qr = new QRDecomposition();
        FunctionTimer timer = new FunctionTimer();
        double qrdTime = 0;
        for (int cnt = 0; cnt < numTrials; cnt++) {
            M.setRandom();
            timer.start();
            for (int i = 0; i < timingCnt; i++) {
                qr.factor(M);
            }
            timer.stop();
            qrdTime += timer.getTimeUsec() / timingCnt;
        }
        qrdTime /= numTrials;
        System.out.println("  " + ifmt.format(n) + "    " + ffmt.format(qrdTime));
    }
}
Also used : FunctionTimer(maspack.util.FunctionTimer) NumberFormat(maspack.util.NumberFormat)

Example 10 with NumberFormat

use of maspack.util.NumberFormat in project artisynth_core by artisynth.

the class VectoriBase method setDefaultFormat.

/**
 * Sets the default format string used in {@link #toString() toString}. For
 * a description of the format string syntax, see {@link
 * maspack.util.NumberFormat NumberFormat}.
 *
 * @param fmtStr
 * new format string
 * @throws IllegalArgumentException
 * if the format string is invalid
 * @see #getDefaultFormat
 */
public static void setDefaultFormat(String fmtStr) {
    NumberFormat fmt = new NumberFormat(fmtStr);
    myDefaultFmt = fmt;
}
Also used : NumberFormat(maspack.util.NumberFormat)

Aggregations

NumberFormat (maspack.util.NumberFormat)55 PrintWriter (java.io.PrintWriter)15 IOException (java.io.IOException)8 Point3d (maspack.matrix.Point3d)6 BufferedWriter (java.io.BufferedWriter)5 File (java.io.File)5 PolygonalMesh (maspack.geometry.PolygonalMesh)5 Point (artisynth.core.mechmodels.Point)4 FileWriter (java.io.FileWriter)4 ArrayList (java.util.ArrayList)4 SparseBlockMatrix (maspack.matrix.SparseBlockMatrix)4 ReaderTokenizer (maspack.util.ReaderTokenizer)4 TestException (maspack.util.TestException)4 Face (maspack.geometry.Face)3 VectorNd (maspack.matrix.VectorNd)3 FunctionTimer (maspack.util.FunctionTimer)3 InternalErrorException (maspack.util.InternalErrorException)3 ContactPoint (artisynth.core.mechmodels.ContactPoint)2 PointParticleAttachment (artisynth.core.mechmodels.PointParticleAttachment)2 Font (java.awt.Font)2