forked from kscience/kmath
fix segmented integral
This commit is contained in:
parent
86818f6864
commit
fd4108b74f
@ -102,7 +102,7 @@ public fun <T : Any> Field<T>.integrate(
|
||||
require(intervals > 0) { "Number of intervals must be positive" }
|
||||
val rangeSize = (range.endInclusive - range.start) / intervals
|
||||
val ranges = UnivariateIntegrandRanges(
|
||||
(0 until intervals).map { i -> (rangeSize * i)..(rangeSize * i + 1) to order }
|
||||
(0 until intervals).map { i -> (rangeSize * i)..(rangeSize * (i + 1)) to order }
|
||||
)
|
||||
return GaussIntegrator(this).integrate(
|
||||
UnivariateIntegrand(
|
||||
|
@ -24,14 +24,14 @@ class GaussIntegralTest {
|
||||
|
||||
@Test
|
||||
fun gaussUniform() {
|
||||
val res = DoubleField.integrate(0.0..100.0,300) { x ->
|
||||
val res = DoubleField.integrate(0.0..100.0) { x ->
|
||||
if(x in 30.0..50.0){
|
||||
1.0
|
||||
} else {
|
||||
0.0
|
||||
}
|
||||
}
|
||||
assertEquals(20.0, res.value!!, 1.0)
|
||||
assertEquals(20.0, res.value!!, 0.5)
|
||||
}
|
||||
|
||||
|
||||
|
@ -20,8 +20,7 @@ public sealed class Nd4jArrayStructure<T> : MutableStructureND<T> {
|
||||
*/
|
||||
public abstract val ndArray: INDArray
|
||||
|
||||
public override val shape: IntArray
|
||||
get() = ndArray.shape().toIntArray()
|
||||
public override val shape: IntArray get() = ndArray.shape().toIntArray()
|
||||
|
||||
internal abstract fun elementsIterator(): Iterator<Pair<IntArray, T>>
|
||||
internal fun indicesIterator(): Iterator<IntArray> = ndArray.indicesIterator()
|
||||
|
Loading…
Reference in New Issue
Block a user