Feature/tensors performance #497

Closed
margarita0303 wants to merge 91 commits from feature/tensors-performance into feature/tensors-performance
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
*/
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>,
) : Histogram<T, V, DomainBin<T, V>> {
override fun get(point: Point<T>): DomainBin<T, V>? {
val index = histogramSpace.getIndex(point) ?: return null
return histogramSpace.produceBin(index, values[index])
val index = histogramGroup.getIndex(point) ?: return null
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>>
get() = DefaultStrides(histogramSpace.shape).asSequence().map {
histogramSpace.produceBin(it, values[it])
get() = DefaultStrides(histogramGroup.shape).asSequence().map {
histogramGroup.produceBin(it, values[it])
}.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>
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."
}
return IndexedHistogram(this, histogramValueAlgebra { left.values + right.values })
}
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 })
}

View File

@ -46,7 +46,7 @@ public class UniformHistogram1DGroup<V : Any, A>(
public val startPoint: Double = 0.0,
) : 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