Replies: 7 comments 14 replies
-
Just copy/paste here some comments I've exchanged with German by chat: If we do a copy we need to warn the user. It's really critical in a general case. and the m2.factorize() and m2.solve() design is not really what we tend to do, at least on a daily C++ context, where we prefer to specialize small objects instead of having big objects with everything inside. That's a bit orthogonal with the componentization goal. a 10.000 x 10.000 dense matrix is already 800Mb Memory allocations is one of the most critical point we see with big customers (who are running very big models). We try to save every Gb of memory we can. These solves can require several Tb of RAM these days. |
Beta Was this translation helpful? Give feedback.
-
Copying is something the user should opt into, as it is one of the most expensive operations you can do. I do not think an option to copy is necessary, the user should be able to copy it themselves before calling factorize if that is what they want. The function should document clearly what it does, so there's no surprise there. @FredAns it is not clear to me what the |
Beta Was this translation helpful? Give feedback.
-
CHANGED THE DISCUSSION BODY |
Beta Was this translation helpful? Give feedback.
-
I would personally go for both proposed solutions; implement I believe the current implementation is prone to confusion. |
Beta Was this translation helpful? Give feedback.
-
Hi @germa89 it makes more sense to me to keep the behavior; unless we have really good documentation that highlights the difference in this and the straight APDL. In either case I'm no fan of a default copy being made. I'm not sure of the 1 TB sized models that @FredAns is talking about (that's a big model!). But ~100 GB is pretty standard these days for just the run-of-the-mill medium sized models. See those all the time. |
Beta Was this translation helpful? Give feedback.
-
It seems there is consensus on keep the default behavior, add a copy option and improve docs. |
Beta Was this translation helpful? Give feedback.
-
I personally don't feel a copy option is necessary |
Beta Was this translation helpful? Give feedback.
-
Trying to fix a unit test in the math module, I realized that the assert done on the
m2
fail.As @FredAns told me it seems that
mm.factorize
does changem2
, which in my opinion doesn't make sense if we are returning an object (solver
in this case).Explaining it with code
Current implementation
As we saw in the example above, the method
factorize
return an objectSolver
which we can use it to solve the linear system (A*x=B
).However, this method also change the matrix
m2
, meaning that if you try to usem2
to solve a linear system using Numpy for example, you won't get the right answer (That is why the first assertion fail).I believe this is not reasonable, if we use
m2
as an argument of a function (mm.factorize
) and it does return an object, to me the changes inm2
are not obvious.Solutions
factorize
feature as a method ofm2
like:I think this way, it is more obvious that the changes are affecting
m2
.It might be an issue changing object nature on
m2
because solving in implemented onAnsSolver
class, andm2
is anAnsMat
, but both are derived fromApdlMathObj
.m2
matrix, and perform factorization on this copy. Then you could do something like this:Assuming the object
Solver
is intrinsically different (not only different in the class definition) than the factorized version of m2, it will generate a copy ofm2
which will be deleted once the function has finished. Hence this is not very performant compared with the above one. However, this is the type of notation or way of working someone would expect in Numpy.Pinging @akaszynski @koubaa @mikerife @FredAns
2 votes ·
Beta Was this translation helpful? Give feedback.
All reactions