https://kotlinlang.org logo
Join the conversationJoin Slack
Channels
100daysofcode
100daysofkotlin
100daysofkotlin-2021
advent-of-code
aem
ai
alexa
algeria
algolialibraries
amsterdam
android
android-architecture
android-databinding
android-studio
androidgithubprojects
androidthings
androidx
androidx-xprocessing
anime
anko
announcements
apollo-kotlin
appintro
arabic
argentina
arkenv
arksemdevteam
armenia
arrow
arrow-contributors
arrow-meta
ass
atlanta
atm17
atrium
austin
australia
austria
awesome-kotlin
ballast
bangladesh
barcelona
bayarea
bazel
beepiz-libraries
belgium
berlin
big-data
books
boston
brazil
brikk
budapest
build
build-tools
bulgaria
bydgoszcz
cambodia
canada
carrat
carrat-dev
carrat-feed
chicago
chile
china
chucker
cincinnati-user-group
cli
clikt
cloudfoundry
cn
cobalt
code-coverage
codeforces
codemash-precompiler
codereview
codingame
codingconventions
coimbatore
collaborations
colombia
colorado
communities
competitive-programming
competitivecoding
compiler
compose
compose-android
compose-desktop
compose-hiring
compose-ios
compose-mp
compose-ui-showcase
compose-wear
compose-web
connect-audit-events
corda
cork
coroutines
couchbase
coursera
croatia
cryptography
cscenter-course-2016
cucumber-bdd
cyprus
czech
dagger
data2viz
databinding
datascience
dckotlin
debugging
decompose
decouple
denmark
deprecated
detekt
detekt-hint
dev-core
dfw
docs-revamped
dokka
domain-driven-design
doodle
dsl
dublin
dutch
eap
eclipse
ecuador
edinburgh
education
effective-kotlin
effectivekotlin
emacs
embedded-kotlin
estatik
event21-community-content
events
exposed
failgood
fb-internal-demo
feed
firebase
flow
fluid-libraries
forkhandles
forum
fosdem
fp-in-kotlin
framework-elide
freenode
french
fritz2
fuchsia
functional
funktionale
gamedev
ge-kotlin
general-advice
georgia
geospatial
german-lang
getting-started
github-workflows-kt
glance
godot-kotlin
google-io
gradle
graphic
graphkool
graphql
graphql-kotlin
graviton-browser
greece
grpc
gsoc
gui
hackathons
hacktoberfest
hamburg
hamkrest
helios
helsinki
hexagon
hibernate
hikari-cp
hire-me
hiring
hongkong
hoplite
http4k
hungary
hyderabad
image-processing
india
indonesia
inkremental
intellij
intellij-plugins
intellij-tricks
internships
introduce-yourself
io
ios
iran
israel
istanbulcoders
italian
jackson-kotlin
jadx
japanese
jasync-sql
java-to-kotlin-refactoring
javadevelopers
javafx
javalin
javascript
jdbi
jhipster-kotlin
jobsworldwide
jpa
jshdq
juul-libraries
jvm-ir-backend-feedback
jxadapter
k2-early-adopters
kaal
kafka
kakao
kalasim
kapt
karachi
karg
karlsruhe
kash_shell
kaskade
kbuild
kdbc
kgen-doc-tools
kgraphql
kinta
klaxon
klock
kloudformation
kmdc
kmm-español
kmongo
knbt
knote
koalaql
koans
kobalt
kobweb
kodein
kodex
kohesive
koin
koin-dev
komapper
kondor-json
kong
kontent
kontributors
korau
korean
korge
korim
korio
korlibs
korte
kotest
kotest-contributors
kotless
kotlick
kotlin-asia
kotlin-beam
kotlin-by-example
kotlin-csv
kotlin-data-storage
kotlin-foundation
kotlin-fuel
kotlin-in-action
kotlin-inject
kotlin-latam
kotlin-logging
kotlin-multiplatform-contest
kotlin-mumbai
kotlin-native
kotlin-pakistan
kotlin-plugin
kotlin-pune
kotlin-roadmap
kotlin-samples
kotlin-sap
kotlin-serbia
kotlin-spark
kotlin-szeged
kotlin-website
kotlinacademy
kotlinbot
kotlinconf
kotlindl
kotlinforbeginners
kotlingforbeginners
kotlinlondon
kotlinmad
kotlinprogrammers
kotlinsu
kotlintest
kotlintest-devs
kotlintlv
kotlinultimatechallenge
kotlinx-datetime
kotlinx-files
kotlinx-html
kotrix
kotson
kovenant
kprompt
kraph
krawler
kroto-plus
ksp
ktcc
ktfmt
ktlint
ktor
ktp
kubed
kug-leads
kug-torino
kvision
kweb
lambdaworld_cadiz
lanark
language-evolution
language-proposals
latvia
leakcanary
leedskotlinusergroup
lets-have-fun
libgdx
libkgd
library-development
linkeddata
lithuania
london
losangeles
lottie
love
lychee
macedonia
machinelearningbawas
madrid
malaysia
mathematics
meetkotlin
memes
meta
metro-detroit
mexico
miami
micronaut
minnesota
minutest
mirror
mockk
moko
moldova
monsterpuzzle
montreal
moonbean
morocco
motionlayout
mpapt
mu
multiplatform
mumbai
munich
mvikotlin
mvrx
myndocs-oauth2-server
naming
navigation-architecture-component
nepal
new-mexico
new-zealand
newname
nigeria
nodejs
norway
npm-publish
nyc
oceania
ohio-kotlin-users
oldenburg
oolong
opensource
orbit-mvi
osgi
otpisani
package-search
pakistan
panamá
pattern-matching
pbandk
pdx
peru
philippines
phoenix
pinoy
pocketgitclient
polish
popkorn
portugal
practical-functional-programming
proguard
prozis-android-backup
pyhsikal
python
python-contributors
quasar
random
re
react
reaktive
realm
realworldkotlin
reductor
reduks
redux
redux-kotlin
refactoring-to-kotlin
reflect
refreshversions
reports
result
rethink
revolver
rhein-main
rocksdb
romania
room
rpi-pico
rsocket
russian
russian_feed
russian-kotlinasfirst
rx
rxjava
san-diego
science
scotland
scrcast
scrimage
script
scripting
seattle
serialization
server
sg-user-group
singapore
skia-wasm-interop-temp
skrape-it
slovak
snake
sofl-user-group
southafrica
spacemacs
spain
spanish
speaking
spek
spin
splitties
spotify-mobius
spring
spring-security
squarelibraries
stackoverflow
stacks
stayhungrystayfoolish
stdlib
stlouis
strife-discord-lib
strikt
students
stuttgart
sudan
swagger-gradle-codegen
swarm
sweden
swing
swiss-user-group
switzerland
talking-kotlin
tallinn
tampa
teamcity
tegal
tempe
tensorflow
terminal
test
testing
testtestest
texas
tgbotapi
thailand
tornadofx
touchlab-tools
training
tricity-kotlin-user-group
trójmiasto
truth
tunisia
turkey
turkiye
twitter-feed
uae
udacityindia
uk
ukrainian
uniflow
unkonf
uruguay
utah
uuid
vancouver
vankotlin
vertx
videos
vienna
vietnam
vim
vkug
vuejs
web-mpp
webassembly
webrtc
wimix_sentry
wwdc
zircon
Powered by Linen
mathematics
  • t

    thomasnield

    12/01/2021, 3:47 AM
    Hey all, sorry I've gone dark for awhile. I've been juggling a lot of stuff, all good. I might have a Kotlin differential programming project headed my way with a client. If it goes through I'll be plugging back in shortly.
    a
    • 2
    • 2
  • a

    Alexandre Brown

    12/03/2021, 3:09 AM
    1.Could someone help me figure out the differences between KMath and MultiK ? 2.When should we use one over the other ?Should we use both ? What if we're interested in tensors manipulation ? 3. Are they both still being developed?
    a
    z
    • 3
    • 8
  • a

    altavir

    01/19/2022, 8:03 AM
    I plan to repeat my talk about Math architecture (and difference between KMath approach and Multik as well) from Joker in English. Is January 28 15:00 CET OK for everyone interested?
    :kotlin-intensifies: 2
    i
    j
    • 3
    • 11
  • g

    George Pandian

    01/21/2022, 12:03 PM
    Why can't I see it the other way around as the relationship is from co domain to domain and use the same above understanding and say Oh I see a function ? Basically relationship identified across sers be it domian -> co domain Or co domain -> domain Then I can map it with directions as in Graph Theory style with a function definition above the directed relationship identified ?
    i
    • 2
    • 6
  • p

    Peter

    02/08/2022, 12:35 PM
    Does anyone know why Kotlin BigDecimal div operator decided to use the scaling of the nominator and behave different from the equivalent Java implementation?
    import java.math.BigDecimal
    
    val x = BigDecimal("127.0")
    val y = BigDecimal("50")
    
    println(x / y)  // 2.5 unexpected
    println(x.divide(y)) // 2.54 what I expected
    Took me while to figure out why what was going on in my code and I cannot see many cases where this is the desired behaviour. Would rather have the div operator just calling the divide method.
    a
    r
    • 3
    • 4
  • s

    Slackbot

    02/14/2022, 9:18 AM
    This message was deleted.
    z
    a
    • 3
    • 7
  • a

    altavir

    02/18/2022, 8:58 AM
    Latest matrix dot (1000 x 1000 matrices) benchmark results for different KMath algebras (after tensor algebra fix by @Ivan Kylchik:
    jvm summary:
    Benchmark                            Mode  Cnt   Score   Error  Units
    DotBenchmark.bufferedDot            thrpt    5   1.017 ± 0.399  ops/s
    DotBenchmark.cmDot                  thrpt    5   0.589 ± 0.348  ops/s
    DotBenchmark.cmDotWithConversion    thrpt    5   0.627 ± 0.395  ops/s
    DotBenchmark.doubleDot              thrpt    5   1.168 ± 0.125  ops/s
    DotBenchmark.doubleTensorDot        thrpt    5   1.263 ± 0.235  ops/s
    DotBenchmark.ejmlDot                thrpt    5   2.573 ± 0.427  ops/s
    DotBenchmark.ejmlDotWithConversion  thrpt    5   2.332 ± 0.239  ops/s
    DotBenchmark.multikDot              thrpt    5  16.067 ± 0.959  ops/s
    DotBenchmark.tensorDot              thrpt    5   0.614 ± 0.053  ops/s
    DotBenchmark.tfDot                  thrpt    5   3.905 ± 0.541  ops/s
    Multik result (cc @Pavel Gorgulov) is a bit surprising. I did not expect it to be much faster than TensorFlow. KMath-core results are good enough for default implementation.
    🙌 4
    a
    • 2
    • 5
  • a

    altavir

    04/12/2022, 9:44 AM
    https://twitter.com/noraltavir/status/1513815121138700288?s=20&t=FIAC3f7nxzeZUEzusU3ucQ
    🤘 1
    🤔 1
    🎉 6
    h
    • 2
    • 6
  • a

    Alexandre Brown

    05/04/2022, 10:53 AM
    Is it possible to use KMaths for deep learning inference on Native (I think KMaths is multiplatform right?)? (Eg: via ONNX model)
    a
    i
    • 3
    • 9
  • a

    Alexandre Brown

    05/12/2022, 3:03 AM
    Hello just wondering, does KMath have a function to compute the area of the intersection between two rectangles ?
    i
    a
    • 3
    • 4
  • m

    Muhammet Emin Gündoğar

    05/25/2022, 6:45 PM
    fun Int.floorEven() = this and 0x01.inv()
    I was reading a project and i saw this code but i could not understand why this code flooring the number to even i know 01 inverse equals to -2 because of 2's complement equals to 1's complement - 1 and 2 complent is negative of that number but i could not understand why this code will always work?
    i
    • 2
    • 1
  • b

    Big Chungus

    06/07/2022, 4:42 PM
    Does anyone know if multik has something like np.roll() for d2Array?
    p
    a
    • 3
    • 16
  • b

    Big Chungus

    06/07/2022, 8:22 PM
    Does anyone have a handy link for 3d <> 1d array index conversions? Google only surfaces the common 2d<>1d... I basically need to get x,y,z coordinates from a given 1d array index
    a
    • 2
    • 4
  • b

    Big Chungus

    06/10/2022, 12:02 PM
    Anyone here familiar with OpenCV Java and would be willing to answer a few questions about Dnn and Mat? The docs for java are pretty much non-existent and the API differs quite a lot in some places from Python...
    a
    r
    • 3
    • 3
  • a

    altavir

    06/17/2022, 3:00 PM
    Does anybody want earth coordinate transformation? I've added them because people asked me but I wonder if there are specific features people need? For example distance computations?
    a
    e
    • 3
    • 3
  • a

    altavir

    06/17/2022, 7:53 PM
    @ESchouten By the way, a team in our centre is currently working on enhancement of Dubins algorithm. They are doing it in Python, but probably it would be interesting to have it in Kotlin. Would you be interesting to include your implementation in KMath-geometry, or it is better to have it in a separate package?
    e
    • 2
    • 7
  • s

    Sam Stone

    06/23/2022, 3:53 AM
    Ideomatic way to get the closest multiple of .5 to a given float? E.g.
    closest(1.03)=1.05
    ,
    closest(1.02)=1.00
    ,
    closest(1.05)=1.05
    a
    g
    • 3
    • 4
  • s

    Sam Stone

    07/04/2022, 8:34 PM
    How do you get the fractional part of a double?
    g
    • 2
    • 7
  • a

    altavir

    07/08/2022, 8:29 AM
    @Gleb Minaev I've started to do a review on your PR. It is too large to be in
    functions
    module (it is intended to be lightweight). Could you create a separate module like
    kmath-rational
    and move all but basic polynomials there?
    g
    • 2
    • 11
  • d

    David Boney

    07/12/2022, 5:34 PM
    Meta just open-sourced an automatic differentiation framework for Kotlin! (https://diffkt.org/). It can compute higher-order and symbolic derivatives, supports user-defined types, and has compile-time shape checking. Examples include machine learning and physical simulations.
    a
    • 2
    • 10
  • s

    Slackbot

    07/12/2022, 6:50 PM
    This message was deleted.
  • a

    altavir

    07/16/2022, 8:34 AM
    Inspired by Facebook, I finally finished refactoring of @Iaroslav Postovalov’s PR on generic autodiff in KMath. It is merged into
    dev
    and yes, it can work with tensors and allows custom operators: https://github.com/mipt-npm/kmath/blob/dev/kmath-core/src/commonTest/kotlin/space/kscience/kmath/expressions/DerivativeStructureExpressionTest.kt. Documentation is not ready yet, but any feedback would be welcome. The difference from Facebook implementation is that operations themselves (including performance optimization) are decoupled from the autodiff algorithm. So you can for example use Multik native implementation with the autodif engine.
    :cool-doge: 1
  • s

    Stumpos

    07/20/2022, 5:55 PM
    To add to the automatic differentiation implementations, https://github.com/facebookresearch/optimizer-plugins is also now open source
    🎉 1
    a
    • 2
    • 4
  • a

    altavir

    07/24/2022, 9:05 AM
    @ESchouten thanks for the contribution. It is finally merged. I want to do some post-merge changes. Mostly related to computation of the "costs" of path. We have cases, where it is not "path length", but some value that depends on the specific point. So it will be some kind of visitor. Also I will probably change structure somewhat to better conform to the other code. Meanwhile, you can check the complementary project: https://github.com/mipt-npm/maps-kt. It allows (or will allow) to visualize the path on maps and schemes.
    e
    • 2
    • 7
  • p

    Pavel Gorgulov

    07/29/2022, 10:25 AM
    message has been deleted
    i
    • 2
    • 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.
    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
Powered by Linen
Title
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?
Intellij even suggests me to change the expression
0.42.rem(0.14) == 0.0
to
false
but
0.28.rem(0.14) == 0.0
is
true
a

andylamax

11/04/2022, 2:37 PM
floating point arithmetics 😔
a

altavir

11/04/2022, 2:39 PM
It is called https://en.wikipedia.org/wiki/IEEE_754. The only way to avoid it is to use BigDecimal.
n

nino

11/04/2022, 4:14 PM
BigDecimal(0.42).rem(BigDecimal(0.14))
doesn't solve the problem
a

altavir

11/04/2022, 4:25 PM
Because it uses limited MathContext by default. It could be done, but I need to remember how. In general, you can't check equality of floating point numbers, the correct way is to do it like this:
require( abs(0.42.rem(0.14)) < 1e-4))
You can add an extension to do that
https://pl.kotl.in/qOAIWX6XZ here is how it looks with BigDecimal. But it is not recommended.
n

nino

11/04/2022, 6:49 PM
both solutions work. Thanks!
I still don't understand why
0.28.rem(0.14) == 0.0
is true though
and also
0.56.rem(0.14) == 0.0
a

altavir

11/04/2022, 7:43 PM
I think it is the problem of the latest bit flip. The problem is that due to floating precision 0.42 is slightly smaller than 3*0.14 so you get almost 0.14 as a reminder.
println(0.42 >= 3*0.14)
it is false
n

nino

11/04/2022, 10:43 PM
thanks @altavir
a

Andrew

11/16/2022, 6:12 PM
BigDecimal works but you need to use the string or .valueOf constructor to avoid any floating point issues
BigDecimal.valueOf(0.42).rem(BigDecimal.valueOf(0.14))
View count: 1