Skip to content

Commit

Permalink
fixes issue #62. Output was not allocated correctly.
Browse files Browse the repository at this point in the history
  • Loading branch information
ViralBShah committed Jun 19, 2011
1 parent 83ec761 commit d5abe85
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions j/linalg_lapack.j
Original file line number Diff line number Diff line change
Expand Up @@ -334,21 +334,29 @@ macro lapack_backslash(fname_lu, fname_chol, fname_lsq, fname_tri, eltype)
# Workspace query
lwork = -1
work = [0.0]
Y = Array($eltype, max(m,n), nrhs)
Y[1:size(X,1), 1:size(X,2)] = X

ccall(dlsym(libLAPACK, $fname_lsq),
Void,
(Ptr{Uint8}, Ptr{Int32}, Ptr{Int32}, Ptr{Int32}, Ptr{$eltype}, Ptr{Int32},
Ptr{$eltype}, Ptr{Int32}, Ptr{$eltype}, Ptr{Int32}, Ptr{Int32}),
"N", m, n, nrhs, Acopy, m, X, max(m,n), work, lwork, info)
"N", m, n, nrhs, Acopy, m, Y, max(m,n), work, lwork, info)

if info[1] == 0; lwork = int32(work[1]); work = Array($eltype, lwork);
else error("Error in ", $fname_lsq); end
if info[1] == 0
lwork = int32(work[1])
work = Array($eltype, lwork)
else
error("Error in ", $fname_lsq)
end

ccall(dlsym(libLAPACK, $fname_lsq),
Void,
(Ptr{Uint8}, Ptr{Int32}, Ptr{Int32}, Ptr{Int32}, Ptr{$eltype}, Ptr{Int32},
Ptr{$eltype}, Ptr{Int32}, Ptr{$eltype}, Ptr{Int32}, Ptr{Int32}),
"N", m, n, nrhs, Acopy, m, X, max(m,n), work, lwork, info)
"N", m, n, nrhs, Acopy, m, Y, max(m,n), work, lwork, info)

X = Y
end # if m == n...

if info[1] == 0; return X; end
Expand Down

0 comments on commit d5abe85

Please sign in to comment.