Skip to content

Add float array operations across JVM (SIMD), JS, and Native platforms#66

Merged
Quafadas merged 3 commits intomainfrom
copilot/add-float-operations-support
Apr 4, 2026
Merged

Add float array operations across JVM (SIMD), JS, and Native platforms#66
Quafadas merged 3 commits intomainfrom
copilot/add-float-operations-support

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 4, 2026

Implements Array[Float] extension methods mirroring the existing Array[Double] API across all three platforms, with platform-optimised implementations.

New files

  • src/floatarray.scalaFloatArrays object: select, unique, argsort
  • src-js-native/floatarray.scalaJsNativeFloatArrays: while-loop implementations shared between JS and Native (clamping, math unary ops with ! in-place variants, element-wise ops, comparisons, outer, logSumExp, productExceptSelf, cumsum, increments, etc.)
  • test/src/floatarray.test.scala — 54 cross-platform float tests

Platform implementations

  • JVM (src-jvm/arrays.scala): FloatVector.SPECIES_PREFERRED SIMD via jdk.incubator.vector for arithmetic, math ops, reductions, comparisons, and statistics
  • Native (src-native/array.scala): BLAS single-precision routines — cblas_saxpy (+=/−=), cblas_sdot (dot), cblas_snrm2 (norm), cblas_sscal (∗=/÷=)
  • JS (src-js/array.scala): while-loop implementations for arithmetic, statistics, and linear algebra

Operations covered

All the standard ops from the double API: scalar and array arithmetic (+, -, *, /, in-place variants), math unary ops (exp, log, sqrt, sin, cos, tan, abs, …), dot, norm, mean, variance, std, cumsum, clamp*, argmax/argmin, outer, logSumExp, pearsonCorrelationCoefficient, spearmansRankCorrelation, covariance, elementRanks, fma, **.

import vecxt.all.*

val v1 = Array[Float](1f, 2f, 3f, 4f, 5f)
val v2 = Array[Float](5f, 4f, 3f, 2f, 1f)

v1.dot(v2)                          // Float: 35.0
v1.norm                             // Float: ~7.416
v1.mean                             // Float: 3.0
v1.exp                              // Array[Float]
v1.clamp(2f, 4f)                    // Array[Float](2,2,3,4,4)
v1.pearsonCorrelationCoefficient(v2) // Float: -1.0
v1 * v2                             // Array[Float](5,8,9,8,5)

Also exports FloatArrays.* from all.scala and adds Array[Float] overloads to dimCheck on JS.

Copilot AI linked an issue Apr 4, 2026 that may be closed by this pull request
Copilot AI and others added 2 commits April 4, 2026 10:49
Copilot AI changed the title [WIP] Add float operations similar to double methods Add float array operations across JVM (SIMD), JS, and Native platforms Apr 4, 2026
Copilot AI requested a review from Quafadas April 4, 2026 10:53
@Quafadas Quafadas marked this pull request as ready for review April 4, 2026 11:17
@Quafadas Quafadas merged commit 8f2add5 into main Apr 4, 2026
7 checks passed
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 this pull request may close these issues.

Float operations

2 participants