Understanding memory preallocation in automatic expansion
조회 수: 9 (최근 30일)
이전 댓글 표시
Hello everyone, I'm one of the users that really love the new automatic expansion with the arithmetic operators introduced in matlab 2016b. I use it heavily, for instance when I want to compute the 3rd order derivative of an vector function F(x) = [f1(x),f2(x),...], I just have to define an array where the first dimension correspond to the function fi, the second dimension to the derivative with respect the variable xj, the third to the derivative with respect to variable, xk, etc (so if I have a quantity that is constant with respect to xi, then its matrix has a singleton in that dimension...
Well, let go to my question, I have a function where this operation is happening:
M = sum(A .* B + C .* D,2);
This line involve an important singleton expansion since the previous matrices are big. Moreover, that line will be executed over and over because the function that contains it will be called thousands of times. So I suppose matlab preallocates the required memory for such expansion every time that function is called, however it does not know that the function will be called again just afterwards and the same amound of memory will be required, so I guess that memory is used for other stuff in the meantime, Am I right?
Is there a way to do that in a more efficient way?
Thanks in advance,
David
댓글 수: 0
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Performance and Memory에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!