Matrix Klasse mit Vectoren
-
Ein Hinweis nebenbei: der Container std::valarray könnte sich für numerische Operationen besser eignen als std::vector.
Gruß Kimmi
-
Habe ein ähnliches Problem.
Würde sich valarray auch bei großen Datentypen, wie z.B. aus gmp, auch besser eignen?
Was hätte eine bessere Preformance?
-
Matrix(int d1, int d2) : mat(d1, std::vector<int>(d2)){}
-
Welche Vorteile hat in diesem Fall ( Matrizen sind meistens von konstanter Länge ) eigentlich die Verwendung von std::vector?
früher gabs da mal so dinge wie new und delete...
*sich auf den Kritik-hagel vorbereitet*
-
leider funktioniert mit gmp (mpq_t) das nicht:
Matrix(int d1, int d2) : mat(d1, std::vector<mpq_t>(d2)){}wahrscheinlich muss ich sowas wie laraM vorgeschlagen hat machen:
vector<mpq_t*> matmachen.
und dann auch über new und delete gehen oder?
Hat einer sowas schonmal gemacht?
-
Was funktioniert nicht?
-
Matrix(int d1, int d2) : mat(d1, std::vector<mpq_t>(d2)){}‘std::vector<_Tp, _Alloc>::vector(size_t, const _Tp&, const _Alloc&) [with _Tp = __mpq_struct [1], _Alloc = std::allocator<__mpq_struct [1]>]’: error: conversion from ‘int’ to non-scalar type ‘__mpq_struct [1]’ requested /usr/include/c++/4.3/bits/stl_construct.h: In function ‘void std::_Destroy(_Tp*) [with _Tp = __mpq_struct [1]]’: /usr/include/c++/4.3/bits/stl_construct.h:103: instantiated from ‘void std::_Destroy(_ForwardIterator, _ForwardIterator) [with _ForwardIterator = __mpq_struct (*)[1]]’ /usr/include/c++/4.3/bits/stl_construct.h:128: instantiated from ‘void std::_Destroy(_ForwardIterator, _ForwardIterator, std::allocator<_T2>&) [with _ForwardIterator = __mpq_struct (*)[1], _Tp = __mpq_struct [1]]’ /usr/include/c++/4.3/bits/stl_vector.h:300: instantiated from ‘std::vector<_Tp, _Alloc>::~vector() [with _Tp = __mpq_struct [1], _Alloc = std::allocator<__mpq_struct [1]>]’ich denke das hat was damit zu tun, das ich den ersten vector erst mit mpq_init() aufrufen müßte, bevor ich zweite Dimension einfügen kann, oder?
-
Kann es sein dass die Membervariable "mat" noch vom Typ vector<vector<int> > ist?
-
class Matrix { public: Matrix(); Matrix(int rows, int cols): mat(rows, vector<mpq_t>(cols)){}; private: vector< vector<mpq_t> > mat; };hmm
-
Es klappt auch schon eindimensional nicht:
class Matrix { public: Matrix(); Matrix(int rows): mat(rows){}; private: vector<mpq_t > mat; };selbe Fehlermeldung:
../Matrix.h: In constructor ‘std::vector<_Tp, _Alloc>::vector(size_t, const _Tp&, const _Alloc&) [with _Tp = __mpq_struct [1], _Alloc = std::allocator<__mpq_struct [1]>]’: ../Matrix.h:20: error: conversion from ‘int’ to non-scalar type ‘__mpq_struct [1]’ requested /usr/include/c++/4.3/bits/stl_construct.h: In function ‘void std::_Destroy(_Tp*) [with _Tp = __mpq_struct [1]]’: /usr/include/c++/4.3/bits/stl_construct.h:103: instantiated from ‘void std::_Destroy(_ForwardIterator, _ForwardIterator) [with _ForwardIterator = __mpq_struct (*)[1]]’ /usr/include/c++/4.3/bits/stl_construct.h:128: instantiated from ‘void std::_Destroy(_ForwardIterator, _ForwardIterator, std::allocator<_T2>&) [with _ForwardIterator = __mpq_struct (*)[1], _Tp = __mpq_struct [1]]’ /usr/include/c++/4.3/bits/stl_vector.h:300: instantiated from ‘std::vector<_Tp, _Alloc>::~vector() [with _Tp = __mpq_struct [1], _Alloc = std::allocator<__mpq_struct [1]>]’ ../Matrix.h:20: instantiated from here /usr/include/c++/4.3/bits/stl_construct.h:88: error: request for member ‘~__mpq_struct [1]’ in ‘* __pointer’, which is of non-class type ‘__mpq_struct [1]’ /usr/include/c++/4.3/bits/stl_algobase.h: In function ‘typename __gnu_cxx::__enable_if<(! std::__is_scalar::__value), _OutputIterator>::__type std::__fill_n_a(_OutputIterator, _Size, const _Tp&) [with _OutputIterator = __mpq_struct (*)[1], _Size = unsigned int, _Tp = __mpq_struct [1]]’: /usr/include/c++/4.3/bits/stl_algobase.h:784: instantiated from ‘_OI std::fill_n(_OI, _Size, const _Tp&) [with _OI = __mpq_struct (*)[1], _Size = unsigned int, _Tp = __mpq_struct [1]]’ /usr/include/c++/4.3/bits/stl_uninitialized.h:209: instantiated from ‘static void std::__uninitialized_fill_n<true>::uninitialized_fill_n(_ForwardIterator, _Size, const _Tp&) [with _ForwardIterator = __mpq_struct (*)[1], _Size = unsigned int, _Tp = __mpq_struct [1]]’ /usr/include/c++/4.3/bits/stl_uninitialized.h:228: instantiated from ‘void std::uninitialized_fill_n(_ForwardIterator, _Size, const _Tp&) [with _ForwardIterator = __mpq_struct (*)[1], _Size = unsigned int, _Tp = __mpq_struct [1]]’ /usr/include/c++/4.3/bits/stl_uninitialized.h:323: instantiated from ‘void std::__uninitialized_fill_n_a(_ForwardIterator, _Size, const _Tp&, std::allocator<_Tp2>&) [with _ForwardIterator = __mpq_struct (*)[1], _Size = unsigned int, _Tp = __mpq_struct [1], _Tp2 = __mpq_struct [1]]’ /usr/include/c++/4.3/bits/stl_vector.h:976: instantiated from ‘void std::vector<_Tp, _Alloc>::_M_fill_initialize(size_t, const _Tp&) [with _Tp = __mpq_struct [1], _Alloc = std::allocator<__mpq_struct [1]>]’ /usr/include/c++/4.3/bits/stl_vector.h:236: instantiated from ‘std::vector<_Tp, _Alloc>::vector(size_t, const _Tp&, const _Alloc&) [with _Tp = __mpq_struct [1], _Alloc = std::allocator<__mpq_struct [1]>]’ ../Matrix.h:20: instantiated from here /usr/include/c++/4.3/bits/stl_algobase.h:741: error: invalid array assignmentschade.. kennt einer einen ausweg
(sorry LaraM, hätte einen eigenen Beitrag aufmachen sollen
)EDIT: Ich habe einen eigenen Beitrag aufgemacht!