Add contentEquals extension to ND algebra and LinearSpace
This commit is contained in:
parent
21dd5ddd7d
commit
86a45504e3
@ -29,7 +29,7 @@ public typealias MutableMatrix<T> = MutableStructure2D<T>
|
|||||||
public typealias Point<T> = Buffer<T>
|
public typealias Point<T> = Buffer<T>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Basic operations on matrices and vectors. Operates on [Matrix].
|
* Basic operations on matrices and vectors.
|
||||||
*
|
*
|
||||||
* @param T the type of items in the matrices.
|
* @param T the type of items in the matrices.
|
||||||
* @param A the type of ring over [T].
|
* @param A the type of ring over [T].
|
||||||
|
@ -5,8 +5,11 @@
|
|||||||
|
|
||||||
package space.kscience.kmath.nd
|
package space.kscience.kmath.nd
|
||||||
|
|
||||||
|
import space.kscience.kmath.linear.LinearSpace
|
||||||
import space.kscience.kmath.misc.PerformancePitfall
|
import space.kscience.kmath.misc.PerformancePitfall
|
||||||
import space.kscience.kmath.misc.UnstableKMathAPI
|
import space.kscience.kmath.misc.UnstableKMathAPI
|
||||||
|
import space.kscience.kmath.operations.Ring
|
||||||
|
import space.kscience.kmath.operations.invoke
|
||||||
import space.kscience.kmath.structures.Buffer
|
import space.kscience.kmath.structures.Buffer
|
||||||
import space.kscience.kmath.structures.BufferFactory
|
import space.kscience.kmath.structures.BufferFactory
|
||||||
import kotlin.jvm.JvmName
|
import kotlin.jvm.JvmName
|
||||||
@ -145,6 +148,44 @@ public interface StructureND<out T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates whether some [StructureND] is equal to another one.
|
||||||
|
*/
|
||||||
|
@PerformancePitfall
|
||||||
|
public fun <T : Comparable<T>> AlgebraND<T, Ring<T>>.contentEquals(
|
||||||
|
st1: StructureND<T>,
|
||||||
|
st2: StructureND<T>,
|
||||||
|
): Boolean = StructureND.contentEquals(st1, st2)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates whether some [StructureND] is equal to another one.
|
||||||
|
*/
|
||||||
|
@PerformancePitfall
|
||||||
|
public fun <T : Comparable<T>> LinearSpace<T, Ring<T>>.contentEquals(
|
||||||
|
st1: StructureND<T>,
|
||||||
|
st2: StructureND<T>,
|
||||||
|
): Boolean = StructureND.contentEquals(st1, st2)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates whether some [StructureND] is equal to another one with [absoluteTolerance].
|
||||||
|
*/
|
||||||
|
@PerformancePitfall
|
||||||
|
public fun <T : Comparable<T>> GroupND<T, Ring<T>>.contentEquals(
|
||||||
|
st1: StructureND<T>,
|
||||||
|
st2: StructureND<T>,
|
||||||
|
absoluteTolerance: T,
|
||||||
|
): Boolean = st1.elements().all { (index, value) -> elementContext { (value - st2[index]) } < absoluteTolerance }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates whether some [StructureND] is equal to another one with [absoluteTolerance].
|
||||||
|
*/
|
||||||
|
@PerformancePitfall
|
||||||
|
public fun <T : Comparable<T>> LinearSpace<T, Ring<T>>.contentEquals(
|
||||||
|
st1: StructureND<T>,
|
||||||
|
st2: StructureND<T>,
|
||||||
|
absoluteTolerance: T,
|
||||||
|
): Boolean = st1.elements().all { (index, value) -> elementAlgebra { (value - st2[index]) } < absoluteTolerance }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the value at the specified indices.
|
* Returns the value at the specified indices.
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user