Minor change in grid builders
This commit is contained in:
parent
1a869ace0e
commit
774b1123f7
@ -128,14 +128,14 @@ fun <T : Comparable<T>, F : Field<T>> GenericMatrixContext<T, F>.lup(
|
||||
luRow[col] = sum
|
||||
|
||||
// maintain best permutation choice
|
||||
if (abs(sum) > largest) {
|
||||
largest = abs(sum)
|
||||
if (this@lup.abs(sum) > largest) {
|
||||
largest = this@lup.abs(sum)
|
||||
max = row
|
||||
}
|
||||
}
|
||||
|
||||
// Singularity check
|
||||
if (checkSingular(abs(lu[max, col]))) {
|
||||
if (checkSingular(this@lup.abs(lu[max, col]))) {
|
||||
error("The matrix is singular")
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
package scientifik.kmath.misc
|
||||
|
||||
import kotlin.math.abs
|
||||
|
||||
/**
|
||||
* Convert double range to sequence.
|
||||
*
|
||||
@ -8,28 +10,36 @@ package scientifik.kmath.misc
|
||||
*
|
||||
* If step is negative, the same goes from upper boundary downwards
|
||||
*/
|
||||
fun ClosedFloatingPointRange<Double>.toSequence(step: Double): Sequence<Double> =
|
||||
when {
|
||||
step == 0.0 -> error("Zero step in double progression")
|
||||
step > 0 -> sequence {
|
||||
var current = start
|
||||
while (current <= endInclusive) {
|
||||
yield(current)
|
||||
current += step
|
||||
}
|
||||
}
|
||||
else -> sequence {
|
||||
var current = endInclusive
|
||||
while (current >= start) {
|
||||
yield(current)
|
||||
current += step
|
||||
}
|
||||
}
|
||||
fun ClosedFloatingPointRange<Double>.toSequenceWithStep(step: Double): Sequence<Double> = when {
|
||||
step == 0.0 -> error("Zero step in double progression")
|
||||
step > 0 -> sequence {
|
||||
var current = start
|
||||
while (current <= endInclusive) {
|
||||
yield(current)
|
||||
current += step
|
||||
}
|
||||
}
|
||||
else -> sequence {
|
||||
var current = endInclusive
|
||||
while (current >= start) {
|
||||
yield(current)
|
||||
current += step
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert double range to sequence with the fixed number of points
|
||||
*/
|
||||
fun ClosedFloatingPointRange<Double>.toSequenceWithPoints(numPoints: Int): Sequence<Double> {
|
||||
require(numPoints > 1) { "The number of points should be more than 2" }
|
||||
return toSequenceWithStep(abs(endInclusive - start) / (numPoints - 1))
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert double range to array of evenly spaced doubles, where the size of array equals [numPoints]
|
||||
*/
|
||||
@Deprecated("Replace by 'toSequenceWithPoints'")
|
||||
fun ClosedFloatingPointRange<Double>.toGrid(numPoints: Int): DoubleArray {
|
||||
if (numPoints < 2) error("Can't create generic grid with less than two points")
|
||||
return DoubleArray(numPoints) { i -> start + (endInclusive - start) / (numPoints - 1) * i }
|
||||
|
Loading…
Reference in New Issue
Block a user