Comments (3)
IMO this is an API design issue in the linear algebra module.
Looking at proc inv
specifically:
proc inv(ref A: [?Adom] ?eltType, overwrite=false) where usingLAPACK { ... }
Here it seems that the LAPACK calls modify the array in-place. At some point in history, it might have been the case that if overwrite=true
, this routine would not return a copy of A
. However, today, it copies A
either way (with overwrite=false
, it does it with var A_clone = A;
and with overwrite=true
it does it with return A;
. So, I don't think the design of having overwrite
as an optional argument here is reasonable. It doesn't offer much benefit (in terms of reducing copying in some cases, at least) and it means that the function needs to accept A
with ref
intent (because it might mutate it).
Instead, I'd recommend that we change proc inv
(and any LinearAlgebra routine in a similar situation) into two routines with different names:
- A routine that never modifies the array passed in, always copies it and returns the new array (the result of inverting). E.g.
proc inv(const ref A:[]): A.type
. - Another routine that never returns anything and mutates the array in place to compute the inverse. E.g.
proc invInPlace(ref A:[])
.
from chapel.
I agree with Michael that there is an issue with the design of the API. I would go so far as as to say there is an issue with its use.
I am assuming that you are intending these routines for use in real applications, not just toy (or purely pedagogic) applications.
Most of the time, you won't need a copy. In those situations where you really do need a copy of the original matrix as well as the mutated one, or probably more precisely, a factored or transformed one,, you really need to make those copies blatantly obvious in the code, not hidden under the hood so you never know the real overhead!
As a user of LINPACK and now LAPACK for a long time, and having rewritten them in C and C++ for real world use, the default name should refer to modify in place. Having the reverse convention encourages very (very very) bad programming practices.
I regularly get given MATLAB code that gobbles up memory like it is going out of style because there are copies of arrays all over the place. It makes such codes impractical for production work. The bane of my life.
Memory is expensive (from numerous perspectives even if its dollar cost has dropped). Don't waste it on lazy programming practices.
That advice is worth a lot more than my usual 2c.
from chapel.
@redhatturtle - until we have a better API for inv
, your working variant is the same what used to happen in v1.31 under the covers for AtB_inv = inv(dot(A,B));
.
I would suggest a minor tweak to your solution: move the declaration of AtB_inv
to where it gets the output of inv(). This will ensure that AtB_inv takes over the outcome of inv():
var A, B : [1..n, 1..n] real;
var AtB = dot(A,B);
var AtB_inv = inv(AtB);
Cf. here the array produced by inv() is copied into the array AtB_inv then discarded:
var A, B, AtB_inv : [1..n, 1..n] real;
writeln(AtB_inv);
var AtB = dot(A,B);
AtB_inv = inv(AtB);
from chapel.
Related Issues (20)
- Missing deprecation warnings for converting `owned` to `shared`
- Internal error when building Chapel code with HIP module loaded HOT 7
- Apparent bug in readBinary() (for sufficiently large files? sufficiently large offsets within files? array slice reads?) HOT 3
- GPU: Initializers with promoted expressions don't get GPUized. HOT 3
- assertOnGpu fails when applied to `foreach` with custom iterator HOT 2
- Discussion on forall intents
- What to do with the empty regex initializer? HOT 4
- GPU Kernels in Standard Modules cause segfaults or internal errors
- Restore support for casting expressions to strings?
- forall reductions fail silently for GPU HOT 1
- dyno: incremental re-scope resolution causes recursive query when standard modules are enabled HOT 1
- Using `CHPL_GPU=cpu` with the gnu compiler gives an attribute warning HOT 3
- Stabilizing Associative Domains and Arrays HOT 1
- stdin/stdout/stderr store the dummy locale rather than locale 0 HOT 1
- Improve IO's bulk read/write performance when endianness is non-native HOT 2
- Clarify documentation around profiling based on user feedback HOT 1
- Add a note to the GPU technote about best practices for host profiling when using the GPU locale model HOT 3
- Add support for `-pg` to the LLVM back-end? HOT 1
- Capitalization / Naming of ioendian HOT 6
- Can Chapel code use a param to detect endianness?
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.