Registered Member
|
Hi,
I've created a "unique" (returns unique elements) helper function that works for a specific type ArrayXi but it throws an exception when I make the function "generic" (for one column or one row objects only). This is the version that works:
this is my generic version:
I test the generic version with an ArrayXi ArrayXi values; ArrayXi unique_values; //fill values unique_values = unique(values); everything goes well until it returns from unique. I would assume that ArrayXi copy constructor creates a new ArrayXi from tmp and that's what is assigned to unique_values. This test seems to work well for the function version with specific type ArrayXi but not for the generic version. In the generic version, somewhere when tmp comes out of scope the number of columns changes to a huge random number that ultimately throws Eigen::internal::throw_std_bad_alloc() I don't know why is doing what is doing. Any help would be most appreciated. |
Moderator
|
Simply looking at your code, I don't have a clue. So I'd recommend to run your under valgrind to detect the memory issues.
As an optimization you could rather declare tmp as: typename Derived::PlainObject tmp(data.derived()); but that should not solve your issue. |
Registered Member
|
Hi,
I tried the optimization using derived(), as you said no effect on the exception. It's strange, it's like if the copy constructor for ArrayXi wasn't called at the return, I wonder if it has anything to do with the templated inheritance... Using valgrind can be a bit difficult for me cause I'm on windows 7, I could try to run it on a virtual machine, but I think it'll take me quite a lot of time as I have never use it before and I'm not very familiar with linux and gcc, gdb. I think that for the moment I'll use specific type versions as I need to get this job done urgently. |
Moderator
|
oh, I did not looked carefully but you cannot return a Eigen::DenseBase<Derived>. Such an object cannot exist alone. Instead the return type must be typename Derived::PlainObject.
|
Registered Member
|
Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]