kyonifer / koma

A scientific computing library for Kotlin. https://kyonifer.github.io/koma
Other
270 stars 23 forks source link

Update validation to work with equality changes #45

Open kyonifer opened 6 years ago

kyonifer commented 6 years ago

In #43 equality was changed to be elementwise. This currently causes matrix validation to break in some cases. For example:

val x = zeros(3,2)
val y = zeros(3,2)
validate {
    x("x"){'N' x 1}
    y("y"){'N' x 'M'}
}

This should fail (because x must have 1 column) but doesn't.

The issue is that DimensionValidator constructs a dimensions hashmap from matrices to possible dimensions. Because y and x are equal under elementwise equality they hash to the same bin in DimensionValidator.dimensions. Thus x's dimension list is clobbered by y's and x survives the dimension check.

Its probably enough to change the validator hashes to use a referential equality wrapper.