comparison liboctave/CMatrix.cc @ 10805:8c858a1a2079

simplify Matrix::extract
author Jaroslav Hajek <highegg@gmail.com>
date Tue, 20 Jul 2010 12:56:05 +0200
parents add87b12e63c
children 7c542263a92a
comparison
equal deleted inserted replaced
10804:3d5c6b84ddaf 10805:8c858a1a2079
901 ComplexMatrix::extract (octave_idx_type r1, octave_idx_type c1, octave_idx_type r2, octave_idx_type c2) const 901 ComplexMatrix::extract (octave_idx_type r1, octave_idx_type c1, octave_idx_type r2, octave_idx_type c2) const
902 { 902 {
903 if (r1 > r2) { octave_idx_type tmp = r1; r1 = r2; r2 = tmp; } 903 if (r1 > r2) { octave_idx_type tmp = r1; r1 = r2; r2 = tmp; }
904 if (c1 > c2) { octave_idx_type tmp = c1; c1 = c2; c2 = tmp; } 904 if (c1 > c2) { octave_idx_type tmp = c1; c1 = c2; c2 = tmp; }
905 905
906 octave_idx_type new_r = r2 - r1 + 1; 906 return index (idx_vector (r1, r2+1), idx_vector (c1, c2+1));
907 octave_idx_type new_c = c2 - c1 + 1;
908
909 ComplexMatrix result (new_r, new_c);
910
911 for (octave_idx_type j = 0; j < new_c; j++)
912 for (octave_idx_type i = 0; i < new_r; i++)
913 result.xelem (i, j) = elem (r1+i, c1+j);
914
915 return result;
916 } 907 }
917 908
918 ComplexMatrix 909 ComplexMatrix
919 ComplexMatrix::extract_n (octave_idx_type r1, octave_idx_type c1, octave_idx_type nr, octave_idx_type nc) const 910 ComplexMatrix::extract_n (octave_idx_type r1, octave_idx_type c1, octave_idx_type nr, octave_idx_type nc) const
920 { 911 {
921 ComplexMatrix result (nr, nc); 912 return index (idx_vector (r1, r1 + nr), idx_vector (r2, r2 + nr));
922
923 for (octave_idx_type j = 0; j < nc; j++)
924 for (octave_idx_type i = 0; i < nr; i++)
925 result.xelem (i, j) = elem (r1+i, c1+j);
926
927 return result;
928 } 913 }
929 914
930 // extract row or column i. 915 // extract row or column i.
931 916
932 ComplexRowVector 917 ComplexRowVector