Kotlin / multik

Multidimensional array library for Kotlin
https://kotlin.github.io/multik/
Apache License 2.0
633 stars 38 forks source link

Usage of unsupported type causes runtime error #177

Open fekazar opened 8 months ago

fekazar commented 8 months ago

The following code will compile, but cause the runtime error because inferred type is Number which is unsupported. val b = mk.ndarray(mk[1.0, 2]). Considering current library design, is it possible to move this check to compile time? Maybe numbers should be treated as Double?

devcrocod commented 8 months ago

The mk[...] construct is simply a list. While it's possible to convert the types to a common type, it's currently a substantial effort for a minor benefit. This is because we'd need to first determine the larger type and then convert the remaining types to it, all while optimizing the process. I already have a task on my plate to create a parser for external data reading. Once I add that, it should address and close this issue as well. It's worth considering whether this approach is the right choice at all. Since it exhibits non-intuitive behavior, users may be surprised by the high memory consumption.

And for now, I agree that it might be a good idea to add validation and throw a runtime exception