altavir/diff #494

Merged
altavir merged 71 commits from altavir/diff into commandertvis/diff 2022-07-16 09:58:44 +03:00
2 changed files with 9 additions and 9 deletions
Showing only changes of commit 229c36b661 - Show all commits

View File

@ -28,20 +28,20 @@ public data class DomainBin<in T : Comparable<T>, out V>(
* @param V the type of bin value * @param V the type of bin value
*/ */
public class IndexedHistogram<T : Comparable<T>, V : Any>( public class IndexedHistogram<T : Comparable<T>, V : Any>(
public val histogramSpace: IndexedHistogramGroup<T, V>, public val histogramGroup: IndexedHistogramGroup<T, V>,
public val values: StructureND<V>, public val values: StructureND<V>,
) : Histogram<T, V, DomainBin<T, V>> { ) : Histogram<T, V, DomainBin<T, V>> {
override fun get(point: Point<T>): DomainBin<T, V>? { override fun get(point: Point<T>): DomainBin<T, V>? {
val index = histogramSpace.getIndex(point) ?: return null val index = histogramGroup.getIndex(point) ?: return null
return histogramSpace.produceBin(index, values[index]) return histogramGroup.produceBin(index, values[index])
} }
override val dimension: Int get() = histogramSpace.shape.size override val dimension: Int get() = histogramGroup.shape.size
override val bins: Iterable<DomainBin<T, V>> override val bins: Iterable<DomainBin<T, V>>
get() = DefaultStrides(histogramSpace.shape).asSequence().map { get() = DefaultStrides(histogramGroup.shape).asSequence().map {
histogramSpace.produceBin(it, values[it]) histogramGroup.produceBin(it, values[it])
}.asIterable() }.asIterable()
} }
@ -68,14 +68,14 @@ public interface IndexedHistogramGroup<T : Comparable<T>, V : Any> : Group<Index
public fun produce(builder: HistogramBuilder<T, V>.() -> Unit): IndexedHistogram<T, V> public fun produce(builder: HistogramBuilder<T, V>.() -> Unit): IndexedHistogram<T, V>
override fun add(left: IndexedHistogram<T, V>, right: IndexedHistogram<T, V>): IndexedHistogram<T, V> { override fun add(left: IndexedHistogram<T, V>, right: IndexedHistogram<T, V>): IndexedHistogram<T, V> {
require(left.histogramSpace == this && right.histogramSpace == this) { require(left.histogramGroup == this && right.histogramGroup == this) {
"A histogram belonging to a different group cannot be operated." "A histogram belonging to a different group cannot be operated."
} }
return IndexedHistogram(this, histogramValueAlgebra { left.values + right.values }) return IndexedHistogram(this, histogramValueAlgebra { left.values + right.values })
} }
override fun scale(a: IndexedHistogram<T, V>, value: Double): IndexedHistogram<T, V> { override fun scale(a: IndexedHistogram<T, V>, value: Double): IndexedHistogram<T, V> {
require(a.histogramSpace == this) { "A histogram belonging to a different group cannot be operated." } require(a.histogramGroup == this) { "A histogram belonging to a different group cannot be operated." }
return IndexedHistogram(this, histogramValueAlgebra { a.values * value }) return IndexedHistogram(this, histogramValueAlgebra { a.values * value })
} }

View File

@ -46,7 +46,7 @@ public class UniformHistogram1DGroup<V : Any, A>(
public val startPoint: Double = 0.0, public val startPoint: Double = 0.0,
) : Group<Histogram1D<Double, V>>, ScaleOperations<Histogram1D<Double, V>> where A : Ring<V>, A : ScaleOperations<V> { ) : Group<Histogram1D<Double, V>>, ScaleOperations<Histogram1D<Double, V>> where A : Ring<V>, A : ScaleOperations<V> {
override val zero: UniformHistogram1D<V> by lazy { UniformHistogram1D(this, emptyMap()) } override val zero: UniformHistogram1D<V> = UniformHistogram1D(this, emptyMap())
/** /**
* Get index of a bin * Get index of a bin