Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Publish as a Multiplatform Library #8

Closed
ccjernigan opened this issue Feb 22, 2021 · 8 comments · Fixed by #110
Closed

Publish as a Multiplatform Library #8

ccjernigan opened this issue Feb 22, 2021 · 8 comments · Fixed by #110
Milestone

Comments

@ccjernigan
Copy link

This is a feature request to publish Multik as a Kotlin Multiplatform library.

My use case is that I've developed a multiplatform application for processing a lot sensor data, and we're currently using some non-optimal home grown matrix operations. Being able to leverage Multik would be a great improvement, however I need to be able to consume it as a mutiplatform library.

Multik's "JVM" implementation is effectively multiplatform compatible already, with only one method touching the JVM class library (DataType.kt has one line using reflection which could be quickly removed).

This feature request mostly involves changes to how the library is published, as opposed to changes to the library code itself.

@devcrocod
Copy link
Collaborator

Multik's "JVM" implementation is effectively multiplatform compatible already, with only one method touching the JVM class library (DataType.kt has one line using reflection which could be quickly removed).

Do you mean KClass in DataType.kt?

This feature request mostly involves changes to how the library is published, as opposed to changes to the library code itself.

If the problem is reflection, then it is just necessary to remove the dependency. Could you tell me in more detail, maybe I misunderstood.

Could you tell us what operations you use in your application? Multik lacks a lot of matrix operations, we are working on adding and supporting new operations. Therefore, understanding the priority will help us.

@ccjernigan
Copy link
Author

ccjernigan commented Feb 25, 2021

I was able to copy multik-api/src and multik-jvm/src into my project under src/commonMain. It compiled with a 1-line change, removing type.jvmName from this exception message
else -> throw IllegalStateException("One of the primitive types was expected, got ${type.jvmName}")

else -> throw IllegalStateException("One of the primitive types was expected, got ${type.jvmName}")

With that removed, multik-api and multik-jvm are effectively compatible to be published as Kotlin Multiplatform libraries. After removing that one line, the remaining step would be changing the gradle build scripts to apply the multiplatform plugin and moving the code to commonMain.

The specific multik APIs I use aren't super relevant, as my feature request is just to publish as multiplatform which is 99.9% of the way there. Although I can still get back to you on those for general feedback purposes.

@luca992
Copy link
Contributor

luca992 commented Apr 25, 2021

@occultus73 #20 just converted multik-api, multik-jvm, multik-default to use the multiplatform plugin and added native targets for multik-jvm!

@occultus73
Copy link

@occultus73 #20 just converted multik-api, multik-jvm, multik-default to use the multiplatform plugin and added native targets for multik-jvm!

Nice man. I will try it out next week when I'm back from holiday. To implement in my codebase I will also need support for JavaScript targets. I had a little trouble with number types getting js to work. The problem is if you ask JavaScript whether a number is a byte, or an int or a float or whatever, it will just say "yes" indiscriminately. As you know, there's when statements in multik that do this, and byte is the first in the list. So all numbers where being truncated to Byte values. Not good! My project only used double matrices, so I just pushed "is Double" to the top of the when clauses, and fixed the problem.

@luca992
Copy link
Contributor

luca992 commented Apr 27, 2021

@occultus73 haven't done much with targeting js so didn't try that out. Are there existing test cases that would fail when multik targets js?

@occultus73
Copy link

@occultus73 haven't done much with targeting js so didn't try that out. Are there existing test cases that would fail when multik targets js?

I never actually ported the unit tests in anticipation that I wouldn't have to maintain the code long term like I would with Apache math. Relying on you man! But yes more than a few would almost certainly fail for the reason I described.

@luca992
Copy link
Contributor

luca992 commented Sep 28, 2021

@occultus73 #20 just converted multik-api, multik-jvm, multik-default to use the multiplatform plugin and added native targets for multik-jvm!

Nice man. I will try it out next week when I'm back from holiday. To implement in my codebase I will also need support for JavaScript targets. I had a little trouble with number types getting js to work. The problem is if you ask JavaScript whether a number is a byte, or an int or a float or whatever, it will just say "yes" indiscriminately. As you know, there's when statements in multik that do this, and byte is the first in the list. So all numbers where being truncated to Byte values. Not good! My project only used double matrices, so I just pushed "is Double" to the top of the when clauses, and fixed the problem.

Js with fixes for this issue is now included in my multiplatform pr #20 now btw

@occultus73
Copy link

Awesome man. Look forward to this being merged and released. If JetBrains wants to make multiplatform a success they need their incubated libraries to jump on the train 🚂.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants