Dev #127
@ -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,8 +10,7 @@ package scientifik.kmath.misc
|
||||
*
|
||||
* If step is negative, the same goes from upper boundary downwards
|
||||
*/
|
||||
fun ClosedFloatingPointRange<Double>.toSequence(step: Double): Sequence<Double> =
|
||||
when {
|
||||
fun ClosedFloatingPointRange<Double>.toSequenceWithStep(step: Double): Sequence<Double> = when {
|
||||
step == 0.0 -> error("Zero step in double progression")
|
||||
step > 0 -> sequence {
|
||||
var current = start
|
||||
@ -25,11 +26,20 @@ fun ClosedFloatingPointRange<Double>.toSequence(step: Double): Sequence<Double>
|
||||
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