creation of matrix elements
"Michael Smolsky" <[email protected]> Sun, 23 Dec 2007 01:36:19 -0500
| Newsgroups | gmane.comp.lib.mtl.devel |
|---|---|
| Message-ID | <[email protected]> |
This is a multi-part message in MIME format.
--===============0426192636==
Content-Transfer-Encoding: 7bit
Content-Type: multipart/alternative; boundary="_----------=_119839177913701"
This is a multi-part message in MIME format.
--_----------=_119839177913701
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset="iso-8859-1"
Thank you for your insight, Peter.
By looking at your code (contiguous_memory_block.hpp,
generic_array<..>::alloc(..)) I've noticed, that you don't initialize
matrix elements on allocation. That method seems to be called from some
methods of dense2D, such as resize(..). If that is the case, the library
won't work with any class, that has a non-trivial default constructor.
Is this by design?
In order to cover classes with non-trivial default constructors (STL has
no problem with this), you might want to invoke in-place operator new on
the newly allocated memory in generic_array<..>::alloc(..) and perhaps
other places as well. If the default constructor of the element type is
trivial, the compiler will probably optimize this call out and you won't
loose in performance.
Michael.
----- Original Message -----
From: "Peter Gottschling"
To: "General Matrix Template Library \(MTL\) list"
Subject: Re: MTL: Loop-free submatrix extraction
Date: Sat, 22 Dec 2007 17:24:03 +0100
Hi again, Michael,
For dense2D and morton_dense there is a function sub_matrix (shame on
me that there is no documentation yet). You can use it like:b=3D
sub_matrix(a, begin_row, end_row, begin_column, end_column);
As you see it only supports intervals of rows and columns not
arbitrary sets. The reason is that this can be realized efficiently
with a view.
If you are going to write a function I would do something like (only
sketch not tested code):
template <typename Matrix, typename RowVector, typename ColVector>Matrix
list_sub_matrix(const Matrix& matrix, const RowVector& row_vector,
const ColVector& col_vector){ Matrix s(size(row_vector),
size(col_vector)); { matrix::inserter<Matrix> ins(s); for (size_t
r=3D 0; r < size(row_vector); r++) for (size_t c=3D 0; c <
size(col_vector); c++) ins(r, c) <<
matrix[row_vector[r]][col_vector[c]]; } return s;}
Returning a matrix is quite expensive at the moment but will be okay
once I've implemented move semantics. I hope I haven't overseen a
detail otherwise you can asked again. Once you have it done and
tested I'd like to put it in the repository.
Good luck and Merry Christmas,Peter
--=20
Want an e-mail address like mine?
Get a free e-mail account today at www.mail.com!
--_----------=_119839177913701
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset="iso-8859-1"
Thank you for your insight, Peter.<br><br>By looking at your code (contiguo=
us_memory_block.hpp, generic_array<..>::alloc(..)) I've noticed, that=
you don't initialize matrix elements on allocation. That method seems to b=
e called from some methods of dense2D, such as resize(..). If that is the c=
ase, the library won't work with any class, that has a non-trivial default =
constructor.<br><br>Is this by design?<br><br>In order to cover classes wit=
h non-trivial default constructors (STL has no problem with this), you migh=
t want to invoke in-place operator new on the newly allocated memory in gen=
eric_array<..>::alloc(..) and perhaps other places as well. If the de=
fault constructor of the element type is trivial, the compiler will probabl=
y optimize this call out and you won't loose in performance.<br><br>
<div>
Michael.<br>
<br>
<blockquote style=3D"border-left: 2px solid rgb(16, 16, 255); margin-left: =
5px; padding-left: 5px;">----- Original Message -----<br>
From: "Peter Gottschling" <[email protected]><br>
To: "General Matrix Template Library \(MTL\) list" <[email protected]><b=
r>
Subject: Re: MTL: Loop-free submatrix extraction<br>
Date: Sat, 22 Dec 2007 17:24:03 +0100<br>
<br>
Hi again, Michael,</[email protected]></[email protected]><div><br cla=
ss=3D"webkit-block-placeholder"></div><div>For dense2D and morton_dense the=
re is a function sub_matrix (shame on me that there is no documentation yet=
). You can use it like:</div><div>b=3D sub_matrix(a, begin_row, end_r=
ow, begin_column, end_column);</div><div><br class=3D"webkit-block-placehol=
der"></div><div>As you see it only supports intervals of rows and columns n=
ot arbitrary sets. The reason is that this can be realized efficientl=
y with a view.</div><div><br class=3D"webkit-block-placeholder"></div><div>=
If you are going to write a function I would do something like (only sketch=
not tested code):</div><div><br class=3D"webkit-block-placeholder"></div><=
div>template <typename Matrix, typename RowVector, typename ColVector>=
;</div><div>Matrix list_sub_matrix(const Matrix& matrix, const RowVecto=
r& row_vector, const ColVector& col_vector)</div><div>{</div><div>&=
nbsp; Matrix s(size(row_vector), size(col_vector));</div><div> &n=
bsp;{</div><div> matrix::inserter<Matrix> in=
s(s);</div><div> for (size_t r=3D 0; r < size(row_vect=
or); r++)</div><div> for (size_t c=3D 0; c < s=
ize(col_vector); c++)</div><div> &n=
bsp;ins(r, c) << matrix[row_vector[r]][col_vector[c]];</div><div>&nbs=
p; }</div><div> return s;</div><div>}</div><div><br class=
=3D"webkit-block-placeholder"></div><div>Returning a matrix is quite expens=
ive at the moment but will be okay once I've implemented move semantics. &n=
bsp;I hope I haven't overseen a detail otherwise you can asked again.  =
;Once you have it done and tested I'd like to put it in the repository.</di=
v><div><br class=3D"webkit-block-placeholder"></div><div>Good luck and Merr=
y Christmas,</div><div>Peter</div><div><br class=3D"webkit-block-placeholde=
r"></div><div><br></div></blockquote></div><br><BR>
--=20
<div> Want an e-mail address like mine? </b><br>
Get a <b>free e-mail </b>account today at <a href=3D"http://www.mail.com/Pr=
oduct.aspx" target=3D"_blank">www.mail.com</a>!</div>
--_----------=_119839177913701--
--===============0426192636==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
This list is archived at http://www.osl.iu.edu/MailArchives/mtl-devel/
--===============0426192636==--