Skip to content

Possible bug in outerProduct #28

@dsyme

Description

@dsyme

From #17

Potential Bug: outerProduct Implementation Incomplete
Location: src/FsMath/SpanMath.fs:338-353

Issue: The outerProduct function only implements the SIMD path and doesn't have fallback logic for remaining elements:

for i = 0 to rows - 1 do
    let ui = u[i]
    for j = 0 to cols - 1 do
        // Only SIMD path implemented - no fallback for j loop!
        for k = 0 to simdCount - 1 do
            let vi = Numerics.Vector<'T>(ui)
            let res = vi * vVec[k]
            res.CopyTo(MemoryMarshal.CreateSpan(&data.[i * cols + k * simdCols], simdCols))

Impact: For vectors smaller than SIMD width, or for remaining elements after SIMD processing, the function returns zeros instead of computing the actual outer product.

Example: outerProduct([1.0; 2.0], [3.0; 4.0; 5.0]) returns all zeros instead of the expected [3, 4, 5, 6, 8, 10].

Recommendation: Add a fallback loop to handle elements not processed by SIMD:

// After SIMD loop
for j = ceiling to cols - 1 do
    data.[i * cols + j] <- ui * v.[j]
Tests for outerProduct were intentionally omitted from this PR to avoid failing tests on existing bugs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions