JuliaLinearAlgebra / NonNegLeastSquares.jl

Some nonnegative least squares solvers in Julia
MIT License
46 stars 11 forks source link

Different results shape in single process vs distributed #34

Closed aplavin closed 3 months ago

aplavin commented 2 years ago

When Distributed.nprocs() == 1:

julia> nonneg_lsq([1.0;;], [1.])
1×1 Matrix{Float64}:
 1.0

When Distributed.nprocs() > 1:

julia> nonneg_lsq([1.0;;], [1.])
1-element Vector{Float64}:
 1.0

Seems like this is caused by https://github.com/ahwillia/NonNegLeastSquares.jl/blob/2c932bb7cee975db31258555596481aa24351ee8/src/pivot.jl#L97-L106, but not sure how to cleanly fix those lines.

JeffFessler commented 2 years ago

Looks like @distributed with hcat has inconsistent output when 1:k is a singleton:

using Distributed
@distributed (hcat) for i in 1:1; 2i; end
2

@distributed (hcat) for i in 1:3; 2i; end
1×3 Matrix{Int64}:
2  4  6

Seems like a flaw in @distributed to me because hcat(2) returns a 1 by 1 array so is self consistent. Before line 101, perhaps just add X = reshape(X, n, k) at least for k=1 case.