https://kotlinlang.org logo
Join Slack
Powered by
# mathematics
  • p

    Pavel Gorgulov

    07/29/2022, 10:25 AM
    Multik v0.2.0 is out! 🎉 Now Multik is a multiplatform library, with native support for Android and Apple Silicon: https://blog.jetbrains.com/kotlin/2022/07/multik-0-2-multiplatform-with-support-for-android-and-apple-silicon Slack Conversation
    👍 3
    🎉 1
    i
    • 2
    • 1
  • a

    altavir

    08/03/2022, 1:56 PM
    @Pavel Gorgulov This seems to be a bug. The type should be DN, not D4
    👀 1
  • a

    altavir

    08/04/2022, 6:58 AM
    @Pavel Gorgulov I finished migrating KMath multik integration to MPP: https://github.com/mipt-npm/kmath/commit/a8182fad23417f4302ea77ccdeba3b931e50a471. The only major problem is that service provider mechanism does not work on JS (see https://youtrack.jetbrains.com/issue/KT-53056/Multiplatform-equivalent-of-JVMs-ServiceLoader). So getters like
    Multik.stat
    fail by default there. Engines must be loaded manually and it should be mentioned in the documentation.
    👍 1
    p
    • 2
    • 1
  • a

    altavir

    08/17/2022, 6:01 PM
    https://kotlinlang.slack.com/archives/C0BJ0GTE2/p1660759184455119
  • a

    altavir

    10/04/2022, 7:34 AM
    I am thinking about replacing all @Ролан postfix notations in tensors like
    tensor.lup()
    with prefix notations like
    Algebra::lup(tensor)
    . It allows much more robust use of contexts and extensions and in my opinion is much more readable. In numpy/Torch postfix notation is used mostly because it could not be done in the other way. The only thing we loose is easy chaining (it could be brought back via scope functions). Does anybody know a case with real complicated chaining on tensors?
  • c

    Curtis Ullerich

    10/06/2022, 3:02 AM
    I'm experimenting with writing a DSL for AST matching (and hopefully also property extraction). I'm curious if anyone knows of prior art.
    a
    • 2
    • 7
  • n

    nino

    11/04/2022, 1:40 PM
    Hey there, why does
    0.42.rem(0.14)
    return
    0.13999999999999996
    and how can I fix it?
    a
    a
    a
    • 4
    • 15
  • a

    altavir

    11/05/2022, 6:37 PM
    KMath-polynomial package by @Gleb Minaev was to heavy for our primary repository, so it has moved to a separate one: https://github.com/SciProgCentre/kmath-polynomial. Gleb is maintaining it now. The library is dedicated to operations on polynomials and rational functions.
  • s

    Sam Stone

    12/04/2022, 1:59 AM
    Given x (values from 0..Int.MAX_VALUE), when
    x in 0 until a
    , return 0,
    a until b
    return 1,
    b until c
    return 2, greater than or equal to
    d
    , return 3?
    g
    • 2
    • 3
  • a

    altavir

    12/10/2022, 9:29 AM
    A naïve classifier (proto convolutional network), using Commons Math and Plotly-kt: https://github.com/SciProgCentre/kmath/blob/dev/examples/notebooks/Naive%20classifier.ipynb
    👍 3
  • p

    Peter

    12/12/2022, 8:37 AM
    Have been playing around with Multik this weekend and have to say nice performance out of the box (I’m using the JVM version only). One thing I couldn’t figure out how to efficiently copy/set data. What I want to do in a matrix (D2Array<Float>) is to move the last x rows to the first x rows. I use a “hack”, but I feel this is not very elegantly:
    Copy code
    data = data[rows-x until rows].cat(mk.zeros(rows-x, columns))
    Does anyone knows a better way of doing this (performance is key) ?
    a
    r
    p
    • 4
    • 5
  • s

    Sam Stone

    01/01/2023, 10:23 PM
    Given a 2D square array, how do I get the row and column given a position? Can't quite get the modulos right. E.g. in a 5x5 array, how do I find the 13th element?
    i
    a
    • 3
    • 2
  • m

    mcpiroman

    01/10/2023, 12:16 PM
    Is KMath going to have general purpose equation solving and simplification as sympy does?
    a
    • 2
    • 4
  • p

    Paolo Rotolo

    01/24/2023, 11:36 AM
    Hey all! Are there any plans to release a new version of KMath with
    iosSimulatorArm64
    as target?
    a
    • 2
    • 4
  • p

    PHondogo

    02/14/2023, 7:34 AM
    Hello! Is there KMath analog for org.apache.commons.math3.analysis.interpolation.PiecewiseBicubicSplineInterpolatingFunction?
    a
    • 2
    • 11
  • a

    altavir

    04/09/2023, 8:37 AM
    They say "do not release on Friday". How about releases on Sunday? KMath 0.3.1 pre-release is out: https://github.com/SciProgCentre/kmath/releases/tag/v0.3.1-dev-RC and available on http://repo.kotlin.link. Documentation is still a bit of a mess. But on the other hand we now have Wasm support for core modules.
    👍 3
    🐕 2
    ❤️ 2
    👍🏾 1
    K 3
    K 2
    K 2
    🤠 2
  • m

    Marc Reichelt

    04/20/2023, 3:06 PM
    Hey there! We’re using Multik in production, and it’s working great - most of the time, because it crashes for some of our users with:
    IllegalStateException: Fail to find engine
    What’s weird about this is that it is happening only sometimes. Did anyone ran into this issue? Link: https://github.com/Kotlin/multik/issues/155
    👀 1
    r
    p
    • 3
    • 5
  • a

    altavir

    05/13/2023, 6:19 AM
    KMath 0.3.1 is released on mavencentral (without ios artefacts) and
    repo.kotlin.link
    (with ios artefacts). It contains a lot of minor and major changes and new features: https://github.com/SciProgCentre/kmath/releases. Additionally there is a huge new separate KMath-based project kmath-polynomials: https://github.com/SciProgCentre/kmath-polynomial with algebras for polynomials and rational functions maintained by @Gleb Minaev. A lot of work has been done. A lot more still awaits. Slack Conversation
    👍 2
  • d

    Daniel Rindt

    07/10/2023, 11:31 AM
    dear community, I'm not a mathematician so please forgive me if I can't express my concern correctly. In my scenario, I have X and Y values that represent a connection. I would now like to use any X value and calculate the Y for it. I've already done this in a spreadsheet using a 4th degree polynomial. Now my question, can I solve this question with kmath and if so, how? Thank you for your time and effort. Daniel
    i
    a
    • 3
    • 16
  • s

    Sam Stone

    07/26/2023, 10:09 PM
    Is there an official or widely used BigDecimal KMM equivalent, or do I need to
    expect
    these various implementations? https://discuss.kotlinlang.org/t/multiplatform-bigdecimal-implementation/5631/10
    a
    a
    • 3
    • 8
  • p

    Paolo Rotolo

    08/04/2023, 12:49 PM
    Hi! Do you know if
    kotlin-statistics
    has been moved somewhere else? I can't find it on GH anymore: https://github.com/thomasnield/kotlin-statistics
    p
    a
    m
    • 4
    • 5
  • s

    Sam Stone

    08/11/2023, 9:18 AM
    I am writing a program to calculate wages (usually doubles are a no-no, but I think it is ok in this case). Part of the company’s requirements are that the new salary must be expressed in terms of the old rate with a proportionate number of hours added to the total hours worked. This function is not giving me the answers that a colleague drafted on paper - are our equations correct?
    Copy code
    /**
    Given:
    old rate = $30/hour
    new rate = $37.5/hour
    Hours in new rate = 36.72
    Total hours = 52.21
    
    Equations:
    1/x := 30/37.5 == 37.5/30 = x; x=1.25, so 1 hour of the new rate is worth 1.25 hours in the old rate.
    
    Hours in old rate = total hours - hours in new rate = 52.21 - 32.67 = 15.49
    (1.25 * hours worked in new rate) * old rate = equivalent hours in new rate * old rate = salary for hours in new rate
    
    Calculations:
    1.25   * 36.72   = 45.9 upscaled hours
    45.9   * 30      = $1,377  for hours in new rate
    15.49  * 30      = $464.70 for hours in old rate
    $1,377 + $464.70 = $1,841.70 total
    Check: 
    36.72  * $37.5   = $1,377  for hours in new rate
    15.49  * $30     = $464.70 for hours in old rate
    $1,377 + $464.70 = $1,841.70 total
     * */
    Copy code
    fun calculateHoursInNewRate(oldRatePerHour: Double,newRatePerHour: Double,totalHoursWorked: Double,hoursInNewRateWorked: Double): Double {
        val equivalentOfOldHoursWorkedInNewRate = newRatePerHour / oldRatePerHour
        val hoursInOldRate = totalHoursWorked - hoursInNewRateWorked
        val upscaledHours = equivalentOfOldHoursWorkedInNewRate * hoursInNewRateWorked
        val salaryForHoursInNewRateWorked = upscaledHours * oldRatePerHour
        val salaryForHoursInOldRateWorked = hoursInOldRate * oldRatePerHour
        return salaryForHoursInNewRateWorked + salaryForHoursInOldRateWorked
    }
    g
    a
    • 3
    • 3
  • a

    altavir

    02/18/2024, 6:11 AM
    Interesting fact. It seems like using newer Oracle GraalVM JIT significantly improves performance even for Multik
    i
    • 2
    • 20
  • a

    altavir

    02/18/2024, 4:45 PM
    @Iaroslav Postovalov here are the results for Oracle GraalVM 21:
    Copy code
    jvm summary:
    Benchmark                            Mode  Cnt   Score   Error  Units
    DotBenchmark.bufferedDot            thrpt    5   1.336 ± 0.026  ops/s
    DotBenchmark.cmDot                  thrpt    5   0.836 ± 0.027  ops/s
    DotBenchmark.cmDotWithConversion    thrpt    5   0.795 ± 0.344  ops/s
    DotBenchmark.ejmlDot                thrpt    5   6.532 ± 0.066  ops/s
    DotBenchmark.ejmlDotWithConversion  thrpt    5   6.051 ± 0.180  ops/s
    DotBenchmark.multikDot              thrpt    5  40.559 ± 4.751  ops/s
    DotBenchmark.parallelDot            thrpt    5  11.879 ± 1.117  ops/s
    DotBenchmark.tensorDot              thrpt    5   1.183 ± 0.125  ops/s
    DotBenchmark.tfDot                  thrpt    5   6.013 ± 0.323  ops/s
    • 1
    • 2
  • a

    Abdhilahi Wabwire

    03/01/2024, 4:58 AM
    Has anyone here ever written a mathematics engine in Kotlin? If so, describe your implementation or provide a code snippet. I am using mathematical algorithms as references. I am currently building a mathematics engine to challenge Microsoft Math Solver but Open Source. How have you used KMath?
    g
    a
    • 3
    • 4
  • j

    Jason Thomas

    03/10/2024, 2:01 AM
    I'm trying to do matrix multiplication in multik (https://github.com/Kotlin/multik). It seems like I should get a 2 X 3 matrix, but I get an error message that says "Array shapes don't match: [2, 1] != [1, 3]". Can anyone say if this is a bug or am I doing something horribly wrong?
    Copy code
    val a = mk.ndarray(floatArrayOf(1.0f, 2.0f), 2, 1)
    val b = mk.ndarray(floatArrayOf(1.0f, 2.0f, 3.0f), 1, 3)
    
    val result = a * b
    println(result)
    a
    • 2
    • 3
  • c

    corneil

    10/17/2024, 1:09 PM
    It would be interesting to see benchmarks comparing to other languages / tools that are being used for solving same problems.
    a
    • 2
    • 3
  • f

    Fudge

    11/13/2024, 8:08 PM
    Hey, I'm a little confused when it comes to Kotlin math libs. I'm looking for a good library to use for 3D graphics (matrix multiplications etc). There is kmath by romain guy, multik by Kotlin itself, korlibs-math, and some others. So which one fits best?
    a
    • 2
    • 6
  • a

    altavir

    01/12/2025, 11:22 AM
    KMarth 0.4.1 is released: https://github.com/SciProgCentre/kmath/releases/tag/v0.4.1 • Moved to Kotlin 2.1 and enabled cross-compilation for iOS targets (now Maven central releases will be more frequent, but we can't run tests on iOS artefacts) • Added ojalgo wrapper. • Refactored Ejml and Commons-math linear spaces to match common pattern. • Small additions and refactoring.
    👍 2
    K 1
    • 1
    • 1
  • a

    altavir

    01/27/2025, 10:46 AM
    KMath 0.4.2 is released. It fixes one critical bug in ojalgo and makes some changes to unstable API for matrix builders: https://github.com/SciProgCentre/kmath/releases/tag/v0.4.2