This forum has been archived. All content is frozen. Please use KDE Discuss instead.

DynamicSparseMatrix with non-POD elements

Tags: None
(comma "," separated)
dtcaciuc
Registered Member
Posts
3
Karma
0
Hello everyone,

I know it might be abusing the sparse facilities, but should it be possible to use, say, std::vector for DynamicSparseMatrix coefficient type? It *seems* like it's working, template gets properly instantiated and I can even access the coefficients. However as I'm filling out the values, I start getting strange memory errors so I figured it's not as smooth as I thought it would be.

Thanks,

Dimitri.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
if your goal is only to store data I don't which it would fails. Do you have a small self contained example showing the issue?
dtcaciuc
Registered Member
Posts
3
Karma
0
Sure thing, here's one... I'm using Eigen 3.0.0. GCC info:

Code: Select all
gcc version 4.3.4 (Gentoo 4.3.4 p1.0, pie-10.1.5)


Code: Select all
#define EIGEN_YES_I_KNOW_SPARSE_MODULE_IS_NOT_STABLE_YET

#include <Eigen/Core>
#include <Eigen/Sparse>

#include <vector>

typedef
    Eigen::DynamicSparseMatrix<std::vector<size_t>, Eigen::RowMajor>
    M; 

void f(M & m, size_t n, size_t i, size_t j, size_t k) {
    m.coeffRef(i, j).push_back(n);
    m.coeffRef(j, k).push_back(n);
}

int main() {
    M m(40, 40);

    f(m, 1, 0, 4, 5);
    f(m, 2, 0, 4, 6);
    f(m, 3, 0, 4, 17);
    f(m, 4, 1, 0, 2);
    f(m, 5, 1, 0, 3);
    f(m, 6, 1, 0, 4);
    f(m, 7, 2, 0, 3);
    f(m, 8, 2, 0, 4);
    f(m, 9, 3, 0, 4);

    return 0;
}


Edit:

I tried compiling the same on a different machine with gcc version 4.5.1 20100924 (Red Hat 4.5.1-4) and getting segfaults as well.

Code: Select all
#0  0x00002aaaab0e7dfb in ?? () from /lib/libc.so.6
#1  0x00002aaaab0e981a in malloc () from /lib/libc.so.6
#2  0x00002aaaaac8b9bd in operator new(unsigned long) () from /usr/lib/gcc/x86_64-pc-linux-gnu/4.3.4/libstdc++.so.6
#3  0x0000000000402905 in __gnu_cxx::new_allocator<unsigned long>::allocate (this=0x607838, __n=1)
    at /usr/lib/gcc/x86_64-pc-linux-gnu/4.3.4/include/g++-v4/ext/new_allocator.h:92
#4  0x0000000000402934 in std::_Vector_base<unsigned long, std::allocator<unsigned long> >::_M_allocate (this=0x607838, __n=1)
    at /usr/lib/gcc/x86_64-pc-linux-gnu/4.3.4/include/g++-v4/bits/stl_vector.h:144
#5  0x000000000040342e in std::vector<unsigned long, std::allocator<unsigned long> >::_M_insert_aux (this=0x607838, __position=...,
    __x=@0x7fffffffd480) at /usr/lib/gcc/x86_64-pc-linux-gnu/4.3.4/include/g++-v4/bits/vector.tcc:308
#6  0x00000000004035aa in std::vector<unsigned long, std::allocator<unsigned long> >::push_back (this=0x607838, __x=@0x7fffffffd480)
    at /usr/lib/gcc/x86_64-pc-linux-gnu/4.3.4/include/g++-v4/bits/stl_vector.h:694
#7  0x0000000000400be9 in f (m=..., n=9, i=3, j=0, k=4) at sparse-vector.cpp:13
#8  0x0000000000400d38 in main () at sparse-vector.cpp:28


Code: Select all
#0  0x0000003bb8076761 in _int_free () from /lib64/libc.so.6
#1  0x00000000004025c4 in __gnu_cxx::new_allocator<unsigned long>::deallocate (this=0x6067f8, __p=0x606730)
    at /usr/lib/gcc/x86_64-redhat-linux/4.5.1/../../../../include/c++/4.5.1/ext/new_allocator.h:95
#2  0x0000000000401cf0 in std::_Vector_base<unsigned long, std::allocator<unsigned long> >::_M_deallocate (this=0x6067f8, __p=0x606730,
    __n=1)
    at /usr/lib/gcc/x86_64-redhat-linux/4.5.1/../../../../include/c++/4.5.1/bits/stl_vector.h:146
#3  0x0000000000401288 in std::vector<unsigned long, std::allocator<unsigned long> >::_M_insert_aux (this=0x6067f8, __position=5,
    __x=@0x7fffffffe230)
    at /usr/lib/gcc/x86_64-redhat-linux/4.5.1/../../../../include/c++/4.5.1/bits/vector.tcc:361
#4  0x0000000000400cca in std::vector<unsigned long, std::allocator<unsigned long> >::push_back (this=0x6067f8, __x=@0x7fffffffe230)
    at /usr/lib/gcc/x86_64-redhat-linux/4.5.1/../../../../include/c++/4.5.1/bits/stl_vector.h:749
#5  0x0000000000400999 in f (m=..., n=8, i=2, j=0, k=4)
    at sparse-vector.cpp:13
#6  0x0000000000400aeb in main () at sparse-vector.cpp:27
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
hi, this is fixed in the default branch.
dtcaciuc
Registered Member
Posts
3
Karma
0
Awesome, thanks for your help!


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], q.ignora, watchstar