fslaborg / FSharp.Stats

statistical testing, linear algebra, machine learning, fitting and signal processing in F#
https://fslab.org/FSharp.Stats/
Other
205 stars 54 forks source link

`JaggedCollection.transpose` results in wrong result when applied to rows of varying length #319

Closed bvenn closed 3 months ago

bvenn commented 3 months ago

Transpose operations as in JaggedArray.transpose and JaggedList.transpose should be applied to collections of equal length. When collections exist, that are longer than the first one, they get truncated:

let a = [|
    [|1; 2; 3|]
    [|1; 2; 3; 4|]
    |]

JaggedArray.transpose a
//[| [|1; 1|]; [|2; 2|]; [|3; 3|]|]

When the first element is the longest, an error is thrown:

let a2 = [|
    [|1; 2; 3; 4|]
    [|1; 2; 3|]
    |]

JaggedArray.transpose a2
//throws: System.IndexOutOfRangeException: Index was outside the bounds of the array.

The following additions should be made