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

[BUG] Incorrect Behavior in FSharp.Stats.SpecializedGenericImpl.setColM for Non-Square Matrices #315

Closed LibraChris closed 4 months ago

LibraChris commented 4 months ago

Bug Description:

The FSharp.Stats.SpecializedGenericImpl.setColM function encounters an issue with non-square matrices. This is because it incorrectly checks column counts instead of row counts, leading to failure. You can see the problematic line here.

Furthermore, the tests in this section are only designed for square matrices and use Matrix.setRow instead of Matrix.setCol.

Steps to Reproduce:

  1. Run the provided code snippet:
#r "nuget: FSharp.Stats, 0.5.1-preview.1"
open FSharp.Stats

let testMatrix = 
    [|
        [|2.;3.|]
        [|2.;4.|]
        [|1.;1.|]
    |]
    |> Matrix.ofJaggedArray 

Matrix.setCol testMatrix 0 ([0.;0.;0.] |> Vector.ofList)

Expected Outcome:

The specified column insertion should succeed regardless of the column count, ensuring independence from the matrix's column count.