Boost logo

Ublas :

Subject: Re: [ublas] Matrix with vector interface.
From: Oswin Krause (Oswin.Krause_at_[hidden])
Date: 2012-09-18 05:07:15


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
>>> _______________________________________________
>>> ublas mailing list
>>> ublas_at_[hidden]
>>> http://lists.boost.org/mailman/listinfo.cgi/ublas
>>> Sent to: Oswin.Krause_at_[hidden]
>>
>>
>> _______________________________________________
>> ublas mailing list
>> ublas_at_[hidden]
>> http://lists.boost.org/mailman/listinfo.cgi/ublas
>> Sent to: jduran.gm_at_[hidden]
> _______________________________________________
> ublas mailing list
> ublas_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/ublas
> Sent to: Oswin.Krause_at_[hidden]