Skip to content

Commit

Permalink
Upgrade build tools plugin to dev version; file reformat; change depe…
Browse files Browse the repository at this point in the history
…ndencies' versions; specify visibility explicitly at certain places (core, especially), make some interfaces `fun`
  • Loading branch information
CommanderTvis committed Sep 8, 2020
1 parent 6494583 commit 5e4522b
Show file tree
Hide file tree
Showing 90 changed files with 899 additions and 1,036 deletions.
17 changes: 5 additions & 12 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
plugins {
id("scientifik.publish") apply false
}

val kmathVersion by extra("0.1.4-dev-8")
plugins { id("ru.mipt.npm.publish") apply false }

val bintrayRepo by extra("scientifik")
val githubProject by extra("kmath")
val kmathVersion: String by extra("0.1.4-dev-8")
val bintrayRepo: String by extra("scientifik")
val githubProject: String by extra("kmath")

allprojects {
repositories {
Expand All @@ -18,8 +15,4 @@ allprojects {
version = kmathVersion
}

subprojects {
if (name.startsWith("kmath")) {
apply(plugin = "scientifik.publish")
}
}
subprojects { if (name.startsWith("kmath")) apply(plugin = "ru.mipt.npm.publish") }
34 changes: 13 additions & 21 deletions examples/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import org.jetbrains.kotlin.allopen.gradle.AllOpenExtension
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
java
kotlin("jvm")
kotlin("plugin.allopen") version "1.3.72"
id("kotlinx.benchmark") version "0.2.0-dev-8"
kotlin("plugin.allopen") version "1.4.0"
id("kotlinx.benchmark") version "0.2.0-dev-20"
}

configure<AllOpenExtension> {
annotation("org.openjdk.jmh.annotations.State")
}
allOpen.annotation("org.openjdk.jmh.annotations.State")

repositories {
maven("http://dl.bintray.com/kyonifer/maven")
Expand All @@ -19,9 +16,7 @@ repositories {
mavenCentral()
}

sourceSets {
register("benchmarks")
}
sourceSets.register("benchmarks")

dependencies {
implementation(project(":kmath-ast"))
Expand All @@ -34,25 +29,22 @@ dependencies {
implementation(project(":kmath-dimensions"))
implementation("com.kyonifer:koma-core-ejml:0.12")
implementation("org.jetbrains.kotlinx:kotlinx-io-jvm:0.2.0-npm-dev-6")
implementation("org.jetbrains.kotlinx:kotlinx.benchmark.runtime:0.2.0-dev-8")
implementation("org.jetbrains.kotlinx:kotlinx.benchmark.runtime:0.2.0-dev-20")
"benchmarksCompile"(sourceSets.main.get().output + sourceSets.main.get().compileClasspath) //sourceSets.main.output + sourceSets.main.runtimeClasspath
}

// Configure benchmark
benchmark {
// Setup configurations
targets {
targets
// This one matches sourceSet name above
register("benchmarks")
}
.register("benchmarks")

configurations {
register("fast") {
warmups = 5 // number of warmup iterations
iterations = 3 // number of iterations
iterationTime = 500 // time in seconds per iteration
iterationTimeUnit = "ms" // time unity for iterationTime, default is seconds
}
configurations.register("fast") {
warmups = 5 // number of warmup iterations
iterations = 3 // number of iterations
iterationTime = 500 // time in seconds per iteration
iterationTimeUnit = "ms" // time unity for iterationTime, default is seconds
}
}

Expand All @@ -65,7 +57,7 @@ kotlin.sourceSets.all {

tasks.withType<KotlinCompile> {
kotlinOptions {
jvmTarget = Scientifik.JVM_TARGET.toString()
jvmTarget = "11"
freeCompilerArgs = freeCompilerArgs + "-Xopt-in=kotlin.RequiresOptIn"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package scientifik.kmath.structures

import kotlin.system.measureTimeMillis

fun main(args: Array<String>) {
fun main() {
val n = 6000

val array = DoubleArray(n * n) { 1.0 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ package scientifik.kmath.structures

import kotlin.system.measureTimeMillis


fun main(args: Array<String>) {

fun main() {
val n = 6000

val structure = NDStructure.build(intArrayOf(n, n), Buffer.Companion::auto) { 1.0 }
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.6.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
2 changes: 1 addition & 1 deletion gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ fi
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`

JAVACMD=`cygpath --unix "$JAVACMD"`

# We build the pattern for arguments to be converted via cygpath
Expand Down
21 changes: 3 additions & 18 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome

set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init
if "%ERRORLEVEL%" == "0" goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Expand All @@ -54,7 +54,7 @@ goto fail
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto init
if exist "%JAVA_EXE%" goto execute

echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
Expand All @@ -64,29 +64,14 @@ echo location of your Java installation.

goto fail

:init
@rem Get command-line arguments, handling Windows variants

if not "%OS%" == "Windows_NT" goto win9xME_args

:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2

:win9xME_args_slurp
if "x%~1" == "x" goto execute

set CMD_LINE_ARGS=%*

:execute
@rem Setup the command line

set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar


@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*

:end
@rem End local scope for the variables with windows NT shell
Expand Down
6 changes: 2 additions & 4 deletions kmath-ast/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
plugins { id("scientifik.mpp") }
plugins { id("ru.mipt.npm.mpp") }

kotlin.sourceSets {
all { languageSettings.useExperimentalAnnotation("kotlin.contracts.ExperimentalContracts") }

commonMain {
dependencies {
api(project(":kmath-core"))
Expand All @@ -17,4 +15,4 @@ kotlin.sourceSets {
implementation(kotlin("reflect"))
}
}
}
}
18 changes: 7 additions & 11 deletions kmath-ast/src/commonMain/kotlin/scientifik/kmath/ast/MST.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,28 @@ import scientifik.kmath.operations.RealField
/**
* A Mathematical Syntax Tree node for mathematical expressions.
*/
sealed class MST {
public sealed class MST {
/**
* A node containing raw string.
*
* @property value the value of this node.
*/
data class Symbolic(val value: String) : MST()
public data class Symbolic(val value: String) : MST()

/**
* A node containing a numeric value or scalar.
*
* @property value the value of this number.
*/
data class Numeric(val value: Number) : MST()
public data class Numeric(val value: Number) : MST()

/**
* A node containing an unary operation.
*
* @property operation the identifier of operation.
* @property value the argument of this operation.
*/
data class Unary(val operation: String, val value: MST) : MST() {
companion object
}
public data class Unary(val operation: String, val value: MST) : MST()

/**
* A node containing binary operation.
Expand All @@ -39,9 +37,7 @@ sealed class MST {
* @property left the left operand.
* @property right the right operand.
*/
data class Binary(val operation: String, val left: MST, val right: MST) : MST() {
companion object
}
public data class Binary(val operation: String, val left: MST, val right: MST) : MST()
}

// TODO add a function with named arguments
Expand All @@ -53,7 +49,7 @@ sealed class MST {
* @param node the node to evaluate.
* @return the value of expression.
*/
fun <T> Algebra<T>.evaluate(node: MST): T = when (node) {
public fun <T> Algebra<T>.evaluate(node: MST): T = when (node) {
is MST.Numeric -> (this as? NumericAlgebra<T>)?.number(node.value)
?: error("Numeric nodes are not supported by $this")
is MST.Symbolic -> symbol(node.value)
Expand Down Expand Up @@ -84,4 +80,4 @@ fun <T> Algebra<T>.evaluate(node: MST): T = when (node) {
* @param algebra the algebra that provides operations.
* @return the value of expression.
*/
fun <T> MST.interpret(algebra: Algebra<T>): T = algebra.evaluate(this)
public fun <T> MST.interpret(algebra: Algebra<T>): T = algebra.evaluate(this)
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import scientifik.kmath.operations.*
/**
* [Algebra] over [MST] nodes.
*/
object MstAlgebra : NumericAlgebra<MST> {
public object MstAlgebra : NumericAlgebra<MST> {
override fun number(value: Number): MST = MST.Numeric(value)

override fun symbol(value: String): MST = MST.Symbolic(value)
Expand All @@ -20,7 +20,7 @@ object MstAlgebra : NumericAlgebra<MST> {
/**
* [Space] over [MST] nodes.
*/
object MstSpace : Space<MST>, NumericAlgebra<MST> {
public object MstSpace : Space<MST>, NumericAlgebra<MST> {
override val zero: MST = number(0.0)

override fun number(value: Number): MST = MstAlgebra.number(value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package scientifik.kmath.ast

import scientifik.kmath.expressions.*
import scientifik.kmath.operations.*
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind
import kotlin.contracts.contract

Expand All @@ -13,7 +12,7 @@ import kotlin.contracts.contract
* @property algebra the algebra that provides operations.
* @property mst the [MST] node.
*/
class MstExpression<T>(val algebra: Algebra<T>, val mst: MST) : Expression<T> {
public class MstExpression<T>(public val algebra: Algebra<T>, public val mst: MST) : Expression<T> {
private inner class InnerAlgebra(val arguments: Map<String, T>) : NumericAlgebra<T> {
override fun symbol(value: String): T = arguments[value] ?: algebra.symbol(value)
override fun unaryOperation(operation: String, arg: T): T = algebra.unaryOperation(operation, arg)
Expand All @@ -33,71 +32,73 @@ class MstExpression<T>(val algebra: Algebra<T>, val mst: MST) : Expression<T> {
/**
* Builds [MstExpression] over [Algebra].
*/
inline fun <reified T : Any, A : Algebra<T>, E : Algebra<MST>> A.mst(
public inline fun <reified T : Any, A : Algebra<T>, E : Algebra<MST>> A.mst(
mstAlgebra: E,
block: E.() -> MST
): MstExpression<T> = MstExpression(this, mstAlgebra.block())

/**
* Builds [MstExpression] over [Space].
*/
inline fun <reified T : Any> Space<T>.mstInSpace(block: MstSpace.() -> MST): MstExpression<T> {
public inline fun <reified T : Any> Space<T>.mstInSpace(block: MstSpace.() -> MST): MstExpression<T> {
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
return MstExpression(this, MstSpace.block())
}

/**
* Builds [MstExpression] over [Ring].
*/
inline fun <reified T : Any> Ring<T>.mstInRing(block: MstRing.() -> MST): MstExpression<T> {
public inline fun <reified T : Any> Ring<T>.mstInRing(block: MstRing.() -> MST): MstExpression<T> {
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
return MstExpression(this, MstRing.block())
}

/**
* Builds [MstExpression] over [Field].
*/
inline fun <reified T : Any> Field<T>.mstInField(block: MstField.() -> MST): MstExpression<T> {
public inline fun <reified T : Any> Field<T>.mstInField(block: MstField.() -> MST): MstExpression<T> {
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
return MstExpression(this, MstField.block())
}

/**
* Builds [MstExpression] over [ExtendedField].
*/
inline fun <reified T : Any> Field<T>.mstInExtendedField(block: MstExtendedField.() -> MST): MstExpression<T> {
public inline fun <reified T : Any> Field<T>.mstInExtendedField(block: MstExtendedField.() -> MST): MstExpression<T> {
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
return MstExpression(this, MstExtendedField.block())
}

/**
* Builds [MstExpression] over [FunctionalExpressionSpace].
*/
inline fun <reified T : Any, A : Space<T>> FunctionalExpressionSpace<T, A>.mstInSpace(block: MstSpace.() -> MST): MstExpression<T> {
public inline fun <reified T : Any, A : Space<T>> FunctionalExpressionSpace<T, A>.mstInSpace(block: MstSpace.() -> MST): MstExpression<T> {
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
return algebra.mstInSpace(block)
}

/**
* Builds [MstExpression] over [FunctionalExpressionRing].
*/
inline fun <reified T : Any, A : Ring<T>> FunctionalExpressionRing<T, A>.mstInRing(block: MstRing.() -> MST): MstExpression<T> {
public inline fun <reified T : Any, A : Ring<T>> FunctionalExpressionRing<T, A>.mstInRing(block: MstRing.() -> MST): MstExpression<T> {
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
return algebra.mstInRing(block)
}

/**
* Builds [MstExpression] over [FunctionalExpressionField].
*/
inline fun <reified T : Any, A : Field<T>> FunctionalExpressionField<T, A>.mstInField(block: MstField.() -> MST): MstExpression<T> {
public inline fun <reified T : Any, A : Field<T>> FunctionalExpressionField<T, A>.mstInField(block: MstField.() -> MST): MstExpression<T> {
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
return algebra.mstInField(block)
}

/**
* Builds [MstExpression] over [FunctionalExpressionExtendedField].
*/
inline fun <reified T : Any, A : ExtendedField<T>> FunctionalExpressionExtendedField<T, A>.mstInExtendedField(block: MstExtendedField.() -> MST): MstExpression<T> {
public inline fun <reified T : Any, A : ExtendedField<T>> FunctionalExpressionExtendedField<T, A>.mstInExtendedField(
block: MstExtendedField.() -> MST
): MstExpression<T> {
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
return algebra.mstInExtendedField(block)
}
Loading

0 comments on commit 5e4522b

Please sign in to comment.