|
Ublas : |
Subject: Re: [ublas] Matrix with vector interface.
From: Joaquim Duran (jduran.gm_at_[hidden])
Date: 2012-09-18 06:26:30
I'll take a to boost::range.
> also a resize of a matrix row doesn't make sense, since all rows need the
> same size and so on...i went through the same problems (and actually
> implemented my suggested alternative) and there is no good way for a resize
> which doesn't lead to all kinds of strange problems.
My idea is that when the the matrix is used as a vector, when the
matrix is resized, COLUMN(S) are added or removed, but NOT simple
elements to a concrete row. Think something like:
Matrix m;
matrix_as_vector v(m);
for (iter = v.begin(); iter != v.end(), iter++)
{
matrix_column<Matrix> mc = *iter; // The contents of the
iterator is a column of the matrix.
std::cout << "Column: " << mc << std::endl;
}
Joaquim Duran
2012/9/18 Oswin Krause <Oswin.Krause_at_[hidden]>:
> boost range gives you automatically size(m). resize is a strange operation
> for matrices in this context aside from m.resize(rows,columns) which is
> already there. as long as you add both informations it is fine, but for
> example in this case it is not clear what should happen:
>
> m.resize(0) //no columns-> empty matrix
> m.resize(10) //10 columns, but how many rows?
>
> also a resize of a matrix row doesn't make sense, since all rows need the
> same size and so on...i went through the same problems (and actually
> implemented my suggested alternative) and there is no good way for a resize
> which doesn't lead to all kinds of strange problems.
>
> Oswin Krause
>
>
> On 2012-09-18 10:16, Joaquim Duran wrote:
>>
>> Thanks for your suggestion, but I should implement other operations
>> like size and resize.
>>
>> Joaquim Duran
>>
>>
>> 2012/9/17 Oswin Krause <Oswin.Krause_at_[hidden]>:
>>>
>>> The easisest way, which dos not require a poxy would be to use
>>> boost.range
>>> and implement a suitable
>>>
>>> begin(m) and end(m) along with the required iterator and typedefs.
>>>
>>> than your example would look like:
>>>
>>> main()
>>> {
>>> matrix m;
>>> std::sort(begin(m), end(m), less_module);
>>>
>>> }
>>>
>>> On 2012-09-17 11:11, Joaquim Duran wrote:
>>>>
>>>>
>>>> Sorry to send the example unfinished. Here it is completed.
>>>>
>>>> Example: Sort the columns of a matrix based on their module:
>>>>
>>>> using namespace boost::numeric::ublas;
>>>>
>>>> template <typedef Vector>
>>>> bool less_module(const Vector& v1, const Vector& v2)
>>>> {
>>>> return norm_2(v1) < norm_2(v2);
>>>> }
>>>>
>>>> main()
>>>> {
>>>> matrix m;
>>>> column_facade(m);
>>>> std::sort(m.begin(), m.end(), less_module);
>>>> }
>>>>
>>>> Joaquim Duran