![]() ![]() with some kind of AbstractODESolutionVector<:AbstractODESolution). Building on this first example: for a scalar ode y' = 0 + g(t) where g is a polynomial the solution will be polynomial an could in fact be represented by a polynomial type if it were advantageous to do so.Īs far as I can tell removing the constraint doesn't cost anything, since it can always be put back in later (e.g. For a first example, in cases where an exact solution is known as a function of time it might be more useful to have a callable type that can return the known solution at arbitrary times. Having solutions types is useful not just for the issue here but could also reflect the fact that ODEs can have "special" solutions in certain cases (for example for particular initial or final conditions it might be easy to find the solution).īut with respect to this issue, there could be a benefit in dropping the AbstractVector constraint to allow for more general behavior. If not, then state your rule(s) for getting each row of your desired output vector. This isn't unique for this approach, though if we decide to just return a Matrix directly, how would you build it iteratively while solving the +1 on the idea of AbstractODESolution. Convert the row of a matrix into a vector Follow 7 views (last 30 days) Show older comments Jose L. How about this to convert the matrix into a column vector param2 data2d(:,1) Convert column 1 of 2-d data matrix into a column vector. If you are saying that there is no Julia function/package that gives Vector = hcat(s.solution, v) # is there a way to avoid this copy?Īs you notice, the hcat at the end actually copies the solution each time a vector is added, which is obviously going to be bad for performance. How about this to convert the matrix into a column vector param2 data2d(:,1) Convert column 1 of 2-d data matrix into a column vector. The convenience really depends on the use case I suppose. Maybe this was introduced by MATLAB? Often solvers (like in Sundials) only return the final solution and one can access intermediate results only via some event system. ![]() There is no logical reason why an ODE solver has to return a matrix either. ![]() My point is, "consistency" is pretty much the only possible reason for the current behavior but it's not really a good reason because the other way around is consistent with the distinction between array and scalar every else. However, we went through some discussions ( #20) to define the current API, so we shouldn't make fast decisions now. Not to mention that there's good reason we have a Matrix type and many libraries expect data in such format when getting a 2D : Don't get me wrong, I don't insist on the current behavior. Access the element in the buffer is also much more expensive when you have Vector of Vector. There's no benchmark on converting from Matrix to Vector of Vector because you can just use SubArray or ArrayView to slice the matrix. The benchmark measures the effeciency for some basic operations including creating the buffers, converting them into different format and assessing elements (sum).Īs clearly shown above, creating arrays of arrays is mush slower, Concatenating the vectors is commonly even more expensive than transposing ( splat_vector1 is relatively effective because the memory is relatively continuous due to how it is created in this benchmark but it is still very expensive). ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |