Merge remote-tracking branch 'origin/dev' into nd4j

This commit is contained in:
Iaroslav 2020-08-15 17:14:32 +07:00
commit a6d47515eb
No known key found for this signature in database
GPG Key ID: 46E15E4A31B3BCD7
9 changed files with 115 additions and 7 deletions

View File

@ -16,6 +16,8 @@
- Local coding conventions - Local coding conventions
- Geometric Domains API in `kmath-core` - Geometric Domains API in `kmath-core`
- Blocking chains in `kmath-coroutines` - Blocking chains in `kmath-coroutines`
- Full hyperbolic functions support and default implementations within `ExtendedField`
- Norm support for `Complex`
### Changed ### Changed
- BigInteger and BigDecimal algebra: JBigDecimalField has companion object with default math context; minor optimizations - BigInteger and BigDecimal algebra: JBigDecimalField has companion object with default math context; minor optimizations
@ -23,10 +25,11 @@
- Memory objects have more preconditions (overflow checking) - Memory objects have more preconditions (overflow checking)
- `tg` function is renamed to `tan` (https://github.com/mipt-npm/kmath/pull/114) - `tg` function is renamed to `tan` (https://github.com/mipt-npm/kmath/pull/114)
- Gradle version: 6.3 -> 6.5.1 - Gradle version: 6.3 -> 6.5.1
- Moved probability distributions to commons-rng and to `kmath-prob`. - Moved probability distributions to commons-rng and to `kmath-prob`
### Fixed ### Fixed
- Missing copy method in Memory implementation on JS (https://github.com/mipt-npm/kmath/pull/106) - Missing copy method in Memory implementation on JS (https://github.com/mipt-npm/kmath/pull/106)
- D3.dim value in `kmath-dimensions` - D3.dim value in `kmath-dimensions`
- Multiplication in integer rings in `kmath-core` (https://github.com/mipt-npm/kmath/pull/101) - Multiplication in integer rings in `kmath-core` (https://github.com/mipt-npm/kmath/pull/101)
- Commons RNG compatibility (https://github.com/mipt-npm/kmath/issues/93) - Commons RNG compatibility (https://github.com/mipt-npm/kmath/issues/93)
- Multiplication of BigInt by scalar

View File

@ -22,8 +22,9 @@ object BigIntField : Field<BigInt> {
override val one: BigInt = BigInt.ONE override val one: BigInt = BigInt.ONE
override fun add(a: BigInt, b: BigInt): BigInt = a.plus(b) override fun add(a: BigInt, b: BigInt): BigInt = a.plus(b)
override fun number(value: Number): BigInt = value.toLong().toBigInt()
override fun multiply(a: BigInt, k: Number): BigInt = a.times(k.toLong()) override fun multiply(a: BigInt, k: Number): BigInt = a.times(number(k))
override fun multiply(a: BigInt, b: BigInt): BigInt = a.times(b) override fun multiply(a: BigInt, b: BigInt): BigInt = a.times(b)

View File

@ -1,9 +1,13 @@
package scientifik.kmath.operations package scientifik.kmath.operations
import scientifik.kmath.operations.internal.RingVerifier
import kotlin.test.Test import kotlin.test.Test
import kotlin.test.assertEquals import kotlin.test.assertEquals
class BigIntAlgebraTest { internal class BigIntAlgebraTest {
@Test
fun verify() = BigIntField { RingVerifier(this, +"42", +"10", +"-12", 10).verify() }
@Test @Test
fun testKBigIntegerRingSum() { fun testKBigIntegerRingSum() {
val res = BigIntField { val res = BigIntField {

View File

@ -1,5 +1,6 @@
package scientifik.kmath.operations package scientifik.kmath.operations
import scientifik.kmath.operations.internal.FieldVerifier
import kotlin.math.PI import kotlin.math.PI
import kotlin.math.abs import kotlin.math.abs
import kotlin.test.Test import kotlin.test.Test
@ -7,6 +8,9 @@ import kotlin.test.assertEquals
import kotlin.test.assertTrue import kotlin.test.assertTrue
internal class ComplexFieldTest { internal class ComplexFieldTest {
@Test
fun verify() = ComplexField { FieldVerifier(this, 42.0 * i, 66.0 + 28 * i, 2.0 + 0 * i, 5).verify() }
@Test @Test
fun testAddition() { fun testAddition() {
assertEquals(Complex(42, 42), ComplexField { Complex(16, 16) + Complex(26, 26) }) assertEquals(Complex(42, 42), ComplexField { Complex(16, 16) + Complex(26, 26) })

View File

@ -1,14 +1,16 @@
package scientifik.kmath.operations package scientifik.kmath.operations
import scientifik.kmath.operations.internal.FieldVerifier
import kotlin.test.Test import kotlin.test.Test
import kotlin.test.assertEquals import kotlin.test.assertEquals
class RealFieldTest { internal class RealFieldTest {
@Test
fun verify() = FieldVerifier(RealField, 42.0, 66.0, 2.0, 5).verify()
@Test @Test
fun testSqrt() { fun testSqrt() {
val sqrt = RealField { val sqrt = RealField { sqrt(25 * one) }
sqrt(25 * one)
}
assertEquals(5.0, sqrt) assertEquals(5.0, sqrt)
} }
} }

View File

@ -0,0 +1,9 @@
package scientifik.kmath.operations.internal
import scientifik.kmath.operations.Algebra
internal interface AlgebraicVerifier<T, out A> where A : Algebra<T> {
val algebra: A
fun verify()
}

View File

@ -0,0 +1,24 @@
package scientifik.kmath.operations.internal
import scientifik.kmath.operations.Field
import scientifik.kmath.operations.invoke
import kotlin.test.assertEquals
import kotlin.test.assertNotEquals
internal class FieldVerifier<T>(override val algebra: Field<T>, a: T, b: T, c: T, x: Number) :
RingVerifier<T>(algebra, a, b, c, x) {
override fun verify() {
super.verify()
algebra {
assertNotEquals(a / b, b / a, "Division in $algebra is not anti-commutative.")
assertNotEquals((a / b) / c, a / (b / c), "Division in $algebra is associative.")
assertEquals((a + b) / c, (a / c) + (b / c), "Division in $algebra is not right-distributive.")
assertEquals(a, a / one, "$one in $algebra is not neutral division element.")
assertEquals(one, one / a * a, "$algebra does not provide single reciprocal element.")
assertEquals(zero / a, zero, "$zero in $algebra is not left neutral element for division.")
assertEquals(-one, a / (-a), "Division by sign reversal element in $algebra does not give ${-one}.")
}
}
}

View File

@ -0,0 +1,28 @@
package scientifik.kmath.operations.internal
import scientifik.kmath.operations.Ring
import scientifik.kmath.operations.invoke
import kotlin.test.assertEquals
internal open class RingVerifier<T>(override val algebra: Ring<T>, a: T, b: T, c: T, x: Number) :
SpaceVerifier<T>(algebra, a, b, c, x) {
override fun verify() {
super.verify()
algebra {
assertEquals(a * b, a * b, "Multiplication in $algebra is not commutative.")
assertEquals(a * b * c, a * (b * c), "Multiplication in $algebra is not associative.")
assertEquals(c * (a + b), (c * a) + (c * b), "Multiplication in $algebra is not distributive.")
assertEquals(a * one, one * a, "$one in $algebra is not a neutral multiplication element.")
assertEquals(a, one * a, "$one in $algebra is not a neutral multiplication element.")
assertEquals(a, a * one, "$one in $algebra is not a neutral multiplication element.")
assertEquals(a, one * a, "$one in $algebra is not a neutral multiplication element.")
assertEquals(a, a * one * one, "Multiplication by $one in $algebra is not idempotent.")
assertEquals(a, a * one * one * one, "Multiplication by $one in $algebra is not idempotent.")
assertEquals(a, a * one * one * one * one, "Multiplication by $one in $algebra is not idempotent.")
assertEquals(zero, a * zero, "Multiplication by $zero in $algebra doesn't give $zero.")
assertEquals(zero, zero * a, "Multiplication by $zero in $algebra doesn't give $zero.")
assertEquals(a * zero, a * zero, "Multiplication by $zero in $algebra doesn't give $zero.")
}
}
}

View File

@ -0,0 +1,33 @@
package scientifik.kmath.operations.internal
import scientifik.kmath.operations.Space
import scientifik.kmath.operations.invoke
import kotlin.test.assertEquals
import kotlin.test.assertNotEquals
internal open class SpaceVerifier<T>(
override val algebra: Space<T>,
val a: T,
val b: T,
val c: T,
val x: Number
) :
AlgebraicVerifier<T, Space<T>> {
override fun verify() {
algebra {
assertEquals(a + b, b + a, "Addition in $algebra is not commutative.")
assertEquals(a + b + c, a + (b + c), "Addition in $algebra is not associative.")
assertEquals(x * (a + b), x * a + x * b, "Addition in $algebra is not distributive.")
assertEquals((a + b) * x, a * x + b * x, "Addition in $algebra is not distributive.")
assertEquals(a + zero, zero + a, "$zero in $algebra is not a neutral addition element.")
assertEquals(a, a + zero, "$zero in $algebra is not a neutral addition element.")
assertEquals(a, zero + a, "$zero in $algebra is not a neutral addition element.")
assertEquals(a - b, -(b - a), "Subtraction in $algebra is not anti-commutative.")
assertNotEquals(a - b - c, a - (b - c), "Subtraction in $algebra is associative.")
assertEquals(x * (a - b), x * a - x * b, "Subtraction in $algebra is not distributive.")
assertEquals(a, a - zero, "$zero in $algebra is not a neutral addition element.")
assertEquals(a * x, x * a, "Multiplication by scalar in $algebra is not commutative.")
assertEquals(x * (a + b), (x * a) + (x * b), "Multiplication by scalar in $algebra is not distributive.")
}
}
}