|
SuanShu, a Java numerical and statistical library | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectcom.numericalmethod.suanshu.misc.SuanShuUtils
public class SuanShuUtils
This class collects some miscellaneous utility functions that are commonly used. These functions are static and stateless.
| Method Summary | |
|---|---|
static void |
assertArgument(boolean condition,
java.lang.String errorMessage)
Check if an argument condition is satisfied. |
static void |
assertOrThrow(java.lang.RuntimeException error)
Throw the argument RuntimeException if it is not null. |
static double |
autoEpsilon(double... inputs)
Compute a reasonable precision parameter. |
static double |
autoEpsilon(double[]... inputs)
Compute a reasonable precision parameter. |
static double |
autoEpsilon(Matrix A)
Compute a reasonable precision parameter. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static void assertArgument(boolean condition,
java.lang.String errorMessage)
IllegalArgumentException if not.
This is a convenience method for checking input arguments.
condition - the argument condition to be checkederrorMessage - the error message if the condition is not satisfiedpublic static void assertOrThrow(java.lang.RuntimeException error)
RuntimeException if it is not null.
This function is slow because the RuntimeException is always created and passed in as an argument to a function. The object creation is often unnecessary.
To efficiently use this method for checking whether a condition is satisified, a sample usage is the following.
assertOrThrow(cond ? null : new RuntimeException("msg"));
It is important that we use lazy evaluation of the if statement.
This is to avoid the expensive object (exception) creation for each checking.
error - the error thrown if the condition is not satisfiedpublic static double autoEpsilon(double... inputs)
This method suggests a more 'objective' way to determine the 'correct' epsilon from the inputs. Roughly,
auto ε = |max(inputs)| * sqrt(number of inputs) * machine ε * 10
inputs - doubles
public static double autoEpsilon(double[]... inputs)
This method suggests a more 'objective' way to determine the 'correct' epsilon from the inputs. Roughly,
auto ε = |max(inputs)| * sqrt(number of inputs) * machine ε * 10
inputs - arrays of doubles
public static double autoEpsilon(Matrix A)
This method suggests a more 'objective' way to determine the 'correct' epsilon from the inputs. Roughly,
auto ε = |max(inputs)| * sqrt(number of inputs) * machine ε * 10
A - a matrix
|
SuanShu, a Java numerical and statistical library | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||