![]() Registered Member ![]()
|
Hi all,
I was wondering whether one can definately predict the bahaviour of block operations. For example:
In terms of speed and memory usage this is equal to:
In the second example I am explictely using a Map-Object and therefore a pointer to a data-array. This definately does not result in copying anything. But in the first example I am only hoping, that the bahaviour is equal to the second example, but I am never sure about it. The reason for my question is, that I observed a copy-behaviour when using the specialized block-operation for vectors, namely: .segment() . When I was using that particular block operation, it resulted in extremely poor performs compared to constructing a Map<> to the data and using the pointer. Therefore I am assuming that .segment() results in copying data. But .segment() and .col() and so on are all part of the Block<> family. In my application I never write to blocks, it is just about getting a pointer to a subset of the data. Is there a way of safely predicting the behaviour of block-operations? What happens when using block operations like .col() on sparse-matrices? Thanks in advance! |
![]() Registered Member ![]()
|
The best way to find out if an Eigen allocates any temporary memory while evaluating an expression is to call Eigen::set_is_malloc_allowed(false) just above the expression you want to check. If Eigen attempts to allocate any memory you should see the following assertion failure:
"heap allocation is forbidden (EIGEN_RUNTIME_NO_MALLOC is defined and g_is_malloc_allowed is false)" Note that this mechanism is not available by default. You need to make sure that EIGEN_RUNTIME_NO_MALLOC has been #defined when you compile Eigen to make use of it. |
![]() Moderator ![]()
|
Submatrices expressions never trigger a copy of the data. If you observed a slowdown by using .segment(), then please show us the complete expression because this can only comes from other operations, not segment.
|
![]() Registered Member ![]()
|
@benoitsteiner: thank you for the suggestion. That is a good way for debugging some crucial parts!
@ggael: I can't remeber what I did with .segment(), but I did some tests and of course you are right: the copying must have been caused by something else! Thank you |
Registered users: Baidu [Spider], Bing [Bot], Google [Bot], rblackwell