A scientific computing library for Kotlin

Related tags

App koma
Overview

GitHub issues License Bintray Travis AppVeyor

Koma

Koma is a scientific computing environment for Kotlin.

Project goals:

  • Create a scientific programming environment that is similar in style to NumPy or MATLAB
  • Enable writing numerical applications which can be deployed on JVM, JS, and native platforms
  • Support using said applications from Python, MATLAB, Java, and other pre-existing codebases
  • Use pluggable back-ends to enable optimized computation via pre-existing platform libraries

Project documentation

For more information on using Koma, please see the documentation

Building

To build from source, use one of the following commands:

# Java
./gradlew buildJvm
# Javascript
./gradlew buildJs
# Native (example executable, see examples/native/main.kt)
./gradlew buildNative

Output artifacts are left in the ./build folder. For more information see building from source.

Related Projects

Koma has backends that wrap several other numerical projects on the JVM:

For a data analysis library similar to pandas, check out https://github.com/holgerbrandl/kplyr

For Kotlin statistical methods, check out https://github.com/thomasnield/kotlin-statistics

Comments
  • Make NDArray's map function generic

    Make NDArray's map function generic

    NDArray's map is defined as fun map(f: (T) -> T): NDArray<T>. It would be more useful if map were a generic, in the sense of fun map<R>(f: (T) -> R): NDArray<R>.

    Here's some sample code which I'd like to compile, but can't:

    var counter = 0
    val ints: NDArray<Int> = DefaultNDArray(3, 4, 5) { ++counter }
    val doubles: NDArray<Double> = ints.map { it.toDouble() }
    

    Currently I'm using the following hacky workaround, which is dangerous and insane but seems to work.

    fun <TIn, TOut> NDArray<TIn>.crazyMapWorkaround(fn: (TIn) -> TOut) = 
        toIterable().iterator().let { itr ->
            DefaultNDArray(*(shape().toIntArray())) { fn(itr.next()) }
        }
    
    enhancement 
    opened by drmoose 29
  • Improvements to slicing

    Improvements to slicing

    I'd like to suggest several improvements to slicing.

    Matrix lets you use any combination of Ints and IntRanges for slicing. It does this by providing all combinations of them in get() and set(): (Int, Int), (Int, IntRange), (IntRange, Int), and (IntRange, IntRange). That wouldn't be practical for NDArray, so instead it only has two versions. One takes vararg Int and returns an element, and the other takes vararg IntRange and returns an NDArray. That means you can't mix them. For example, if I want to extract a 1D slice from a 3D array I can't write

    array[0, 0..10, 5]
    

    Instead I have to write

    array[0..0, 0..10, 5..5]
    

    That's much less readable, and it creates more opportunities for errors. It also returns an array of the wrong shape. I wanted a 1D array, but instead it returns a 3D array of shape (1, 10, 1).

    I suggest changing the signature form vararg IntRange to vararg Any so the user can mix and match Ints and IntRanges. That will mean relying on runtime type checking to throw an exception if the user passes a value of any other type, which isn't ideal. But I think it's a minor tradeoff compared to the much more important benefits.

    Unlike Matrix, NDArray only supports slicing in get(), not set(), so you can't use it on the left side of an assignment. It should be supported in set() too.

    Matrix allows you to use a negative number for the upper bound of a range, which it interprets relative to the width of the matrix. But it doesn't support it for the lower bound, so you can't write -5..-1 to get the last five elements. It also doesn't support negative values for specific indices passed as Ints, only for ranges. And NDArray doesn't support negative indices at all. I suggest allowing them everywhere in any method that takes an index.

    opened by peastman 22
  • More features for NDArray

    More features for NDArray

    Matrix has a lot of features that would be equally appropriate for NDArray. This includes methods like min(), max(), mean(), toString(), etc. Also a lot of the math functions defined in matrixfuncs.kt. If you agree, I'd like to start implementing some of them.

    opened by peastman 13
  • `Could not find com.kyonifer:koma-core-ejml` due to bintray shutdown

    `Could not find com.kyonifer:koma-core-ejml` due to bintray shutdown

    Since 2021-05-01 all bintray services are down permanently, therefore it's impossible to use bintray-hosted libraries. Is it possible to migrate it somewhere? For example, to repo.kotlin.link ?

    opened by MarkTheHopeful 11
  • Better random number generator

    Better random number generator

    Random number generation is implemented with java.util.Random. That's a linear congruential generator, which isn't suitable for scientific applications. Or just about any other application where you care how the numbers are distributed. It would be good to replace it with something more robust.

    The most popular choice is Mersenne Twister, but that's mainly for historical reasons. It has some statistical weaknesses, and it's generally inferior to newer algorithms. PCG has been getting a lot of attention lately. It's fast, and it passes every statistical test that's been thrown at it. It's also very easy to implement.

    opened by peastman 10
  • Easier creation of NDArrays with specified contents

    Easier creation of NDArrays with specified contents

    Matrix has a convenient builder syntax that makes it easy to create matrices containing arbitrary values, but there's nothing comparable for NDArray (or if there is, I haven't found it). This would be a useful addition. Possibly the same builder syntax could be extended to arrays, though it's not obvious to me how to handle arbitrary data types and more than two dimensions. Other approaches are also possible. For example, there could be a method that takes ordinary arrays as input. That's the method used by NumPy, although the syntax is less convenient in Kotlin.

    val array = NDArray.create(arrayOf(doubleArrayOf(10.0, 5.0), doubleArrayOf(-5.0, 10.0)))
    

    Another possibility is to pass the elements directly to the creator function.

    val array = NDArray.create(1, 2, -3, -4)
    

    That would create a 1D array. For more dimensions, you would list the elements in flattened order, then give the shape as an extra argument.

    val array = NDArray.create(10.0, 5.0, -5.0, 10.0, shape=intArrayOf(2, 2))
    

    This is similar to the approach used by ND4J.

    opened by peastman 9
  • Implement toMatrix(), toVector(), matrixOf(), vectorOf()

    Implement toMatrix(), toVector(), matrixOf(), vectorOf()

    I implemented some syntactic sugar to turn an Iterable<T> or Sequence<T> into a Matrix<N>. This can be used via toMatrix() and toVector().

    import javafx.scene.paint.Color
    import koma.matrix.Matrix
    
    fun main(args: Array<String>) {
    
        val colors = sequenceOf(
                Color.RED,
                Color.PINK,
                Color.YELLOW,
                Color.BLUE,
                Color.GREEN
        )
    
        val matrix = colors.toMatrix(
                { it.red },
                { it.green },
                { it.blue }
        )
    
        println(matrix)
    }
    

    I also implemented a matrixOf() and vectorOf() set of functions to follow Kotlin idioms.

    val a = matrixOf(0, 1, 2 end 3, 4, 5)
    
    opened by thomasnield 9
  • Created PCG random number generator

    Created PCG random number generator

    Implements #80.

    When creating the default random number generator, I've currently hardcoded the seed value as 0. It probably would be better to make it nondeterministic so you'll get different random numbers every time you run your program. But I can't figure out how to do that without writing multiplatform code, which really seems excessive! Kotlin 1.3 will add functions like getTimeNanos(), plus the whole kotlin.random package. Until that's released, is there some place to grab a single number worth of entropy from without using platform specific code?

    opened by peastman 7
  • Unable to build native on Mac - Missing cblas.h

    Unable to build native on Mac - Missing cblas.h

    I got the following error trying to build for Kotlin Native:

    Exception in thread "main" java.lang.Error: /var/folders/y7/qnnjc1q143q39hwttm_rs4gm0000gn/T/tmp7387811828594230022.c:1:10: fatal error: 'cblas.h' file not found
            at org.jetbrains.kotlin.native.interop.indexer.UtilsKt.ensureNoCompileErrors(Utils.kt:137)
            at org.jetbrains.kotlin.native.interop.indexer.IndexerKt.indexDeclarations(Indexer.kt:898)
            at org.jetbrains.kotlin.native.interop.indexer.IndexerKt.buildNativeIndexImpl(Indexer.kt:888)
            at org.jetbrains.kotlin.native.interop.indexer.NativeIndexKt.buildNativeIndex(NativeIndex.kt:56)
            at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.processCLib(main.kt:307)
            at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.interop(main.kt:38)
            at org.jetbrains.kotlin.cli.utilities.InteropCompilerKt.invokeInterop(InteropCompiler.kt:100)
            at org.jetbrains.kotlin.cli.utilities.MainKt.main(main.kt:29)
    

    I installed openblas but it didn't help.

    opened by quenio 7
  • Fix for Issue #107 - Bintray shutdown

    Fix for Issue #107 - Bintray shutdown

    Hey folks. My team at Core has a potential fix for the Bintray shutdown #107 . It's working for us and would love to give back to the team who worked hard on putting koma together in the first place.

    @kyonifer Let us know if this works!

    opened by brianbolze 6
  • Add an overload of equals

    Add an overload of equals

    This program:

    import koma.eye
    
    fun main(args: Array<String>)
    {
        val a = eye(3)
        val b = eye(3)
        println(a == b)
    }
    

    Produces false, because it just compares whether a and b refer to the same Kotlin object.

    It would be very useful to have an overload that would compare matrices in the mathematical sense. That is, two matrices are the same if they have the same dimensions and each element of one matrix is equal to the element in the other matrix in the same column and row.

    enhancement 
    opened by martin-drozdik 4
  • Weird bug with augmented assignment and Int constant value

    Weird bug with augmented assignment and Int constant value

    I spent hours tracking down this bug, because the code compiled and looked fine to me:

    val m1 = mat[0.5]
    m1[0] -= 1
    println(m1[0]) // 0.0 WRONG!
    

    When I replaced the 1 with 1.0 (out of lack of things to try) the bug went away:

    val m2 = mat[0.5]
    m2[0] -= 1.0
    println(m2[0]) // -0.5 correct
    

    What's weird is that Kotlin has no issue with auto-casting a constant to double:

    val m3 = mat[0.5]
    println(m3[0] - 1) // -0.5 correct
    

    So the bug only appears when using augmented assignments (+=, -=, etc.)

    I have no idea how to debug this.

    I'm using Koma EJML 0.12, Kotlin 1.3.61, Java 1.8.0_242

    opened by tobia 2
  • Vectorized mathematical functions

    Vectorized mathematical functions

    Hello!

    I need to do some efficient number crunching and was looking into Koma. However, I have need to take the element-wise exponent and logarithm of arrays, which does not seem to be possible without mapping the elements as boxed values (please correct me if I am wrong).

    I think it would be a relevant improvement to catch up feature-wise to other numerical libraries such as Numpy.

    opened by SebastianCallh 2
  • Why is there no Vector interface?

    Why is there no Vector interface?

    I would like to ask what motivated your choice to cover both vectors and matrices by the unified Matrix interface. Are there some underlying technical difficulties? Did you consider adding Vector in the past and dismissed the idea?

    Right now I am converting a lot between List and matrices Matrix about which I know that they are vector-shaped. It would make the code cleaner and more performant, if there was a Vector interface which would extend List.

    If this is not on your agenda, I would like to do this in my code as a private extension and would welcome any advice that you have.

    Thank you!

    opened by martin-drozdik 2
  • Basic example on website fails to compile with unresolved references

    Basic example on website fails to compile with unresolved references

    The snippet

        figure(1)
        // Second parameter is color
        plot(a, 'b', "First Run")
        plot(a+1, 'y', "First Run Offset")
        xlabel("Time (s)")
        ylabel("Magnitude")
        title("White Noise")
    
        figure(2)
        plot(b, 'g') // green
        xlabel("Velocity (lightweeks/minute)")
        ylabel("Intelligence")
        title("Random Walk")
    

    from https://koma.kyonifer.com/index.html fails to compile with these errors:

    e: main.kt: (11, 5): Unresolved reference: figure
    e: main.kt: (13, 5): Unresolved reference: plot
    e: main.kt: (14, 5): Unresolved reference: plot
    e: main.kt: (15, 5): Unresolved reference: xlabel
    e: main.kt: (16, 5): Unresolved reference: ylabel
    e: main.kt: (17, 5): Unresolved reference: title
    e: main.kt: (19, 5): Unresolved reference: figure
    e: main.kt: (20, 5): Unresolved reference: plot
    e: main.kt: (21, 5): Unresolved reference: xlabel
    e: main.kt: (22, 5): Unresolved reference: ylabel
    e: main.kt: (23, 5): Unresolved reference: title
    

    Is the plotting library really included with the listed dependency (below) or am I doing something wrong?

    dependencies{
        compile group: "com.kyonifer", name:"koma-core-ejml", version: "0.12"
    }
    
    opened by obadz 3
  • Compilation Error in Java

    Compilation Error in Java

    Hi, I'm getting these warnings\error when trying to use koma in a java project.

    Warning:java: unknown enum constant kotlin.annotation.AnnotationRetention.BINARY reason: class file for kotlin.annotation.AnnotationRetention not found Warning:java: unknown enum constant kotlin.annotation.AnnotationTarget.CLASS reason: class file for kotlin.annotation.AnnotationTarget not found Warning:java: unknown enum constant kotlin.annotation.AnnotationTarget.FUNCTION Warning:java: unknown enum constant kotlin.annotation.AnnotationTarget.PROPERTY Warning:java: unknown enum constant kotlin.annotation.AnnotationTarget.CONSTRUCTOR Warning:java: unknown enum constant kotlin.annotation.AnnotationTarget.PROPERTY_GETTER Warning:java: unknown enum constant kotlin.annotation.AnnotationTarget.PROPERTY_SETTER Error:(74, 16) java: cannot access kotlin.jvm.functions.Function0 class file for kotlin.jvm.functions.Function0 not found

    I'm new to Kotlin / using kotlin in Java, not sure if I'm doing something wrong. Any guidance is greatly appreciated.

    I built the library using the ./gradlew buildJvm and added the jar files to my project library.

    As for using it in java: import koma.Koma; <-- this seems fine, no import errors

    double[][] distanceMatrix = function assigning value to distanceMatrix

    Matrix m = Koma.create(distanceMatrix); <-- this is where the Compilation Error happened

    opened by newbie-gk 1
  • Allow for dimensional pivoting for cases other than 2D transpose.

    Allow for dimensional pivoting for cases other than 2D transpose.

    Carryover issue from discussion in #83. Swapping dimension ordering is a useful operation outside of just matrices, and should probably have support in N-dimensional cases.

    opened by kyonifer 0
Owner
Kyle Kauffman
Kyle Kauffman
Math World is an Android Application specialized in mathematics, where the application includes some sections related to arithmetic, unit conversion, scientific math laws and constants, as well as some mathematical questions that need some intelligence to reach the solution.

Math World is an Android Application specialized in mathematics, where the application includes some sections related to arithmetic, unit conversion, scientific math laws and constants, as well as some mathematical questions that need some intelligence to reach the solution.

null 7 Mar 12, 2022
Project developed for monitoring hard braking zones as a scientific initiation at Facens in the period 2021/2022

@hard-braking-zones/location Project developed for monitoring hard braking zones as a scientific initiation at Facens in the period 2021/2022. Install

Caique Torres 2 Jan 25, 2022
QCalc - A lightweight semi-scientific calculator for Android

QCalc A lightweight semi-scientific calculator for Android. Written from scratch

Trent Lilley 0 Jan 27, 2022
A mobile application that contains up-to-date information about the latest earthquakes in Turkey, scientific explanations about earthquakes, and Turkey's earthquake map.

Recent-Earthquakes A mobile application that contains up-to-date information about the latest earthquakes in Turkey, scientific explanations about ear

Nisa Efendioğlu 3 Dec 5, 2022
Show worldwide headline. API/Glide library/recycler view/volley library/kotlin/xml/ chrome custom tabs

Show worldwide headline. API/Glide library/recycler view/volley library/kotlin/xml/ chrome custom tabs. -> you can click on headline and it will open an article of that news in the app(no need to go to chrome or any browser)

SUMIT KUMAR 5 Nov 28, 2022
A general purpose kotlin library that use kotlin coroutines, flows and channels to provide timer features with the most easy and efficient way

Timer Timer is a general purpose kotlin library that use kotlin coroutines, flows and channels to provide timer features with the most easy and effici

Amr Saraya 3 Jul 11, 2022
To Do List App is built in Kotlin using Material 3, Data Binding, Navigation Component Graphs, Room persistence library, Kotlin coroutines, LiveData, Dagger Hilt, and Notifications following MVVM Architecture.

ToDoListApp ToDoList App demonstrates modern Android development with Hilt, Coroutines, LiveData, Jetpack (Room, ViewModel), and Material 3 Design bas

Naman Garg 10 Jan 8, 2023
A music picker library for React Native. Provides access to the system's UI for selecting songs from the phone's music library.

Expo Music Picker A music picker library for React Native. Provides access to the system's UI for selecting songs from the phone's music library. Supp

Bartłomiej Klocek 60 Dec 29, 2022
Utility Android app for generating color palettes of images using the Palette library. Written in Kotlin.

Palette Helper is a simple utility app made to generate color palettes of images using Google's fantastic Palette library. It's mostly a for-fun pet p

Zac Sweers 154 Nov 18, 2022
Utility Android app for generating color palettes of images using the Palette library. Written in Kotlin.

Palette Helper is a simple utility app made to generate color palettes of images using Google's fantastic Palette library. It's mostly a for-fun pet p

Zac Sweers 154 Nov 18, 2022
An library to help android developers working easly with activities and fragments (Kotlin version)

AFM An library to help android developer working easly with activities and fragments (Kotlin) Motivation Accelerate the process and abstract the logic

Massive Disaster 12 Oct 3, 2022
This is a open source library on kotlin for Solana protocol.

Solana + RxSolana This is a open source library on kotlin for Solana protocol. The objective is to create a cross platform, fully functional, highly t

Arturo Jamaica 48 Jan 9, 2023
Kotlin Android app for cataloging books off home/office library.

MyLibrary App Kotlin Android app for cataloging books off home/office library. Features: Searching COBISS, Google Books and OpenLibrary by scanning IS

Marko Đorđević 0 Nov 29, 2021
Android Contacts API Library written in Kotlin with Java interoperability.

Android Contacts API Library written in Kotlin with Java interoperability. No more ContentProviders and cursors. Say goodbye to ContactsContract. Build your own contacts app!

Vandolf Estrellado 463 Jan 2, 2023
This little project provides Kotlin bindings for the popular tree-sitter library

kotlintree This little project provides Kotlin bindings for the popular tree-sitter library. Currently it only supports the Kotlin JVM target, but Kot

Christian Banse 23 Nov 28, 2022
Brazilian Holidays: a Kotlin/Java library that provides resources to consult Brazilian holidays and business days

Leia esta documentação em Português. Brazilian Holidays Brazilian Holidays is a

Quantis 2 Oct 3, 2022
Spantastic - an Android library that provides a simple and Kotlin fluent API for creating Android Spannable

Spantastic is an Android library that provides a simple and Kotlin fluent API for creating Android Spannable. This library wrappers SpannableStringBuilder and add methods to easily decorate the text with multiple spans.

Wellington Cabral da Silva 12 Nov 27, 2022
Open-source Kotlin library to connect Alsat pardakht peyment API (Core)

Alsat IPG Core با استفاده از این کتابخانه میتوانید پروژه جاوا یا کاتلین خودتون رو به شبکه پرداخت آل‌سات پرداخت وصل کنید و به راحتی محصولات خودتون رو د

Alsat Pardakht 4 Mar 14, 2022
A Kotlin/JVM based library for BitShares blockchain.

A Kotlin/JVM based library for BitShares blockchain. It implements most functions of BitShares Core including objects (de)serialization, transactions sign/broadcast, wallet create/restore, and more.

Husk 1 Apr 9, 2022