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;
}
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);
}
}
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());
}
}
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));
}
}
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;
}
Aggregations