Comments (11)
Try
proc solve(A: [?Adom] ?eltType, ref b: [?bdom] eltType) {
var (LU, ipiv) = lu(A);
var y = permute (ipiv, b, true);
var z = solve_tril(LU, y);
var x = solve_triu(LU, z);
return x;
}
in LinearAlgebra. That will not affect the original parameter b
.
from chapel.
One could argue that the behavior be changed to not alter that input vector.
from chapel.
Echoing Scott, thanks for the assists here, Guiillaume and Damian! It sounds as though all here agree that it would be better for the routine not to modify the b
input argument, is that right? (or, if not, to at least document that it will be changed).
I think the way I'd achieve the "don't modify b
" would be to change its argument into to in
, which would give the routine a local copy of b
to play with if need be (or to steal the actual argument if it is dead after this), while documenting the potential for a copy. So:
proc solve(A: [?Adom] ?eltType, in b: [?bdom] eltType) {
var (LU, ipiv) = lu(A);
b = permute(ipiv, b, true);
var z = solve_tril(LU, b);
var x = solve_triu(LU, z);
return x;
}
from chapel.
As an aside, the approach taken by LinearAlgebra generally follows the style of MATLAB and does not overwrite the space used by matrix and vector parameters. This gobbles up memory, sometimes inordinately so if used without care.
The other approach is to overwrite space, i.e. the LU decomposition of A replaces A, the solution of Ax=b
is overwritten in b
, etc. If there is a need to keep a copy of the original data, that must be copied explicitly and saved elsewhere. This is a more fine grained approach. It avoids memory blowouts but requires slightly more work. This is the approach taken by tools such as LAPACK.
from chapel.
@sdbachman : Apart from the answer, the fact that B changed definitely seems suspect, right? [edit: Ah yes, you say so, right in the title. I focused in on the incorrect answer at first]. I'm noticing that it seems to have shifted by an element, which is odd, and suggests some sort of 0/1 indexing issue to me. What version of Chapel are you using? (I see this with both chpl version 1.34.0 pre-release (8371b2af80)
and chpl version 1.31.0
, so it seems this has been around for awhile).
I'm tagging @Guillaume-Helbecque on this, knowing that he worked on this routine recently, on the off-chance that he has any insights. (Otherwise, will take a look when it's not so late).
from chapel.
As far as I know, the changes of the input vector B
is the expected behaviour of the solve
procedure. More precisely, solve
computes an LU factorization of M
using partial pivoting, and for some reasons, the permutation is then applied to B
. I don't know what motivates this behaviour, but I agree that it is strange and would not be expected in practice.
For the wrong answer, I suspect an issue with the precision of floating-point numbers. Indeed, you expected 0.0 as first element of tmp
, but you get -8.83858e-11, which is essentially zero.
from chapel.
As Guillaume correctly notes, solve does in fact alter its original B
argument due to the pivoting strategy. Why this is exposed to the user, I do not know.
I see a slightly worse answer in the first element of the solution vector, -2.53552e-10 with the latest compiler. But, yes, that is the result of the underlying algorithm.. If you normalize the solution vector, the first element is just slightly more than 4 times the machine precision. So you have only lost 2 binary digits in accuracy which is extremely close to zero, again as correctly noted by Guillaume. A single pass of an enhanced precision iterative improvement might reduce that discrepancy
from chapel.
Thanks everyone! In my real code I was writing out B
as a sanity check, so you can imagine my stress when I was B
was changing after the Solve. It is good to confirm that this is expected behavior.
from chapel.
Scott, what error did you expect in your solution vector?
from chapel.
@sdbachman How do the following address this issue?
-
With #24294,
solve()
no longer modifies its actual arguments. -
The the last element of
tmp
in your test code is0
; the first element oftmp
is close to zero.
Can this issue be closed now?
from chapel.
@vasslitvinov : Thanks for the fix here! I'm going to assert that we're in better shape now w.r.t. this issue and close this, but Scott, please let us know if you find or think otherwise. Thanks for reporting the issue!
from chapel.
Related Issues (20)
- Allow users to specify comparators for `sort` with a first class procedure
- [Feature Request]: readLine(ref a: [], ...) to indicate reaching EOF
- [Feature Request]: allow to run specific tests from `mason test`
- Update Quick Reference doc to use `new blockDist()` HOT 3
- Make CHPL*_JEMALLOC setting(s) first-class / documented? HOT 8
- Remote-declared arrays and `forall` locality HOT 9
- Problems with running parallel operations within GPU kernels
- [Bug]: `make install` installs a `mason` with incorrect paths
- Should we have a global `CHPL_MEM` and `CHPL_JEMALLOC`? HOT 3
- [Feature Request]: Integrate `gpuSort` into `sort` HOT 1
- [Bug]: VarArgs formal with param number of elements causes internal error
- Wrong disambiguation with variadic arguments and generic type fields with defaults HOT 1
- [Bug]: No ambiguity between formals and nested procs of same name HOT 3
- Rank-change type checking is stricter than array indexing HOT 5
- [Bug]: libunwind seems to check pkg-config for paths even when using "bundled" HOT 12
- [Bug]: logical operators do not work on nilable classes
- [Bug]: `c_ptr` record field to the same record causes infinite recursion HOT 1
- Prepare and pursue Chapel's application to E4S
- Accessing elements of a tuple type field doesn't resolve
- Confusing error message for a syntax error(?) in distributed domain initialization HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from chapel.