comparison liboctave/Sparse.cc @ 5731:c7d5a534afa5

[project @ 2006-04-03 19:33:26 by jwe]
author jwe
date Mon, 03 Apr 2006 19:33:27 +0000
parents 233d98d95659
children 8d7162924bd3
comparison
equal deleted inserted replaced
5730:109fdf7b3dcb 5731:c7d5a534afa5
849 dimensions = dim_vector (0, 0); 849 dimensions = dim_vector (0, 0);
850 850
851 if (r == dim1 () && c == dim2 ()) 851 if (r == dim1 () && c == dim2 ())
852 return; 852 return;
853 853
854 typename Sparse<T>::SparseRep *old_rep = Sparse<T>::rep; 854 typename Sparse<T>::SparseRep *old_rep = rep;
855
855 octave_idx_type nc = cols (); 856 octave_idx_type nc = cols ();
856 octave_idx_type nr = rows (); 857 octave_idx_type nr = rows ();
857 858
858 if (nnz () == 0 || r == 0 || c == 0) 859 if (nnz () == 0 || r == 0 || c == 0)
859 // Special case of redimensioning to/from a sparse matrix with 860 // Special case of redimensioning to/from a sparse matrix with
864 octave_idx_type n = 0; 865 octave_idx_type n = 0;
865 Sparse<T> tmpval; 866 Sparse<T> tmpval;
866 if (r >= nr) 867 if (r >= nr)
867 { 868 {
868 if (c > nc) 869 if (c > nc)
869 n = cidx(nc); 870 n = xcidx(nc);
870 else 871 else
871 n = cidx(c); 872 n = xcidx(c);
872 873
873 tmpval = Sparse<T> (r, c, n); 874 tmpval = Sparse<T> (r, c, n);
874 875
875 if (c > nc) 876 if (c > nc)
876 { 877 {
877 for (octave_idx_type i = 0; i < nc; i++) 878 for (octave_idx_type i = 0; i < nc; i++)
878 tmpval.cidx(i) = cidx(i); 879 tmpval.cidx(i) = xcidx(i);
879 for (octave_idx_type i = nc+2; i < c; i++) 880 for (octave_idx_type i = nc+2; i < c; i++)
880 tmpval.cidx(i) = tmpval.cidx(i-1); 881 tmpval.cidx(i) = tmpval.cidx(i-1);
881 } 882 }
882 else if (c <= nc) 883 else if (c <= nc)
883 for (octave_idx_type i = 0; i < c; i++) 884 for (octave_idx_type i = 0; i < c; i++)
884 tmpval.cidx(i) = cidx(i); 885 tmpval.cidx(i) = xcidx(i);
885 886
886 for (octave_idx_type i = 0; i < n; i++) 887 for (octave_idx_type i = 0; i < n; i++)
887 { 888 {
888 tmpval.data(i) = data(i); 889 tmpval.data(i) = xdata(i);
889 tmpval.ridx(i) = ridx(i); 890 tmpval.ridx(i) = xridx(i);
890 } 891 }
891 } 892 }
892 else 893 else
893 { 894 {
894 // Count how many non zero terms before we do anything 895 // Count how many non zero terms before we do anything
895 for (octave_idx_type i = 0; i < c; i++) 896 for (octave_idx_type i = 0; i < c; i++)
896 for (octave_idx_type j = cidx(i); j < cidx(i+1); j++) 897 for (octave_idx_type j = xcidx(i); j < xcidx(i+1); j++)
897 if (ridx(j) < r) 898 if (xridx(j) < r)
898 n++; 899 n++;
899 900
900 if (n) 901 if (n)
901 { 902 {
902 // Now that we know the size we can do something 903 // Now that we know the size we can do something
903 tmpval = Sparse<T> (r, c, n); 904 tmpval = Sparse<T> (r, c, n);
904 905
905 tmpval.cidx(0); 906 tmpval.cidx(0);
906 for (octave_idx_type i = 0, ii = 0; i < c; i++) 907 for (octave_idx_type i = 0, ii = 0; i < c; i++)
907 { 908 {
908 for (octave_idx_type j = cidx(i); j < cidx(i+1); j++) 909 for (octave_idx_type j = xcidx(i); j < xcidx(i+1); j++)
909 if (ridx(j) < r) 910 if (xridx(j) < r)
910 { 911 {
911 tmpval.data(ii) = data(j); 912 tmpval.data(ii) = xdata(j);
912 tmpval.ridx(ii++) = ridx(j); 913 tmpval.ridx(ii++) = xridx(j);
913 } 914 }
914 tmpval.cidx(i+1) = ii; 915 tmpval.cidx(i+1) = ii;
915 } 916 }
916 } 917 }
917 else 918 else