api / koma.util.validation / ValidationContext
ValidationContext
class ValidationContext
A lambda receiver with state and convenience methods for validating a group of matrices.
In general there is no reason to instantiate this directly, instead @see validate(fn) for example usage.
Constructors
Name | Summary |
---|---|
<init> | ValidationContext() A lambda receiver with state and convenience methods for validating a group of matrices. |
Properties
Name | Summary |
---|---|
currentMatrix | val currentMatrix: Matrix < Double > |
currentMatrixName | val currentMatrixName: String |
matrices | val matrices: MutableList < Matrix < Double >> |
matrixNames | val matrixNames: MutableList < String > |
metadataStorage | val metadataStorage: MutableMap < String , Any > |
Functions
Name | Summary |
---|---|
addValidator | fun addValidator(validator: Validator ): Unit Add a helper that will perform validation at the end of the block. |
invoke | operator fun Matrix < Double >.invoke(fn: ValidationContext .() -> Unit ): ValidationContext Execute the given fn (which should contain validation rules) against the given matrix. operator fun Matrix < Double >.invoke(name: String , fn: ValidationContext .() -> Unit ): ValidationContext Execute the given fn (which should contain validation rules) against the given matrix with the given name. operator fun invoke(): ValidationContext |
metadata | fun <T> metadata(key: String , factory: () -> T ): T |
validate | fun validate(): Unit Check declared matrices against any rules that have been added with addValidator. fun validate(fn: ValidationContext .() -> Unit ): Unit Check declared matrices against any rules that have been added with addValidator, after running the given callback. |
x | infix fun Int .x(cols: Int ): Unit infix fun Int .x(cols: Char ): Unit infix fun Char .x(cols: Int ): Unit infix fun Char .x(cols: Char ): Unit |
Extension Properties
Name | Summary |
---|---|
max | var ValidationContext .max: Double Maximum value for individual elements in the matrix. |
min | var ValidationContext .min: Double Minimum value for individual elements in the matrix. |
symmetric | val ValidationContext .symmetric: ValidationContext Require the current matrix to be symmetric. |
transposable | val ValidationContext .transposable: ValidationContext Accept a transposed version of the matrix as satisfying the dimensions check. For example, allow a 1 x 3 matrix when dimensions are declared as 3 x 1. |
Extension Functions
Name | Summary |
---|---|
dim | fun ValidationContext .dim(rows: Int , cols: Int ): ValidationContext Require the current matrix to have exactly the given number of rows and columns. fun ValidationContext .dim(rows: Int , cols: Char ): ValidationContext Require the current matrix to have exactly the given number of rows and match the number of columns with other dimensions in other matrices based on the cols variable name. fun ValidationContext .dim(rows: Char , cols: Int ): ValidationContext Require the current matrix to have exactly the given number of columns and match the number of rows with other dimensions in other matrices based on the rows variable name. fun ValidationContext .dim(rows: Char , cols: Char ): ValidationContext Require the current matrix's dimensions to correspond to the given variable names. Compares with other dimensions in other matrices in the context that are assigned the same variable name and raises an error if they don't all match. |
max | fun ValidationContext .max(value: Double ): ValidationContext Ensure all of the elements in the current matrix are >= the given value. |
min | fun ValidationContext .min(value: Double ): ValidationContext Ensure all of the elements in the current matrix are >= the given value. |
symmetric | fun ValidationContext .symmetric(precision: Double = 1e-5): ValidationContext |