21 #ifndef SELDON_FILE_PERMUTATION_SCALING_MATRIX_CXX
54 template<
class T,
class Prop,
class Allocator>
59 int i, j, k;
long l, nnz;
71 for (i = 0; i < m; i++)
72 if ((nnz = ptr[i + 1] - ptr[i]) != 0)
74 row_index.Reallocate(nnz);
76 for (k = 0, l = ptr[i]; k < nnz; k++, l++)
79 row_index(k) = col_perm(ind[l]);
80 row_data(k) = data[l];
84 Sort(row_index, row_data);
87 for (k = 0, l = ptr[i]; k < nnz; k++, l++)
89 ind[l] = row_index(k);
90 data[l] = row_data(k);
108 prev_row_index.Fill();
110 Sort(row_permutation, prev_row_index);
111 row_permutation.Clear();
118 long ptr_count = 0;
int length;
119 for (i = 0; i < m; i++)
121 length = ptr[prev_row_index(i) + 1] - ptr[prev_row_index(i)];
122 for (j = 0; j < length; j++)
124 new_data(ptr_count + j) = data[ptr[prev_row_index(i)] + j];
125 new_ind(ptr_count + j) = ind[ptr[prev_row_index(i)] + j];
127 new_ptr(i) = ptr_count;
130 new_ptr(m) = ptr_count;
132 A.
SetData(m, n, new_data, new_ptr, new_ind);
141 template<
class T,
class Prop,
class Allocator>
146 int i, j, k;
long l, nnz;
158 for (i = 0; i < n; i++)
159 if ((nnz = ptr[i + 1] - ptr[i]) != 0)
161 col_index.Reallocate(nnz);
163 for (k = 0, l = ptr[i]; k < nnz; k++, l++)
166 col_index(k) = row_perm(ind[l]);
167 col_data(k) = data[l];
171 Sort(col_index, col_data);
174 for (k = 0, l = ptr[i]; k < nnz; k++, l++)
176 ind[l] = col_index(k);
177 data[l] = col_data(k);
194 prev_col_index.Fill();
196 Sort(col_permutation, prev_col_index);
197 col_permutation.Clear();
204 int ptr_count = 0, length;
205 for (i = 0; i < n; i++)
207 length = ptr[prev_col_index(i) + 1] - ptr[prev_col_index(i)];
208 for (j = 0; j < length; j++)
210 new_data(ptr_count + j) = data[ptr[prev_col_index(i)] + j];
211 new_ind(ptr_count + j) = ind[ptr[prev_col_index(i)] + j];
213 new_ptr(i) = ptr_count;
216 new_ptr(n) = ptr_count;
218 A.
SetData(m, n, new_data, new_ptr, new_ind);
227 template<
class T,
class Prop,
class Allocator>
246 for (
int i = 0; i < m; i++)
247 for (
long j = ptr[i]; j < ptr[i+1]; j++)
249 IndRow(k) = row_perm(i);
251 IndCol(k) = row_perm(ind[j]);
252 if (IndCol(k) <= IndRow(k))
255 int ind_tmp = IndRow(k);
256 IndRow(k) = IndCol(k);
263 Sort(nnz, IndRow, IndCol, Val);
269 for (
int i = 0; i < m; i++)
271 long first_index = k;
273 while (k < nnz && IndRow(k) <= i)
276 Sort(first_index, k-1, IndCol, Val);
280 A.
SetData(m, n, Val, Ptr, IndCol);
289 template<
class T,
class Prop,
class Allocator>
308 for (
int i = 0; i < m; i++)
309 for (
long j = ptr[i]; j < ptr[i+1]; j++)
311 IndCol(k) = row_perm(i);
313 IndRow(k) = row_perm(ind[j]);
314 if (IndCol(k) <= IndRow(k))
317 int ind_tmp = IndRow(k);
318 IndRow(k) = IndCol(k);
325 Sort(nnz, IndCol, IndRow, Val);
331 for (
int i = 0; i < n; i++)
333 long first_index = k;
335 while (k < nnz && IndCol(k) <= i)
338 Sort(first_index, k-1, IndRow, Val);
342 A.
SetData(m, n, Val, Ptr, IndRow);
351 template<
class T,
class Prop,
class Allocator>
355 int m = A.
GetM(), n, i, i_, j, i2;
356 IVect ind_tmp, iperm(m), rperm(m);
357 for (i = 0; i < m; i++)
365 for (i = 0; i < m; i++)
374 ind_tmp.Reallocate(n);
375 for (j = 0; j < n; j++)
376 ind_tmp(j) = col_perm(A.
Index(i2,j));
384 int i_tmp = iperm(i_);
385 iperm(i_) = iperm(i2);
387 rperm(iperm(i_)) = i_;
388 rperm(iperm(i2)) = i2;
401 template<
class T,
class Prop,
class Allocator>
406 IVect ind_tmp, iperm(n), rperm(n);
407 for (
int i = 0; i < n; i++)
415 for (
int i = 0; i < n; i++)
420 int i_ = col_perm(i);
424 ind_tmp.Reallocate(p);
425 for (
int j = 0; j < p; j++)
426 ind_tmp(j) = row_perm(A.
Index(i2, j));
434 int i_tmp = iperm(i_);
435 iperm(i_) = iperm(i2);
437 rperm(iperm(i_)) = i_;
438 rperm(iperm(i2)) = i2;
451 template<
class T,
class Prop,
class Allocator>
468 for (
int i = 0; i < m; i++)
471 IndCol(k) = col_perm(i);
472 Val(k) = A.
Value(i,j);
473 IndRow(k) = row_perm(A.
Index(i, j));
474 if (IndCol(k) <= IndRow(k))
477 int ind_tmp = IndRow(k);
478 IndRow(k) = IndCol(k);
485 Sort(nnz, IndCol, IndRow, Val);
489 for (
int i = 0; i < m; i++)
491 long first_index = k;
493 while (k < nnz && IndCol(k) <= i)
496 int size_column = k - first_index;
502 Sort(k, k+size_column-1, IndRow, Val);
503 for (
int j = 0; j < size_column; j++)
505 A.
Index(i,j) = IndRow(k);
506 A.
Value(i,j) = Val(k);
521 template<
class T,
class Prop,
class Allocator>
538 for (
int i = 0; i < m; i++)
542 IndRow(k) = row_perm(i);
543 Val(k) = A.
Value(i, j);
544 IndCol(k) = col_perm(A.
Index(i, j));
545 if (IndCol(k) <= IndRow(k))
548 int ind_tmp = IndRow(k);
549 IndRow(k) = IndCol(k);
557 Sort(nnz, IndRow, IndCol, Val);
561 for (
int i = 0; i < m; i++)
563 long first_index = k;
565 while (k < nnz && IndRow(k) <= i)
568 int size_row = k - first_index;
574 Sort(k, k+size_row-1, IndCol, Val);
575 for (
int j = 0; j < size_row; j++)
577 A.
Index(i,j) = IndCol(k);
578 A.
Value(i,j) = Val(k);
601 template<
class T,
class Prop,
class Allocator>
608 for (
int i = 0; i < row_perm.GetM(); i++)
609 inv_row_perm(row_perm(i)) = i;
611 for (
int i = 0; i < col_perm.GetM(); i++)
612 inv_col_perm(col_perm(i)) = i;
614 ApplyInversePermutation(A, inv_row_perm, inv_col_perm);
623 template<
class T,
class Prop,
class Allocator>
630 for (
int i = 0; i < row_perm.GetM(); i++)
631 inv_row_perm(row_perm(i)) = i;
633 for (
int i = 0; i < col_perm.GetM(); i++)
634 inv_col_perm(col_perm(i)) = i;
636 ApplyInversePermutation(A, inv_row_perm, inv_col_perm);
645 template<
class T,
class Prop,
class Allocator>
651 for (
int i = 0; i < row_perm.GetM(); i++)
652 inv_row_perm(row_perm(i)) = i;
654 ApplyInversePermutation(A, inv_row_perm, inv_row_perm);
663 template<
class T,
class Prop,
class Allocator>
669 for (
int i = 0; i < row_perm.GetM(); i++)
670 inv_row_perm(row_perm(i)) = i;
672 ApplyInversePermutation(A, inv_row_perm, inv_row_perm);
681 template<
class T,
class Prop,
class Allocator>
688 for (
int i = 0; i < row_perm.GetM(); i++)
689 inv_row_perm(row_perm(i)) = i;
691 for (
int i = 0; i < col_perm.GetM(); i++)
692 inv_col_perm(col_perm(i)) = i;
694 ApplyInversePermutation(A, inv_row_perm, inv_col_perm);
703 template<
class T,
class Prop,
class Allocator>
710 for (
int i = 0; i < row_perm.GetM(); i++)
711 inv_row_perm(row_perm(i)) = i;
713 for (
int i = 0; i < col_perm.GetM(); i++)
714 inv_col_perm(col_perm(i)) = i;
716 ApplyInversePermutation(A, inv_row_perm, inv_col_perm);
725 template<
class T,
class Prop,
class Allocator>
731 for (
int i = 0; i < row_perm.GetM(); i++)
732 inv_row_perm(row_perm(i)) = i;
734 ApplyInversePermutation(A, inv_row_perm, inv_row_perm);
743 template<
class T,
class Prop,
class Allocator>
749 for (
int i = 0; i < row_perm.GetM(); i++)
750 inv_row_perm(row_perm(i)) = i;
752 ApplyInversePermutation(A, inv_row_perm, inv_row_perm);
768 template<
class Prop,
class T1,
class Allocator1,
769 class T2,
class Allocator2,
class T3,
class Allocator3>
774 T1* data = A.GetData();
775 long* ptr = A.GetPtr();
776 int* ind = A.GetInd();
779 for (
int i = 0; i < m; i++ )
780 for (
long j = ptr[i]; j < ptr[i+1]; j++ )
781 data[j] *= scale_left(i) * scale_right(ind[j]);
789 template<
class Prop,
class T1,
class Allocator1,
790 class T2,
class Allocator2,
class T3,
class Allocator3>
795 T1* data = A.GetData();
796 long* ptr = A.GetPtr();
797 int* ind = A.GetInd();
799 for (
int i = 0; i < A.GetN(); i++ )
800 for (
long j = ptr[i]; j < ptr[i+1]; j++ )
801 data[j] *= scale_left(ind[j]) * scale_right(i);
809 template<
class Prop,
class T1,
class Allocator1,
810 class T2,
class Allocator2,
class T3,
class Allocator3>
815 T1* data = A.GetData();
816 long* ptr = A.GetPtr();
817 int* ind = A.GetInd();
820 for (
int i = 0; i < m; i++ )
821 for (
long j = ptr[i]; j < ptr[i+1]; j++ )
822 data[j] *= scale_left(i) * scale_left(ind[j]);
830 template<
class Prop,
class T1,
class Allocator1,
831 class T2,
class Allocator2,
class T3,
class Allocator3>
836 T1* data = A.GetData();
837 long* ptr = A.GetPtr();
838 int* ind = A.GetInd();
840 for (
int i = 0; i < A.GetM(); i++ )
841 for (
long j = ptr[i]; j < ptr[i+1]; j++ )
842 data[j] *= scale_left(i) * scale_left(ind[j]);
850 template<
class Prop,
class T1,
class Allocator1,
851 class T2,
class Allocator2,
class T3,
class Allocator3>
857 for (
int i = 0; i < m; i++ )
858 for (
int j = 0; j < A.GetRowSize(i); j++ )
859 A.Value(i,j) *= scale_left(i) * scale_right(A.Index(i, j));
868 template<
class Prop,
class T1,
class Allocator1,
869 class T2,
class Allocator2,
class T3,
class Allocator3>
874 for (
int i = 0; i < A.GetN(); i++ )
875 for (
int j = 0; j < A.GetColumnSize(i); j++ )
876 A.Value(i, j) *= scale_right(i) * scale_left(A.Index(i, j));
885 template<
class Prop,
class T1,
class Allocator1,
886 class T2,
class Allocator2,
class T3,
class Allocator3>
892 for (
int i = 0; i < m; i++ )
893 for (
int j = 0; j < A.GetRowSize(i); j++ )
894 A.Value(i,j) *= scale_left(i) * scale_right(A.Index(i, j));
903 template<
class Prop,
class T1,
class Allocator1,
904 class T2,
class Allocator2,
class T3,
class Allocator3>
910 for (
int i = 0; i < m; i++ )
911 for (
int j = 0; j < A.GetColumnSize(i); j++ )
912 A.Value(i, j) *= scale_left(i) * scale_right(A.Index(i, j));
929 template<
class T1,
class Allocator1,
930 class Prop,
class T2,
class Allocator2>
934 T1* data = A.GetData();
935 long* ptr = A.GetPtr();
938 for (
int i = 0; i < m; i++ )
939 for (
long j = ptr[i]; j < ptr[i+1]; j++ )
948 template<
class T1,
class Allocator1,
949 class Prop,
class T2,
class Allocator2>
953 T1* data = A.GetData();
954 long* ptr = A.GetPtr();
955 int* ind = A.GetInd();
957 for (
int i = 0; i < A.GetN(); i++ )
958 for (
long j = ptr[i]; j < ptr[i+1]; j++ )
959 data[j] *= scale(ind[j]);
967 template<
class T1,
class Allocator1,
968 class Prop,
class T2,
class Allocator2>
973 for (
int i = 0; i < m; i++ )
974 for (
int j = 0; j < A.GetRowSize(i); j++ )
975 A.Value(i,j) *= scale(i);
983 template<
class T1,
class Allocator1,
984 class Prop,
class T2,
class Allocator2>
988 for (
int i = 0; i < A.GetN(); i++ )
989 for (
int j = 0; j < A.GetColumnSize(i); j++ )
990 A.Value(i, j) *= scale(A.Index(i, j));
1006 template<
class T1,
class Allocator1,
1007 class Prop,
class T2,
class Allocator2>
1011 T1* data = A.GetData();
1012 long* ptr = A.GetPtr();
1013 int* ind = A.GetInd();
1016 for (
int i = 0; i < m; i++ )
1017 for (
long j = ptr[i]; j < ptr[i+1]; j++ )
1018 data[j] *= scale(ind[j]);
1026 template<
class T1,
class Allocator1,
1027 class Prop,
class T2,
class Allocator2>
1031 T1* data = A.GetData();
1032 long* ptr = A.GetPtr();
1034 for (
int i = 0; i < A.GetN(); i++ )
1035 for (
long j = ptr[i]; j < ptr[i+1]; j++ )
1036 data[j] *= scale(i);
1044 template<
class T1,
class Allocator1,
1045 class Prop,
class T2,
class Allocator2>
1050 for (
int i = 0; i < m; i++ )
1051 for (
int j = 0; j < A.GetRowSize(i); j++ )
1052 A.Value(i,j) *= scale(A.Index(i, j));
1060 template<
class T1,
class Allocator1,
1061 class Prop,
class T2,
class Allocator2>
1065 for (
int i = 0; i < A.GetN(); i++ )
1066 for (
int j = 0; j < A.GetColumnSize(i); j++ )
1067 A.Value(i, j) *= scale(i);
1077 #define SELDON_FILE_PERMUTATION_SCALING_MATRIX_CXX