diff --git a/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/NDFieldBenchmark.kt b/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/NDFieldBenchmark.kt index 0cd9a46ab..fbf4bdaba 100644 --- a/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/NDFieldBenchmark.kt +++ b/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/NDFieldBenchmark.kt @@ -46,8 +46,8 @@ internal class NDFieldBenchmark { private companion object { private const val dim = 1000 private const val n = 100 - private val autoField = AlgebraND.auto(DoubleField, dim, dim) - private val specializedField = AlgebraND.real(dim, dim) - private val genericField = AlgebraND.field(DoubleField, Buffer.Companion::boxing, dim, dim) + private val autoField = DoubleField.autoNd(dim, dim) + private val specializedField = DoubleField.nd(dim, dim) + private val genericField = DoubleField.nd(Buffer.Companion::boxing, dim, dim) } } diff --git a/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/ViktorBenchmark.kt b/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/ViktorBenchmark.kt index 1ddc79cf8..6ea64ba3c 100644 --- a/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/ViktorBenchmark.kt +++ b/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/ViktorBenchmark.kt @@ -10,10 +10,9 @@ import kotlinx.benchmark.Blackhole import kotlinx.benchmark.Scope import kotlinx.benchmark.State import org.jetbrains.bio.viktor.F64Array -import space.kscience.kmath.nd.AlgebraND import space.kscience.kmath.nd.StructureND -import space.kscience.kmath.nd.auto -import space.kscience.kmath.nd.real +import space.kscience.kmath.nd.autoNd +import space.kscience.kmath.nd.nd import space.kscience.kmath.operations.DoubleField import space.kscience.kmath.viktor.ViktorNDField @@ -59,8 +58,8 @@ internal class ViktorBenchmark { private const val n = 100 // automatically build context most suited for given type. - private val autoField = AlgebraND.auto(DoubleField, dim, dim) - private val realField = AlgebraND.real(dim, dim) + private val autoField = DoubleField.autoNd(dim, dim) + private val realField = DoubleField.nd(dim, dim) private val viktorField = ViktorNDField(dim, dim) } } diff --git a/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/ViktorLogBenchmark.kt b/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/ViktorLogBenchmark.kt index 8622e8f30..afe44ea99 100644 --- a/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/ViktorLogBenchmark.kt +++ b/benchmarks/src/jvmMain/kotlin/space/kscience/kmath/benchmarks/ViktorLogBenchmark.kt @@ -10,9 +10,8 @@ import kotlinx.benchmark.Blackhole import kotlinx.benchmark.Scope import kotlinx.benchmark.State import org.jetbrains.bio.viktor.F64Array -import space.kscience.kmath.nd.AlgebraND -import space.kscience.kmath.nd.auto -import space.kscience.kmath.nd.real +import space.kscience.kmath.nd.autoNd +import space.kscience.kmath.nd.nd import space.kscience.kmath.operations.DoubleField import space.kscience.kmath.viktor.ViktorFieldND @@ -51,8 +50,8 @@ internal class ViktorLogBenchmark { private const val n = 100 // automatically build context most suited for given type. - private val autoField = AlgebraND.auto(DoubleField, dim, dim) - private val realNdField = AlgebraND.real(dim, dim) + private val autoField = DoubleField.autoNd(dim, dim) + private val realNdField = DoubleField.nd(dim, dim) private val viktorField = ViktorFieldND(intArrayOf(dim, dim)) } } diff --git a/docs/diagrams/core.puml b/docs/diagrams/core.puml new file mode 100644 index 000000000..87f8f2e2d --- /dev/null +++ b/docs/diagrams/core.puml @@ -0,0 +1,1020 @@ +@startuml +interface "ColumnarData" { + size: Int +} +interface "XYColumnarData" { + x: Buffer + y: Buffer +} +interface "XYErrorColumnarData" { + yErr: Buffer +} +interface "XYZColumnarData" { + z: Buffer +} +interface "Domain" { + dimension: Int +} +interface "DoubleDomain" { + +} +class "HyperSquareDomain" { + lower: Buffer + upper: Buffer +} +class "UnconstrainedDomain" { + dimension: Int +} +class "UnivariateDomain" { + range: ClosedFloatingPointRange +} +interface "DifferentiableExpression" { + +} +interface "SpecialDifferentiableExpression" { + +} +abstract "FirstDerivativeExpression" { + +} +interface "AutoDiffProcessor" { + +} +interface "Expression" { + +} +interface "ExpressionAlgebra" { + +} +abstract "FunctionalExpressionAlgebra" { + algebra: A +} +class "FunctionalExpressionGroup" { + algebra: A +} +class "FunctionalExpressionRing" { + algebra: A +} +class "FunctionalExpressionField" { + algebra: A +} +class "FunctionalExpressionExtendedField" { + algebra: A +} +interface "MST" { + +} +class "Numeric" { + value: Number +} +class "Unary" { + operation: String + value: MST +} +class "Binary" { + operation: String + left: MST + right: MST +} +class "InnerAlgebra" { + algebra: Algebra + arguments: Map +} +class "MstNumericAlgebra" { + number() + bindSymbolOrNull() + bindSymbol() + unaryOperationFunction() + binaryOperationFunction() +} +class "MstGroup" { + zero: MST.Numericnumber() + bindSymbolOrNull() + add() + unaryPlus() + unaryMinus() + minus() + scale() + binaryOperationFunction() + unaryOperationFunction() +} +class "MstRing" { + zero: MST.Numeric + one: MST.Numericnumber() + bindSymbolOrNull() + add() + scale() + multiply() + unaryPlus() + unaryMinus() + minus() + binaryOperationFunction() + unaryOperationFunction() +} +class "MstField" { + zero: MST.Numeric + one: MST.NumericbindSymbolOrNull() + number() + add() + scale() + multiply() + divide() + unaryPlus() + unaryMinus() + minus() + binaryOperationFunction() + unaryOperationFunction() +} +class "MstExtendedField" { + zero: MST.Numeric + one: MST.NumericbindSymbolOrNull() + number() + sin() + cos() + tan() + asin() + acos() + atan() + sinh() + cosh() + tanh() + asinh() + acosh() + atanh() + add() + sqrt() + scale() + multiply() + divide() + unaryPlus() + unaryMinus() + minus() + power() + exp() + ln() + binaryOperationFunction() + unaryOperationFunction() +} +class "MstLogicAlgebra" { + bindSymbolOrNull() + const() + not() + and() + or() + xor() +} +class "AutoDiffValue" { + value: T +} +class "DerivationResult" { + value: T + derivativeValues: Map + context: Field +} +class "SimpleAutoDiffField" { + context: F + bindings: Map +} +class "AutoDiffVariableWithDerivative" { + identity: String + value: T + d: T +} +class "SimpleAutoDiffExpression" { + field: F + function: SimpleAutoDiffField +} +class "SimpleAutoDiffExtendedField" { + context: F + bindings: Map +} +interface "Symbol" { + identity: String +} +class "StringSymbol" { + identity: String +} +interface "SymbolIndexer" { + symbols: List +} +class "SimpleSymbolIndexer" { + symbols: List +} +class "BufferedLinearSpace" { + elementAlgebra: A + bufferFactory: BufferFactory +} +interface "LinearSolver" { + +} +interface "LinearSpace" { + elementAlgebra: A +} +class "LupDecomposition" { + context: LinearSpace + elementContext: Field + lu: Matrix + pivot: IntArray + even: Boolean +} +class "MatrixBuilder" { + linearSpace: LinearSpace + rows: Int + columns: Int +} +class "SymmetricMatrixFeature" { + +} +interface "MatrixFeature" { + +} +interface "DiagonalFeature" { + +} +class "ZeroFeature" { + +} +class "UnitFeature" { + +} +interface "InverseMatrixFeature" { + inverse: Matrix +} +interface "DeterminantFeature" { + determinant: T +} +class "LFeature" { + +} +class "UFeature" { + +} +interface "LUDecompositionFeature" { + l: Matrix + u: Matrix +} +interface "LupDecompositionFeature" { + l: Matrix + u: Matrix + p: Matrix +} +class "OrthogonalFeature" { + +} +interface "QRDecompositionFeature" { + q: Matrix + r: Matrix +} +interface "CholeskyDecompositionFeature" { + l: Matrix +} +interface "SingularValueDecompositionFeature" { + u: Matrix + s: Matrix + v: Matrix + singularValues: Point +} +class "MatrixWrapper" { + origin: Matrix + features: FeatureSet +} +class "TransposedFeature" { + original: Matrix +} +class "VirtualMatrix" { + rowNum: Int + colNum: Int + generator: (i:Int,j:Int)->T +} +class "UnstableKMathAPI" { + +} +class "PerformancePitfall" { + message: String +} +interface "Featured" { + +} +interface "Feature" { + key: FeatureKey +} +class "FeatureSet" { + features: Map +} +interface "Loggable" { + +} +class "ShapeMismatchException" { + expected: IntArray + actual: IntArray +} +interface "AlgebraND" { + shape: IntArray + elementContext: C +} +interface "GroupND" { + +} +interface "RingND" { + +} +interface "FieldND" { + +} +interface "BufferAlgebraND" { + strides: Strides + bufferFactory: BufferFactory + buffer: Buffer +} +class "BufferedGroupND" { + shape: IntArray + elementContext: A + bufferFactory: BufferFactory +} +class "BufferedRingND" { + shape: IntArray + elementContext: R + bufferFactory: BufferFactory +} +class "BufferedFieldND" { + shape: IntArray + elementContext: R + bufferFactory: BufferFactory +} +class "BufferND" { + strides: Strides + buffer: Buffer +} +class "MutableBufferND" { + strides: Strides + mutableBuffer: MutableBuffer +} +class "DoubleFieldND" { + shape: IntArray +} +class "ShortRingND" { + shape: IntArray +} +interface "Structure1D" { + dimension: Int +} +interface "MutableStructure1D" { + +} +class "Structure1DWrapper" { + structure: StructureND +} +class "MutableStructure1DWrapper" { + structure: MutableStructureND +} +class "Buffer1DWrapper" { + buffer: Buffer +} +class "MutableBuffer1DWrapper" { + buffer: MutableBuffer +} +interface "Structure2D" { + rowNum: Int + colNum: Int + shape: IntArray + rows: List + columns: List +} +interface "MutableStructure2D" { + rows: List + columns: List +} +class "Structure2DWrapper" { + structure: StructureND +} +class "MutableStructure2DWrapper" { + structure: MutableStructureND +} +interface "StructureFeature" { + +} +interface "StructureND" { + shape: IntArray + dimension: Int +} +interface "MutableStructureND" { + +} +interface "Strides" { + shape: IntArray + strides: IntArray + linearSize: Int +} +class "DefaultStrides" { + shape: IntArray +} +class "KMathContext" { + +} +interface "Algebra" { + +} +interface "GroupOperations" { + +} +interface "Group" { + zero: T +} +interface "RingOperations" { + +} +interface "Ring" { + one: T +} +interface "FieldOperations" { + +} +interface "Field" { + +} +interface "AlgebraElement" { + context: C +} +interface "GroupElement" { + +} +interface "RingElement" { + +} +interface "FieldElement" { + +} +class "BigIntField" { + zero: BigInt + one: BigIntnumber() + unaryMinus() + add() + scale() + multiply() + divide() + unaryPlus() + unaryMinus() +} +class "BigInt" { + sign: Byte + magnitude: Magnitude +} +interface "BufferAlgebra" { + bufferFactory: BufferFactory + elementAlgebra: A +} +class "BufferField" { + bufferFactory: BufferFactory + elementAlgebra: A + size: Int +} +interface "LogicAlgebra" { + +} +class "BooleanAlgebra" { + const() + not() + and() + or() + xor() +} +interface "ExtendedFieldOperations" { + +} +interface "ExtendedField" { + +} +class "DoubleField" { + zero: Double + one: Doublenumber() + binaryOperationFunction() + add() + multiply() + divide() + scale() + sin() + cos() + tan() + acos() + asin() + atan() + sinh() + cosh() + tanh() + asinh() + acosh() + atanh() + sqrt() + power() + exp() + ln() + norm() + unaryMinus() + plus() + minus() + times() + div() +} +class "FloatField" { + zero: Float + one: Floatnumber() + binaryOperationFunction() + add() + scale() + multiply() + divide() + sin() + cos() + tan() + acos() + asin() + atan() + sinh() + cosh() + tanh() + asinh() + acosh() + atanh() + sqrt() + power() + exp() + ln() + norm() + unaryMinus() + plus() + minus() + times() + div() +} +class "IntRing" { + zero: Int + one: Intnumber() + add() + multiply() + norm() + unaryMinus() + plus() + minus() + times() +} +class "ShortRing" { + zero: Short + one: Shortnumber() + add() + multiply() + norm() + unaryMinus() + plus() + minus() + times() +} +class "ByteRing" { + zero: Byte + one: Bytenumber() + add() + multiply() + norm() + unaryMinus() + plus() + minus() + times() +} +class "LongRing" { + zero: Long + one: Longnumber() + add() + multiply() + norm() + unaryMinus() + plus() + minus() + times() +} +interface "NumericAlgebra" { + +} +interface "ScaleOperations" { + +} +interface "NumbersAddOperations" { + +} +interface "TrigonometricOperations" { + +} +interface "PowerOperations" { + +} +interface "ExponentialOperations" { + +} +interface "Norm" { + +} +interface "Buffer" { + size: Int +} +interface "MutableBuffer" { + +} +class "ListBuffer" { + list: List +} +class "MutableListBuffer" { + list: MutableList +} +class "ArrayBuffer" { + array: Array +} +class "ReadOnlyBuffer" { + buffer: MutableBuffer +} +class "VirtualBuffer" { + size: Int + generator: (Int)->T +} +class "BufferAccessor2D" { + rowNum: Int + colNum: Int + factory: MutableBufferFactory +} +class "Row" { + buffer: MutableBuffer + rowIndex: Int +} +class "DoubleBuffer" { + array: DoubleArray +} +class "DoubleBufferFieldOperations" { + unaryMinus() + add() + multiply() + divide() + sin() + cos() + tan() + asin() + acos() + atan() + sinh() + cosh() + tanh() + asinh() + acosh() + atanh() + power() + exp() + ln() +} +class "DoubleL2Norm" { + norm() +} +class "DoubleBufferField" { + size: Int +} +enum "ValueFlag" { + NAN + MISSING + NEGATIVE_INFINITY + POSITIVE_INFINITY +} +interface "FlaggedBuffer" { + +} +class "FlaggedDoubleBuffer" { + values: DoubleArray + flags: ByteArray +} +class "FloatBuffer" { + array: FloatArray +} +class "IntBuffer" { + array: IntArray +} +class "LongBuffer" { + array: LongArray +} +class "MemoryBuffer" { + memory: Memory + spec: MemorySpec +} +class "MutableMemoryBuffer" { + memory: Memory + spec: MemorySpec +} +class "ShortBuffer" { + array: ShortArray +} +class "ExpressionFieldTest" { + x +} +class "InterpretTest" { + +} +class "SimpleAutoDiffTest" { + x + y + z +} +class "DoubleLUSolverTest" { + +} +class "MatrixTest" { + +} +class "CumulativeKtTest" { + +} +class "BigIntAlgebraTest" { + +} +class "BigIntConstructorTest" { + +} +class "BigIntConversionsTest" { + +} +class "BigIntOperationsTest" { + +} +class "DoubleFieldTest" { + +} +class "NDFieldTest" { + +} +class "NumberNDFieldTest" { + algebra + array1 + array2 +} +class "L2Norm" { + norm() +} +interface "AlgebraicVerifier" { + algebra: A +} +class "FieldVerifier" { + algebra: A + a: T + b: T + c: T + x: Number +} +class "RingVerifier" { + algebra: A + a: T + b: T + c: T + x: Number +} +class "SpaceVerifier" { + algebra: S + a: T + b: T + c: T + x: Number +} +class "JBigIntegerField" { + zero: BigInteger + one: BigIntegernumber() + add() + minus() + multiply() + unaryMinus() +} +abstract "JBigDecimalFieldBase" { + mathContext: MathContext +} +class "JBigDecimalField" { + mathContext: MathContext +} +"ColumnarData" <|--- XYColumnarData +"XYColumnarData" <|--- XYErrorColumnarData +"XYColumnarData" <|--- XYZColumnarData +"Domain" <|--- DoubleDomain +"DoubleDomain" <|--- HyperSquareDomain +"DoubleDomain" <|--- UnconstrainedDomain +"DoubleDomain" <|--- UnivariateDomain +"Expression" <|--- DifferentiableExpression +"DifferentiableExpression" <|--- SpecialDifferentiableExpression +"DifferentiableExpression" <|--- FirstDerivativeExpression +"Algebra" <|--- ExpressionAlgebra +"ExpressionAlgebra" <|--- FunctionalExpressionAlgebra +"FunctionalExpressionAlgebra" <|--- FunctionalExpressionGroup +"Group" <|--- FunctionalExpressionGroup +"FunctionalExpressionGroup" <|--- FunctionalExpressionRing +"Ring" <|--- FunctionalExpressionRing +"FunctionalExpressionRing" <|--- FunctionalExpressionField +"Field" <|--- FunctionalExpressionField +"ScaleOperations" <|--- FunctionalExpressionField +"FunctionalExpressionField" <|--- FunctionalExpressionExtendedField +"ExtendedField" <|--- FunctionalExpressionExtendedField +"MST" <|--- Numeric +"MST" <|--- Unary +"MST" <|--- Binary +"NumericAlgebra" <|--- InnerAlgebra +"NumericAlgebra" <|--- MstNumericAlgebra +"Group" <|--- MstGroup +"NumericAlgebra" <|--- MstGroup +"ScaleOperations" <|--- MstGroup +"Ring" <|--- MstRing +"NumbersAddOperations" <|--- MstRing +"ScaleOperations" <|--- MstRing +"Field" <|--- MstField +"NumbersAddOperations" <|--- MstField +"ScaleOperations" <|--- MstField +"ExtendedField" <|--- MstExtendedField +"NumericAlgebra" <|--- MstExtendedField +"LogicAlgebra" <|--- MstLogicAlgebra +"Field" <|--- SimpleAutoDiffField +"ExpressionAlgebra" <|--- SimpleAutoDiffField +"NumbersAddOperations" <|--- SimpleAutoDiffField +"AutoDiffValue" <|--- AutoDiffVariableWithDerivative +"Symbol" <|--- AutoDiffVariableWithDerivative +"FirstDerivativeExpression" <|--- SimpleAutoDiffExpression +"ExtendedField" <|--- SimpleAutoDiffExtendedField +"ScaleOperations" <|--- SimpleAutoDiffExtendedField +'"" <|--- SimpleAutoDiffExtendedField +"SimpleAutoDiffField" <|--- SimpleAutoDiffExtendedField +"MST" <|--- Symbol +"Symbol" <|--- StringSymbol +"SymbolIndexer" <|--- SimpleSymbolIndexer +"LinearSpace" <|--- BufferedLinearSpace +"LupDecompositionFeature" <|--- LupDecomposition +"DeterminantFeature" <|--- LupDecomposition +"MatrixFeature" <|--- SymmetricMatrixFeature +"StructureFeature" <|--- MatrixFeature +"MatrixFeature" <|--- DiagonalFeature +"DiagonalFeature" <|--- ZeroFeature +"DiagonalFeature" <|--- UnitFeature +"MatrixFeature" <|--- InverseMatrixFeature +"MatrixFeature" <|--- DeterminantFeature +"MatrixFeature" <|--- LFeature +"MatrixFeature" <|--- UFeature +"MatrixFeature" <|--- LUDecompositionFeature +"MatrixFeature" <|--- LupDecompositionFeature +"MatrixFeature" <|--- OrthogonalFeature +"MatrixFeature" <|--- QRDecompositionFeature +"MatrixFeature" <|--- CholeskyDecompositionFeature +"MatrixFeature" <|--- SingularValueDecompositionFeature +'"Matrixbyorigin{ +' +' +' @UnstableKMathAPI +' @Suppress +'overridefungetFeature:F? = +'features.getFeature +' +'overridefuntoString" +'}" <|--- MatrixWrapper +"MatrixFeature" <|--- TransposedFeature +"Matrix" <|--- VirtualMatrix +"Featured" <|--- FeatureSet +"RuntimeException" <|--- ShapeMismatchException +"Group" <|--- GroupND +"AlgebraND" <|--- GroupND +"Ring" <|--- RingND +"GroupND" <|--- RingND +"Field" <|--- FieldND +"RingND" <|--- FieldND +"AlgebraND" <|--- BufferAlgebraND +"GroupND" <|--- BufferedGroupND +"BufferAlgebraND" <|--- BufferedGroupND +"BufferedGroupND" <|--- BufferedRingND +"RingND" <|--- BufferedRingND +"BufferedRingND" <|--- BufferedFieldND +"FieldND" <|--- BufferedFieldND +"StructureND" <|--- BufferND +"MutableStructureND" <|--- MutableBufferND +"BufferND" <|--- MutableBufferND +"BufferedFieldND" <|--- DoubleFieldND +'" +'" <|--- DoubleFieldND +'"NumbersAddOperations" <|--- DoubleFieldND +'" +'" <|--- DoubleFieldND +'"ScaleOperations" <|--- DoubleFieldND +'" +'" <|--- DoubleFieldND +"ExtendedField" <|--- DoubleFieldND +"BufferedRingND" <|--- ShortRingND +'" +'" <|--- ShortRingND +"NumbersAddOperations" <|--- ShortRingND +"StructureND" <|--- Structure1D +"Buffer" <|--- Structure1D +"Structure1D" <|--- MutableStructure1D +"MutableStructureND" <|--- MutableStructure1D +"MutableBuffer" <|--- MutableStructure1D +"Structure1D" <|--- Structure1DWrapper +"MutableStructure1D" <|--- MutableStructure1DWrapper +"Structure1D" <|--- Buffer1DWrapper +"MutableStructure1D" <|--- MutableBuffer1DWrapper +"StructureND" <|--- Structure2D +"Structure2D" <|--- MutableStructure2D +"MutableStructureND" <|--- MutableStructure2D +"Structure2D" <|--- Structure2DWrapper +"MutableStructure2D" <|--- MutableStructure2DWrapper +"Feature" <|--- StructureFeature +"Featured" <|--- StructureND +"StructureND" <|--- MutableStructureND +"Strides" <|--- DefaultStrides +"Algebra" <|--- GroupOperations +"GroupOperations" <|--- Group +"GroupOperations" <|--- RingOperations +"Group" <|--- Ring +"RingOperations" <|--- Ring +"RingOperations" <|--- FieldOperations +"Ring" <|--- Field +"FieldOperations" <|--- Field +"ScaleOperations" <|--- Field +"NumericAlgebra" <|--- Field +"AlgebraElement" <|--- GroupElement +"GroupElement" <|--- RingElement +"RingElement" <|--- FieldElement +"Field" <|--- BigIntField +"NumbersAddOperations" <|--- BigIntField +"ScaleOperations" <|--- BigIntField +"Comparable" <|--- BigInt +"Algebra" <|--- BufferAlgebra +"BufferAlgebra" <|--- BufferField +"Field" <|--- BufferField +"Algebra" <|--- LogicAlgebra +"LogicAlgebra" <|--- BooleanAlgebra +"FieldOperations" <|--- ExtendedFieldOperations +'" +'" <|--- ExtendedFieldOperations +'"TrigonometricOperations" <|--- ExtendedFieldOperations +'" +'" <|--- ExtendedFieldOperations +'"PowerOperations" <|--- ExtendedFieldOperations +'" +'" <|--- ExtendedFieldOperations +"ExponentialOperations" <|--- ExtendedFieldOperations +"ExtendedFieldOperations" <|--- ExtendedField +"Field" <|--- ExtendedField +"NumericAlgebra" <|--- ExtendedField +"ScaleOperations" <|--- ExtendedField +"ExtendedField" <|--- DoubleField +"Norm" <|--- DoubleField +"ScaleOperations" <|--- DoubleField +"ExtendedField" <|--- FloatField +"Norm" <|--- FloatField +"Ring" <|--- IntRing +"Norm" <|--- IntRing +"NumericAlgebra" <|--- IntRing +"Ring" <|--- ShortRing +"Norm" <|--- ShortRing +"NumericAlgebra" <|--- ShortRing +"Ring" <|--- ByteRing +"Norm" <|--- ByteRing +"NumericAlgebra" <|--- ByteRing +"Ring" <|--- LongRing +"Norm" <|--- LongRing +"NumericAlgebra" <|--- LongRing +"Algebra" <|--- NumericAlgebra +"Algebra" <|--- ScaleOperations +"Ring" <|--- NumbersAddOperations +"NumericAlgebra" <|--- NumbersAddOperations +"Algebra" <|--- TrigonometricOperations +"Algebra" <|--- PowerOperations +"Algebra" <|--- ExponentialOperations +"Buffer" <|--- MutableBuffer +"Buffer" <|--- ListBuffer +"MutableBuffer" <|--- MutableListBuffer +"MutableBuffer" <|--- ArrayBuffer +"Buffer" <|--- ReadOnlyBuffer +"Buffer" <|--- VirtualBuffer +"MutableBuffer" <|--- Row +"MutableBuffer" <|--- DoubleBuffer +"ExtendedFieldOperations" <|--- DoubleBufferFieldOperations +"Norm" <|--- DoubleL2Norm +"ExtendedField" <|--- DoubleBufferField +"Norm" <|--- DoubleBufferField +"Buffer" <|--- FlaggedBuffer +"FlaggedBuffer" <|--- FlaggedDoubleBuffer +'" +'" <|--- FlaggedDoubleBuffer +"Buffer" <|--- FlaggedDoubleBuffer +"MutableBuffer" <|--- FloatBuffer +"MutableBuffer" <|--- IntBuffer +"MutableBuffer" <|--- LongBuffer +"Buffer" <|--- MemoryBuffer +"MemoryBuffer" <|--- MutableMemoryBuffer +'" +'" <|--- MutableMemoryBuffer +"MutableBuffer" <|--- MutableMemoryBuffer +"MutableBuffer" <|--- ShortBuffer +"Norm" <|--- L2Norm +"RingVerifier" <|--- FieldVerifier +"SpaceVerifier" <|--- RingVerifier +"AlgebraicVerifier" <|--- SpaceVerifier +"Ring" <|--- JBigIntegerField +"NumericAlgebra" <|--- JBigIntegerField +"Field" <|--- JBigDecimalFieldBase +"PowerOperations" <|--- JBigDecimalFieldBase +"NumericAlgebra" <|--- JBigDecimalFieldBase +"ScaleOperations" <|--- JBigDecimalFieldBase +"JBigDecimalFieldBase" <|--- JBigDecimalField +@enduml \ No newline at end of file diff --git a/examples/src/main/kotlin/space/kscience/kmath/functions/matrixIntegration.kt b/examples/src/main/kotlin/space/kscience/kmath/functions/matrixIntegration.kt index 569a57070..d932fdb9f 100644 --- a/examples/src/main/kotlin/space/kscience/kmath/functions/matrixIntegration.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/functions/matrixIntegration.kt @@ -9,12 +9,12 @@ import space.kscience.kmath.integration.gaussIntegrator import space.kscience.kmath.integration.integrate import space.kscience.kmath.integration.value import space.kscience.kmath.nd.StructureND -import space.kscience.kmath.nd.nd +import space.kscience.kmath.nd.withNd import space.kscience.kmath.operations.DoubleField import space.kscience.kmath.operations.invoke fun main(): Unit = DoubleField { - nd(2, 2) { + withNd(2, 2) { //Produce a diagonal StructureND fun diagonal(v: Double) = produce { (i, j) -> diff --git a/examples/src/main/kotlin/space/kscience/kmath/operations/ComplexDemo.kt b/examples/src/main/kotlin/space/kscience/kmath/operations/ComplexDemo.kt index eefc6e896..8b511f961 100644 --- a/examples/src/main/kotlin/space/kscience/kmath/operations/ComplexDemo.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/operations/ComplexDemo.kt @@ -6,18 +6,20 @@ package space.kscience.kmath.operations import space.kscience.kmath.complex.Complex -import space.kscience.kmath.complex.complex -import space.kscience.kmath.nd.AlgebraND +import space.kscience.kmath.complex.ComplexField +import space.kscience.kmath.complex.withNd +import space.kscience.kmath.nd.StructureND +import space.kscience.kmath.nd.autoNd fun main() { // 2d element - val element = AlgebraND.complex(2, 2).produce { (i, j) -> - Complex(i.toDouble() - j.toDouble(), i.toDouble() + j.toDouble()) + val element = ComplexField.autoNd(2, 2).produce { (i, j) -> + Complex(i - j, i + j) } println(element) // 1d element operation - val result = with(AlgebraND.complex(8)) { + val result: StructureND = ComplexField.withNd(8) { val a = produce { (it) -> i * it - it.toDouble() } val b = 3 val c = Complex(1.0, 1.0) diff --git a/examples/src/main/kotlin/space/kscience/kmath/structures/ComplexND.kt b/examples/src/main/kotlin/space/kscience/kmath/structures/ComplexND.kt index 752e00bdf..c591f5682 100644 --- a/examples/src/main/kotlin/space/kscience/kmath/structures/ComplexND.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/structures/ComplexND.kt @@ -9,10 +9,10 @@ package space.kscience.kmath.structures import space.kscience.kmath.complex.* import space.kscience.kmath.linear.transpose -import space.kscience.kmath.nd.AlgebraND import space.kscience.kmath.nd.StructureND import space.kscience.kmath.nd.as2D -import space.kscience.kmath.nd.real +import space.kscience.kmath.nd.nd +import space.kscience.kmath.operations.DoubleField import space.kscience.kmath.operations.invoke import kotlin.system.measureTimeMillis @@ -20,8 +20,8 @@ fun main() { val dim = 1000 val n = 1000 - val realField = AlgebraND.real(dim, dim) - val complexField: ComplexFieldND = AlgebraND.complex(dim, dim) + val realField = DoubleField.nd(dim, dim) + val complexField: ComplexFieldND = ComplexField.nd(dim, dim) val realTime = measureTimeMillis { realField { @@ -49,7 +49,7 @@ fun main() { fun complexExample() { //Create a context for 2-d structure with complex values ComplexField { - nd(4, 8) { + withNd(4, 8) { //a constant real-valued structure val x = one * 2.5 operator fun Number.plus(other: Complex) = Complex(this.toDouble() + other.re, other.im) diff --git a/examples/src/main/kotlin/space/kscience/kmath/structures/NDField.kt b/examples/src/main/kotlin/space/kscience/kmath/structures/NDField.kt index c842960be..c9cafbba8 100644 --- a/examples/src/main/kotlin/space/kscience/kmath/structures/NDField.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/structures/NDField.kt @@ -8,7 +8,9 @@ package space.kscience.kmath.structures import kotlinx.coroutines.DelicateCoroutinesApi import kotlinx.coroutines.GlobalScope import org.nd4j.linalg.factory.Nd4j -import space.kscience.kmath.nd.* +import space.kscience.kmath.nd.StructureND +import space.kscience.kmath.nd.autoNd +import space.kscience.kmath.nd.nd import space.kscience.kmath.nd4j.Nd4jArrayField import space.kscience.kmath.operations.DoubleField import space.kscience.kmath.operations.invoke @@ -31,17 +33,17 @@ fun main() { val n = 1000 // automatically build context most suited for given type. - val autoField = AlgebraND.auto(DoubleField, dim, dim) + val autoField = DoubleField.autoNd(dim, dim) // specialized nd-field for Double. It works as generic Double field as well. - val realField = AlgebraND.real(dim, dim) + val realField = DoubleField.nd(dim, dim) //A generic boxing field. It should be used for objects, not primitives. - val boxingField = AlgebraND.field(DoubleField, Buffer.Companion::boxing, dim, dim) + val boxingField = DoubleField.nd(Buffer.Companion::boxing, dim, dim) // Nd4j specialized field. val nd4jField = Nd4jArrayField.real(dim, dim) //viktor field val viktorField = ViktorNDField(dim, dim) //parallel processing based on Java Streams - val parallelField = AlgebraND.realWithStream(dim, dim) + val parallelField = DoubleField.ndStreaming(dim, dim) measureAndPrint("Boxing addition") { boxingField { diff --git a/examples/src/main/kotlin/space/kscience/kmath/structures/StreamDoubleFieldND.kt b/examples/src/main/kotlin/space/kscience/kmath/structures/StreamDoubleFieldND.kt index e443a588d..b1248bd0f 100644 --- a/examples/src/main/kotlin/space/kscience/kmath/structures/StreamDoubleFieldND.kt +++ b/examples/src/main/kotlin/space/kscience/kmath/structures/StreamDoubleFieldND.kt @@ -105,4 +105,4 @@ class StreamDoubleFieldND(override val shape: IntArray) : FieldND): BufferND = arg.map { atanh(it) } } -fun AlgebraND.Companion.realWithStream(vararg shape: Int): StreamDoubleFieldND = StreamDoubleFieldND(shape) +fun DoubleField.ndStreaming(vararg shape: Int): StreamDoubleFieldND = StreamDoubleFieldND(shape) diff --git a/gradle.properties b/gradle.properties index b97db1c54..49bbf36dd 100644 --- a/gradle.properties +++ b/gradle.properties @@ -7,6 +7,8 @@ kotlin.code.style=official kotlin.mpp.enableGranularSourceSetsMetadata=true kotlin.mpp.stability.nowarn=true kotlin.native.enableDependencyPropagation=false +kotlin.jupyter.add.scanner=false + org.gradle.configureondemand=true org.gradle.jvmargs=-XX:MaxMetaspaceSize=2G org.gradle.parallel=true diff --git a/kmath-complex/src/commonMain/kotlin/space/kscience/kmath/complex/ComplexFieldND.kt b/kmath-complex/src/commonMain/kotlin/space/kscience/kmath/complex/ComplexFieldND.kt index ae4e05631..41bcb83df 100644 --- a/kmath-complex/src/commonMain/kotlin/space/kscience/kmath/complex/ComplexFieldND.kt +++ b/kmath-complex/src/commonMain/kotlin/space/kscience/kmath/complex/ComplexFieldND.kt @@ -6,7 +6,6 @@ package space.kscience.kmath.complex import space.kscience.kmath.misc.UnstableKMathAPI -import space.kscience.kmath.nd.AlgebraND import space.kscience.kmath.nd.BufferND import space.kscience.kmath.nd.BufferedFieldND import space.kscience.kmath.nd.StructureND @@ -113,12 +112,12 @@ public inline fun BufferedFieldND.produceInline(initializ } -public fun AlgebraND.Companion.complex(vararg shape: Int): ComplexFieldND = ComplexFieldND(shape) +public fun ComplexField.nd(vararg shape: Int): ComplexFieldND = ComplexFieldND(shape) /** * Produce a context for n-dimensional operations inside this real field */ -public inline fun ComplexField.nd(vararg shape: Int, action: ComplexFieldND.() -> R): R { +public inline fun ComplexField.withNd(vararg shape: Int, action: ComplexFieldND.() -> R): R { contract { callsInPlace(action, InvocationKind.EXACTLY_ONCE) } return ComplexFieldND(shape).action() } diff --git a/kmath-core/build.gradle.kts b/kmath-core/build.gradle.kts index 564d06f49..e4436c1df 100644 --- a/kmath-core/build.gradle.kts +++ b/kmath-core/build.gradle.kts @@ -2,6 +2,7 @@ plugins { kotlin("multiplatform") id("ru.mipt.npm.gradle.common") id("ru.mipt.npm.gradle.native") +// id("com.xcporter.metaview") version "0.0.5" } kotlin.sourceSets { @@ -12,6 +13,12 @@ kotlin.sourceSets { } } +//generateUml { +// classTree { +// +// } +//} + readme { description = "Core classes, algebra definitions, basic linear algebra" maturity = ru.mipt.npm.gradle.Maturity.DEVELOPMENT diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/BufferedLinearSpace.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/BufferedLinearSpace.kt index 5471cb925..14235515c 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/BufferedLinearSpace.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/linear/BufferedLinearSpace.kt @@ -6,7 +6,10 @@ package space.kscience.kmath.linear import space.kscience.kmath.misc.PerformancePitfall -import space.kscience.kmath.nd.* +import space.kscience.kmath.nd.BufferedRingND +import space.kscience.kmath.nd.as2D +import space.kscience.kmath.nd.nd +import space.kscience.kmath.nd.unwrap import space.kscience.kmath.operations.Ring import space.kscience.kmath.operations.invoke import space.kscience.kmath.structures.Buffer @@ -23,7 +26,7 @@ public class BufferedLinearSpace>( private fun ndRing( rows: Int, cols: Int, - ): BufferedRingND = AlgebraND.ring(elementAlgebra, bufferFactory, rows, cols) + ): BufferedRingND = elementAlgebra.nd(bufferFactory, rows, cols) override fun buildMatrix(rows: Int, columns: Int, initializer: A.(i: Int, j: Int) -> T): Matrix = ndRing(rows, columns).produce { (i, j) -> elementAlgebra.initializer(i, j) }.as2D() diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/BufferAlgebraND.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/BufferAlgebraND.kt index 9ece51ff8..b01beb02d 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/BufferAlgebraND.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/BufferAlgebraND.kt @@ -5,11 +5,13 @@ package space.kscience.kmath.nd +import space.kscience.kmath.misc.UnstableKMathAPI import space.kscience.kmath.operations.* import space.kscience.kmath.structures.Buffer import space.kscience.kmath.structures.BufferFactory import kotlin.contracts.InvocationKind import kotlin.contracts.contract +import kotlin.jvm.JvmName public interface BufferAlgebraND> : AlgebraND { public val strides: Strides @@ -85,58 +87,61 @@ public open class BufferedFieldND>( } // group factories -public fun > AlgebraND.Companion.group( - space: A, +public fun > A.nd( bufferFactory: BufferFactory, vararg shape: Int, -): BufferedGroupND = BufferedGroupND(shape, space, bufferFactory) +): BufferedGroupND = BufferedGroupND(shape, this, bufferFactory) -public inline fun , R> A.ndGroup( +@JvmName("withNdGroup") +public inline fun , R> A.withNd( noinline bufferFactory: BufferFactory, vararg shape: Int, action: BufferedGroupND.() -> R, ): R { contract { callsInPlace(action, InvocationKind.EXACTLY_ONCE) } - return AlgebraND.group(this, bufferFactory, *shape).run(action) + return nd(bufferFactory, *shape).run(action) } //ring factories -public fun > AlgebraND.Companion.ring( - ring: A, +public fun > A.nd( bufferFactory: BufferFactory, vararg shape: Int, -): BufferedRingND = BufferedRingND(shape, ring, bufferFactory) +): BufferedRingND = BufferedRingND(shape, this, bufferFactory) -public inline fun , R> A.ndRing( +@JvmName("withNdRing") +public inline fun , R> A.withNd( noinline bufferFactory: BufferFactory, vararg shape: Int, action: BufferedRingND.() -> R, ): R { contract { callsInPlace(action, InvocationKind.EXACTLY_ONCE) } - return AlgebraND.ring(this, bufferFactory, *shape).run(action) + return nd(bufferFactory, *shape).run(action) } //field factories -public fun > AlgebraND.Companion.field( - field: A, +public fun > A.nd( bufferFactory: BufferFactory, vararg shape: Int, -): BufferedFieldND = BufferedFieldND(shape, field, bufferFactory) +): BufferedFieldND = BufferedFieldND(shape, this, bufferFactory) +/** + * Create a [FieldND] for this [Field] inferring proper buffer factory from the type + */ +@UnstableKMathAPI @Suppress("UNCHECKED_CAST") -public inline fun > AlgebraND.Companion.auto( - field: A, +public inline fun > A.autoNd( vararg shape: Int, -): FieldND = when (field) { +): FieldND = when (this) { DoubleField -> DoubleFieldND(shape) as FieldND - else -> BufferedFieldND(shape, field, Buffer.Companion::auto) + else -> BufferedFieldND(shape, this, Buffer.Companion::auto) } -public inline fun , R> A.ndField( +@JvmName("withNdField") +public inline fun , R> A.withNd( noinline bufferFactory: BufferFactory, vararg shape: Int, action: BufferedFieldND.() -> R, ): R { contract { callsInPlace(action, InvocationKind.EXACTLY_ONCE) } - return AlgebraND.field(this, bufferFactory, *shape).run(action) + return nd(bufferFactory, *shape).run(action) } \ No newline at end of file diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/DoubleFieldND.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/DoubleFieldND.kt index a448e351e..fed4aca0b 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/DoubleFieldND.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/DoubleFieldND.kt @@ -103,12 +103,12 @@ public class DoubleFieldND( override fun atanh(arg: StructureND): BufferND = arg.map { atanh(it) } } -public fun AlgebraND.Companion.real(vararg shape: Int): DoubleFieldND = DoubleFieldND(shape) +public fun DoubleField.nd(vararg shape: Int): DoubleFieldND = DoubleFieldND(shape) /** * Produce a context for n-dimensional operations inside this real field */ -public inline fun DoubleField.nd(vararg shape: Int, action: DoubleFieldND.() -> R): R { +public inline fun DoubleField.withNd(vararg shape: Int, action: DoubleFieldND.() -> R): R { contract { callsInPlace(action, InvocationKind.EXACTLY_ONCE) } return DoubleFieldND(shape).run(action) } diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/ShortRingND.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/ShortRingND.kt index f96978cfc..5b6e2cd22 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/ShortRingND.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/nd/ShortRingND.kt @@ -34,7 +34,7 @@ public class ShortRingND( public inline fun BufferedRingND.produceInline(crossinline initializer: ShortRing.(Int) -> Short): BufferND = BufferND(strides, ShortBuffer(ShortArray(strides.linearSize) { offset -> ShortRing.initializer(offset) })) -public inline fun ShortRing.nd(vararg shape: Int, action: ShortRingND.() -> R): R { +public inline fun ShortRing.withNd(vararg shape: Int, action: ShortRingND.() -> R): R { contract { callsInPlace(action, InvocationKind.EXACTLY_ONCE) } return ShortRingND(shape).run(action) } diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/BigInt.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/BigInt.kt index 2dd61270d..02741e6ab 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/BigInt.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/BigInt.kt @@ -6,7 +6,6 @@ package space.kscience.kmath.operations import space.kscience.kmath.misc.UnstableKMathAPI -import space.kscience.kmath.nd.AlgebraND import space.kscience.kmath.nd.BufferedRingND import space.kscience.kmath.operations.BigInt.Companion.BASE import space.kscience.kmath.operations.BigInt.Companion.BASE_SIZE @@ -533,5 +532,5 @@ public inline fun Buffer.Companion.bigInt(size: Int, initializer: (Int) -> BigIn public inline fun MutableBuffer.Companion.bigInt(size: Int, initializer: (Int) -> BigInt): MutableBuffer = boxing(size, initializer) -public fun AlgebraND.Companion.bigInt(vararg shape: Int): BufferedRingND = +public fun BigIntField.nd(vararg shape: Int): BufferedRingND = BufferedRingND(shape, BigIntField, Buffer.Companion::bigInt) diff --git a/kmath-core/src/commonTest/kotlin/space/kscience/kmath/structures/NDFieldTest.kt b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/structures/NDFieldTest.kt index f623b00e8..6d4531f41 100644 --- a/kmath-core/src/commonTest/kotlin/space/kscience/kmath/structures/NDFieldTest.kt +++ b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/structures/NDFieldTest.kt @@ -5,9 +5,9 @@ package space.kscience.kmath.structures -import space.kscience.kmath.nd.AlgebraND import space.kscience.kmath.nd.get -import space.kscience.kmath.nd.real +import space.kscience.kmath.nd.nd +import space.kscience.kmath.operations.DoubleField import space.kscience.kmath.operations.invoke import space.kscience.kmath.testutils.FieldVerifier import kotlin.test.Test @@ -16,12 +16,12 @@ import kotlin.test.assertEquals internal class NDFieldTest { @Test fun verify() { - (AlgebraND.real(12, 32)) { FieldVerifier(this, one + 3, one - 23, one * 12, 6.66) } + (DoubleField.nd(12, 32)) { FieldVerifier(this, one + 3, one - 23, one * 12, 6.66) } } @Test fun testStrides() { - val ndArray = AlgebraND.real(10, 10).produce { (it[0] + it[1]).toDouble() } + val ndArray = DoubleField.nd(10, 10).produce { (it[0] + it[1]).toDouble() } assertEquals(ndArray[5, 5], 10.0) } } diff --git a/kmath-core/src/commonTest/kotlin/space/kscience/kmath/structures/NumberNDFieldTest.kt b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/structures/NumberNDFieldTest.kt index 1803fff71..1045933b7 100644 --- a/kmath-core/src/commonTest/kotlin/space/kscience/kmath/structures/NumberNDFieldTest.kt +++ b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/structures/NumberNDFieldTest.kt @@ -7,7 +7,11 @@ package space.kscience.kmath.structures import space.kscience.kmath.linear.LinearSpace import space.kscience.kmath.misc.PerformancePitfall -import space.kscience.kmath.nd.* +import space.kscience.kmath.nd.StructureND +import space.kscience.kmath.nd.combine +import space.kscience.kmath.nd.get +import space.kscience.kmath.nd.nd +import space.kscience.kmath.operations.DoubleField import space.kscience.kmath.operations.Norm import space.kscience.kmath.operations.invoke import kotlin.math.abs @@ -17,7 +21,7 @@ import kotlin.test.assertEquals @Suppress("UNUSED_VARIABLE") class NumberNDFieldTest { - val algebra = AlgebraND.real(3, 3) + val algebra = DoubleField.nd(3, 3) val array1 = algebra.produce { (i, j) -> (i + j).toDouble() } val array2 = algebra.produce { (i, j) -> (i - j).toDouble() } @@ -83,7 +87,7 @@ class NumberNDFieldTest { @Test fun testInternalContext() { algebra { - (AlgebraND.real(*array1.shape)) { with(L2Norm) { 1 + norm(array1) + exp(array2) } } + (DoubleField.nd(*array1.shape)) { with(L2Norm) { 1 + norm(array1) + exp(array2) } } } } } diff --git a/kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/DoubleHistogramSpace.kt b/kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/DoubleHistogramSpace.kt index 27b14b65e..37ab8a1b2 100644 --- a/kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/DoubleHistogramSpace.kt +++ b/kmath-histograms/src/commonMain/kotlin/space/kscience/kmath/histogram/DoubleHistogramSpace.kt @@ -9,6 +9,7 @@ import space.kscience.kmath.domains.Domain import space.kscience.kmath.domains.HyperSquareDomain import space.kscience.kmath.misc.UnstableKMathAPI import space.kscience.kmath.nd.* +import space.kscience.kmath.operations.DoubleField import space.kscience.kmath.structures.* import kotlin.math.floor @@ -28,7 +29,7 @@ public class DoubleHistogramSpace( public val dimension: Int get() = lower.size private val shape = IntArray(binNums.size) { binNums[it] + 2 } - override val histogramValueSpace: DoubleFieldND = AlgebraND.real(*shape) + override val histogramValueSpace: DoubleFieldND = DoubleField.nd(*shape) override val strides: Strides get() = histogramValueSpace.strides private val binSize = DoubleBuffer(dimension) { (upper[it] - lower[it]) / binNums[it] } diff --git a/kmath-jupyter/src/main/kotlin/space/kscience/kmath/jupyter/KMathJupyter.kt b/kmath-jupyter/src/main/kotlin/space/kscience/kmath/jupyter/KMathJupyter.kt index d7438bf0f..e646d2bd0 100644 --- a/kmath-jupyter/src/main/kotlin/space/kscience/kmath/jupyter/KMathJupyter.kt +++ b/kmath-jupyter/src/main/kotlin/space/kscience/kmath/jupyter/KMathJupyter.kt @@ -11,7 +11,6 @@ import kotlinx.html.stream.createHTML import kotlinx.html.unsafe import org.jetbrains.kotlinx.jupyter.api.DisplayResult import org.jetbrains.kotlinx.jupyter.api.HTML -import org.jetbrains.kotlinx.jupyter.api.annotations.JupyterLibrary import org.jetbrains.kotlinx.jupyter.api.libraries.JupyterIntegration import space.kscience.kmath.ast.rendering.FeaturedMathRendererWithPostProcess import space.kscience.kmath.ast.rendering.MathMLSyntaxRenderer diff --git a/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/QowOptimizer.kt b/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/QowOptimizer.kt index 4fe8520da..00df0944f 100644 --- a/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/QowOptimizer.kt +++ b/kmath-optimization/src/commonMain/kotlin/space/kscience/kmath/optimization/QowOptimizer.kt @@ -16,6 +16,14 @@ import space.kscience.kmath.operations.DoubleField import space.kscience.kmath.structures.DoubleBuffer import space.kscience.kmath.structures.DoubleL2Norm +public class QowRuns(public val runs: Int) : OptimizationFeature { + init { + require(runs >= 1) { "Number of runs must be more than zero" } + } + + override fun toString(): String = "QowRuns(runs=$runs)" +} + /** * An optimizer based onf Fyodor Tkachev's quasi-optimal weights method. @@ -56,7 +64,7 @@ public object QowOptimizer : Optimizer { val prior: DifferentiableExpression? get() = problem.getFeature>() - override fun toString(): String = parameters.toString() + override fun toString(): String = parameters.toString() } /** @@ -242,9 +250,15 @@ public object QowOptimizer : Optimizer { } override suspend fun optimize(problem: XYFit): XYFit { - val qowSteps = 2 - val initialWeight = QoWeight(problem, problem.startPoint) - val res = initialWeight.newtonianRun() + val qowRuns = problem.getFeature()?.runs ?: 2 + + + var qow = QoWeight(problem, problem.startPoint) + var res = qow.newtonianRun() + repeat(qowRuns - 1) { + qow = QoWeight(problem, res.parameters) + res = qow.newtonianRun() + } return res.problem.withFeature(OptimizationResult(res.parameters)) } } \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index d1cbbe74c..0fc77b38e 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -5,11 +5,11 @@ pluginManagement { gradlePluginPortal() } - val kotlinVersion = "1.5.21" + val kotlinVersion = "1.5.30" plugins { id("org.jetbrains.kotlinx.benchmark") version "0.3.1" - id("ru.mipt.npm.gradle.project") version "0.10.2" + id("ru.mipt.npm.gradle.project") version "0.10.3" kotlin("multiplatform") version kotlinVersion kotlin("plugin.allopen") version kotlinVersion }