forked from kscience/kmath
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
|
luRow[col] = sum
|
||||||
|
|
||||||
// maintain best permutation choice
|
// maintain best permutation choice
|
||||||
if (abs(sum) > largest) {
|
if (this@lup.abs(sum) > largest) {
|
||||||
largest = abs(sum)
|
largest = this@lup.abs(sum)
|
||||||
max = row
|
max = row
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Singularity check
|
// Singularity check
|
||||||
if (checkSingular(abs(lu[max, col]))) {
|
if (checkSingular(this@lup.abs(lu[max, col]))) {
|
||||||
error("The matrix is singular")
|
error("The matrix is singular")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package scientifik.kmath.misc
|
package scientifik.kmath.misc
|
||||||
|
|
||||||
|
import kotlin.math.abs
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert double range to sequence.
|
* Convert double range to sequence.
|
||||||
*
|
*
|
||||||
@ -8,8 +10,7 @@ package scientifik.kmath.misc
|
|||||||
*
|
*
|
||||||
* If step is negative, the same goes from upper boundary downwards
|
* If step is negative, the same goes from upper boundary downwards
|
||||||
*/
|
*/
|
||||||
fun ClosedFloatingPointRange<Double>.toSequence(step: Double): Sequence<Double> =
|
fun ClosedFloatingPointRange<Double>.toSequenceWithStep(step: Double): Sequence<Double> = when {
|
||||||
when {
|
|
||||||
step == 0.0 -> error("Zero step in double progression")
|
step == 0.0 -> error("Zero step in double progression")
|
||||||
step > 0 -> sequence {
|
step > 0 -> sequence {
|
||||||
var current = start
|
var current = start
|
||||||
@ -25,11 +26,20 @@ fun ClosedFloatingPointRange<Double>.toSequence(step: Double): Sequence<Double>
|
|||||||
current += step
|
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]
|
* 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 {
|
fun ClosedFloatingPointRange<Double>.toGrid(numPoints: Int): DoubleArray {
|
||||||
if (numPoints < 2) error("Can't create generic grid with less than two points")
|
if (numPoints < 2) error("Can't create generic grid with less than two points")
|
||||||
return DoubleArray(numPoints) { i -> start + (endInclusive - start) / (numPoints - 1) * i }
|
return DoubleArray(numPoints) { i -> start + (endInclusive - start) / (numPoints - 1) * i }
|
||||||
|
Loading…
Reference in New Issue
Block a user