Skip to content

Reduce overload explosion in constructors.kt #323

Description

@devcrocod

multik-core/src/commonMain/kotlin/org/jetbrains/kotlinx/multik/api/constructors.kt has grown to ~1600 lines with ~110 public functions. Most of them are mechanical variations of ndarray(...) over dimension (D1–D4), primitive type, input container (List / Array / Collection), and Number vs Complex.

Problems

  • Heavy duplication — every new variation multiplies across all axes.
  • @JvmName("ndarrayComplex") disambiguation is not discoverable from the API.
  • Known perf issue: // TODO: boxing/unboxing!!! Find all usages at line 449.
  • Maintenance cost: adding one new input shape requires touching dozens of overloads.

Suggested direction

  • Generate type-specific overloads (template-based, similar to stdlib _Arrays.kt, or KSP).
  • Shrink the public surface to a small set of canonical constructors (primitive array + shape) and derive the rest.
  • Fix the boxing path flagged by the TODO while reworking the layout.

Metadata

Metadata

Assignees

No one assigned

    Labels

    refactorInternal code improvements (no behavior change)

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions