0.3.1-dev-11 #510

Merged
altavir merged 80 commits from dev into master 2023-04-05 18:46:36 +03:00
3 changed files with 6 additions and 23 deletions
Showing only changes of commit 1315a8cd34 - Show all commits

View File

@ -6,6 +6,7 @@ import kotlinx.html.h1
import space.kscience.kmath.operations.algebra
import space.kscience.kmath.operations.bufferAlgebra
import space.kscience.kmath.structures.Buffer
import space.kscience.kmath.structures.slice
import space.kscience.kmath.structures.toList
import space.kscience.plotly.*
import kotlin.math.PI
@ -28,7 +29,7 @@ fun main() = with(Double.algebra.bufferAlgebra.seriesAlgebra()) {
val s1 = series(100) { sin(2 * PI * it / 100) + 1.0 }
val s2 = s1.slice(20..50).moveTo(40)
val s2 = s1.slice(20U..50U).moveTo(40)
val s3: Buffer<Double> = s1.zip(s2) { l, r -> l + r } //s1 + s2
val s4 = ln(s3)

View File

@ -137,4 +137,4 @@ public class PermutatedBuffer<T>(
/**
* Created a permuted view of given buffer using provided [indices]
*/
public fun <T> Buffer<T>.view(indices: IntArray): PermutatedBuffer<T> = PermutatedBuffer(this, indices)
public fun <T> Buffer<T>.permute(indices: IntArray): PermutatedBuffer<T> = PermutatedBuffer(this, indices)

View File

@ -14,14 +14,14 @@ internal fun IntRange.intersect(other: IntRange): IntRange =
max(first, other.first)..min(last, other.last)
@PublishedApi
internal val IntRange.size
internal val IntRange.size: Int
get() = last - first + 1
@PublishedApi
internal operator fun IntRange.contains(other: IntRange): Boolean = (other.first in this) && (other.last in this)
//TODO add permutated buffer
//TODO add rank function
//TODO add permutation sort
//TODO check rank statistics
public interface Series<T> : Buffer<T> {
@ -90,24 +90,6 @@ public class SeriesAlgebra<T, out A : Ring<T>, out BA : BufferAlgebra<T, A>, L>(
OffsetBufer(this, index, size)
}
/**
* Create a buffer view using given absolute range
*/
public fun Buffer<T>.slice(range: IntRange): Series<T> {
val size = range.size
return if (this is Series) {
OffsetBufer(this, indices.first + range.first, size)
} else {
OffsetBufer(this, range.first, size)
}
}
public fun Buffer<T>.expand(range: IntRange, defaultValue: T): Series<T> = if (range in indices) {
slice(range)
} else {
TODO()
}
public val Buffer<T>.offset: Int get() = if (this is Series) position else 0
/**