1 #ifndef MATH_INDEXING_H 2 #define MATH_INDEXING_H 4 #include "VectorTemplate.h" 5 #include "MatrixTemplate.h" 6 #include "SparseVectorTemplate.h" 28 for(
size_t i=0;i<indices.size();i++)
41 Assert((
int)indices.size() == fill.n);
42 for(
size_t i=0;i<indices.size();i++)
43 A(indices[i]) = fill(i);
50 Assert((
int)indices.size() == B.n);
51 for(
size_t i=0;i<indices.size();i++)
60 Assert(aindices.size() == bindices.size());
61 for(
size_t i=0;i<aindices.size();i++)
62 A(aindices[i]) = B(bindices[i]);
69 for(
size_t i=0;i<indices.size();i++) {
70 int start=indices[i]+1;
71 int end=(i+1==indices.size() ? A.n : indices[i+1]);
73 Assert(start > 0 && end <= A.n);
74 for(
int j=start;j<end;j++) {
78 A.n = A.n - (int)indices.size();
85 if(indices.empty())
return;
87 int curIndex=indices[0];
89 for(
typename SparseArray<T>::const_iterator i=A.begin();i!=A.end();i++) {
90 while(i->first>curIndex && curOffset < (
int)indices.size()) {
92 curIndex=indices[curOffset];
94 if(i->first != curIndex) {
95 Assert(i->first >= curOffset);
96 res.push_back(i->first-curOffset,i->second);
110 Assert(A.getCapacity() >= A.base + A.stride*(A.n+(int)indices.size()));
111 A.n = A.n + (int)indices.size();
113 for(
int i=(
int)indices.size()-1;i>=0;i--) {
114 int start=indices[i]+1;
115 int end=(i+1==(int)indices.size() ? A.n : indices[i+1]);
116 Assert(end >= start);
117 Assert(start > 0 && end <= A.n);
118 for(
int j=end-1;j>=start;j--) {
121 A(indices[i]) = fill;
129 for(
size_t i=0;i<indices.size();i++)
130 A.setRow(indices[i],fill);
139 for(
size_t i=0;i<rows.size();i++)
140 for(
size_t j=0;j<cols.size();j++)
141 A(rows[i],cols[j]) = fill;
154 Assert((
int)rows.size() == fill.m);
155 Assert((
int)cols.size() == fill.n);
156 for(
size_t i=0;i<rows.size();i++)
157 for(
size_t j=0;j<cols.size();j++)
158 A(rows[i],cols[j]) = fill(i,j);
165 Assert((
int)rows.size() == B.m);
166 Assert((
int)cols.size() == B.n);
167 for(
size_t i=0;i<rows.size();i++)
168 for(
size_t j=0;j<cols.size();j++)
169 B(i,j) = A(rows[i],cols[j]);
175 const std::vector<int>& arows,
const std::vector<int>& acols,
177 const std::vector<int>& brows,
const std::vector<int>& bcols)
179 Assert(arows.size() == brows.size());
180 Assert(acols.size() == bcols.size());
181 for(
size_t i=0;i<arows.size();i++)
182 for(
size_t j=0;j<acols.size();j++)
183 A(arows[i],acols[j]) = B(brows[i],bcols[j]);
190 for(
size_t i=0;i<rows.size();i++) {
191 int rstart=rows[i]+1;
192 int rend=(i+1==rows.size() ? A.m : rows[i+1]);
193 Assert(rend >= rstart);
194 Assert(rstart > 0 && rend <= A.m);
195 for(
size_t j=0;j<cols.size();j++) {
196 int cstart=cols[j]+1;
197 int cend=(j+1==cols.size() ? A.n : cols[i+1]);
198 Assert(cend >= cstart);
199 Assert(cstart > 0 && cend <= A.n);
200 for(
int k=rstart;k<rend;k++)
201 for(
int l=cstart;l<cend;l++)
202 A(k-i-1,l-j-1) = A(k,l);
205 A.m = A.m - (int)rows.size();
206 A.n = A.n - (int)cols.size();
214 for(
size_t i=0;i<indices.size();i++)
215 A.setCol(indices[i],fill);
222 for(
size_t i=0;i<indices.size();i++)
223 A.copyRow(indices[i],fill);
230 for(
size_t i=0;i<indices.size();i++)
231 A.copyColumn(indices[i],fill);
244 for(
size_t i=0;i<indices.size();i++) {
245 fill.getRowRef(i,filli);
246 A.copyRow(indices[i],filli);
260 for(
size_t i=0;i<indices.size();i++) {
261 fill.getColRef(i,filli);
262 A.copyColumn(indices[i],filli);
274 for(
size_t i=0;i<indices.size();i++) {
276 A.getRowCopy(indices[i],Bi);
288 for(
size_t i=0;i<indices.size();i++) {
290 A.getColCopy(indices[i],Bi);
299 for(
size_t i=0;i<indices.size();i++) {
300 int start=indices[i]+1;
301 int end=(i+1==indices.size() ? A.m : indices[i+1]);
302 Assert(end >= start);
303 Assert(start > 0 && end <= A.m);
304 for(
int j=start;j!=end;j++) {
306 A.getRowRef(j-i-1,dest);
310 A.m = A.m - (int)indices.size();
318 for(
size_t i=0;i<indices.size();i++) {
319 int start=indices[i]+1;
320 int end=(i+1==indices.size() ? A.n : indices[i+1]);
321 Assert(end >= start);
322 Assert(start > 0 && end <= A.n);
323 for(
int j=start;j<end;j++) {
325 A.getColRef(j-i-1,dest);
329 A.n = A.n - (int)indices.size();
336 for(
size_t i=0;i<indices.size();i++) {
337 int start=indices[i]+1;
338 int end=(i+1==indices.size() ? A.m : indices[i+1]);
339 Assert(end >= start);
340 Assert(start > 0 && end <= A.m);
341 for(
int j=start;j!=end;j++) {
343 A.rows[j-i-1].entries.clear();
344 A.rows[j-i-1].entries=A.rows[j].entries();
347 A.m = A.m - (int)indices.size();
354 for(
int i=0;i<A.m;i++)
356 A.n = A.n - (int)indices.size();
A sparse 1D array class.
Definition: SparseArray.h:13
void GetColumns(const MatrixTemplate< T > &A, const std::vector< int > &indices, MatrixTemplate< T > &B)
Copies the indexed columns in A into B.
Definition: math/indexing.h:285
void SetColumns(MatrixTemplate< T > &A, const std::vector< int > &indices, T fill)
Sets the indexed columns of A to fill.
Definition: math/indexing.h:212
Row-major sparse matrix.
Definition: SparseMatrixTemplate.h:44
void SetElements(VectorTemplate< T > &A, const std::vector< int > &indices, T fill)
Sets A[indices] = fill.
Definition: math/indexing.h:26
Several sparse matrix classes.
void RemoveElements(VectorTemplate< T > &A, const std::vector< int > &indices)
Removes the indexed elements of A (shrinking A)
Definition: math/indexing.h:67
void RemoveRows(MatrixTemplate< T > &A, const std::vector< int > &indices)
Removes the rows of A indexed by the sorted list indices.
Definition: math/indexing.h:296
void AddElements(VectorTemplate< T > &A, const std::vector< int > &indices, T fill)
The inverse of RemoveElements.
Definition: math/indexing.h:108
void RemoveColumns(MatrixTemplate< T > &A, const std::vector< int > &indices)
Removes the columns of A indexed by the sorted indices.
Definition: math/indexing.h:315
A matrix over the field T.
Definition: function.h:10
void GetRows(const MatrixTemplate< T > &A, const std::vector< int > &indices, MatrixTemplate< T > &B)
Copies the indexed rows in A into B.
Definition: math/indexing.h:271
Contains all definitions in the Math package.
Definition: WorkspaceBound.h:12
A vector over the field T.
Definition: function.h:9
void GetElements(const VectorTemplate< T > &A, const std::vector< int > &indices, VectorTemplate< T > &B)
Sets B = A[indices].
Definition: math/indexing.h:48
void SetRows(MatrixTemplate< T > &A, const std::vector< int > &indices, T fill)
Sets the indexed rows of A to fill.
Definition: math/indexing.h:127
void CopyElements(VectorTemplate< T > &A, const std::vector< int > &aindices, const VectorTemplate< T > &B, const std::vector< int > &bindices)
Sets A[aindices] = B[bindices].
Definition: math/indexing.h:57