Mark a matrix "upper" in a oct-file

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Mark a matrix "upper" in a oct-file

Marco Caliari-4
Dear all,

I have to take the upper triangular part of a matrix in a oct-file. Later,
I have to perform RowVector-Matrix products with it. This is my code

// given Matrix F(m,m)
// take the upper triangular part
for (octave_idx_type j = 0; j < m; j++)
     {
       for (octave_idx_type i = j+1; i < m; i++)
  F(i,j) = 0.0;
     }
   RowVector d = F.row(0);
// make RowVector-matrix products
   for (octave_idx_type i = 0; i < s-1; i++)
     d = d * F;

My question is: if I mark the matrix "upper" (but do not know how to do
it), is the RowVector-Matrix product faster (for instance BLAS dtrmv is
used instead of general dgemv)?

Thanks,

Marco

_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: Mark a matrix "upper" in a oct-file

David Bateman-2


> Le 5 sept. 2014 à 13:56, Marco Caliari <[hidden email]> a écrit :
>
> Dear all,
>
> I have to take the upper triangular part of a matrix in a oct-file. Later, I have to perform RowVector-Matrix products with it. This is my code
>
> // given Matrix F(m,m)
> // take the upper triangular part
> for (octave_idx_type j = 0; j < m; j++)
>    {
>      for (octave_idx_type i = j+1; i < m; i++)
>    F(i,j) = 0.0;
>    }
>  RowVector d = F.row(0);
> // make RowVector-matrix products
>  for (octave_idx_type i = 0; i < s-1; i++)
>    d = d * F;
>
> My question is: if I mark the matrix "upper" (but do not know how to do it), is the RowVector-Matrix product faster (for instance BLAS dtrmv is used instead of general dgemv)?
>

Look at the matrix_type function for how to mark the matrix as upper. However, marking it as such is only useful at this point for the solve function or slash operators.

D.


> Thanks,
>
> Marco
>
> _______________________________________________
> Help-octave mailing list
> [hidden email]
> https://lists.gnu.org/mailman/listinfo/help-octave

_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: Mark a matrix "upper" in a oct-file

Marco Caliari-4

On Fri, 5 Sep 2014, David Bateman wrote:

>
>
>> Le 5 sept. 2014 à 13:56, Marco Caliari <[hidden email]> a écrit :
>>
>> Dear all,
>>
>> I have to take the upper triangular part of a matrix in a oct-file. Later, I have to perform RowVector-Matrix products with it. This is my code
>>
>> // given Matrix F(m,m)
>> // take the upper triangular part
>> for (octave_idx_type j = 0; j < m; j++)
>>    {
>>      for (octave_idx_type i = j+1; i < m; i++)
>>    F(i,j) = 0.0;
>>    }
>>  RowVector d = F.row(0);
>> // make RowVector-matrix products
>>  for (octave_idx_type i = 0; i < s-1; i++)
>>    d = d * F;
>>
>> My question is: if I mark the matrix "upper" (but do not know how to do it), is the RowVector-Matrix product faster (for instance BLAS dtrmv is used instead of general dgemv)?
>>
>
> Look at the matrix_type function for how to mark the matrix as upper. However, marking it as such is only useful at this point for the solve function or slash operators.
Thanks David,

I do not know how to use matrix_type in a oct file, but I understand it is
useless to my purpose. It seems that Matlab does not use dtrmv for
triangular matrices, too (I see the same cputime). Nevertheless, it could
be an interesting new feature in Octave, maybe not so difficult to
implement.

Cheers,
Marco
_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: Mark a matrix "upper" in a oct-file

Marco Caliari-4
In reply to this post by David Bateman-2
On Fri, 5 Sep 2014, David Bateman wrote:

>
>
>> Le 5 sept. 2014 à 13:56, Marco Caliari <[hidden email]> a écrit :
>>
>> Dear all,
>>
>> I have to take the upper triangular part of a matrix in a oct-file. Later, I have to perform RowVector-Matrix products with it. This is my code
>>
>> // given Matrix F(m,m)
>> // take the upper triangular part
>> for (octave_idx_type j = 0; j < m; j++)
>>    {
>>      for (octave_idx_type i = j+1; i < m; i++)
>>    F(i,j) = 0.0;
>>    }
>>  RowVector d = F.row(0);
>> // make RowVector-matrix products
>>  for (octave_idx_type i = 0; i < s-1; i++)
>>    d = d * F;
>>
>> My question is: if I mark the matrix "upper" (but do not know how to do it), is the RowVector-Matrix product faster (for instance BLAS dtrmv is used instead of general dgemv)?
>>
>
> Look at the matrix_type function for how to mark the matrix as upper. However, marking it as such is only useful at this point for the solve function or slash operators.
Dear all, copying from dMatrix.cc, I replaced

for (octave_idx_type i = 0; i < s-1; i++)
   d = d*F

with the triangular matrix vector product

double *Fd = d.fortran_vec();
for (octave_idx_type i = 0; i < s-1; i++)
      {
       F77_XFCN(dtrmv, DTRMV, (F77_CONST_CHAR_ARG2 ("U",1),
       F77_CONST_CHAR_ARG2 ("T",1),
       F77_CONST_CHAR_ARG2 ("N",1),
       m, F.data(),
       m, Fd, 1
       F77_CHAR_ARG_LEN (1)
       F77_CHAR_ARG_LEN (1)
       F77_CHAR_ARG_LEN (1)));
       }


It works, but even with large matrices (around 400x400) I do not see any
speed-up.

Thanks,

Marco
_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave