Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sparsity iterators to Matrix<> #57

Closed
casadibot opened this issue Oct 31, 2012 · 1 comment
Closed

sparsity iterators to Matrix<> #57

casadibot opened this issue Oct 31, 2012 · 1 comment
Assignees
Milestone

Comments

@casadibot
Copy link
Member

The vector class has four functions to get iterators:
begin, end, rbegin, rend

each of these has a const version and a non-const version.

The Matrix<> class inherits these iterators, which is good, but should add two more sets of iterators, for rowind and col. The same should be done for CRSSparsity

Created by jaeandersson at: 2011-01-12T14:31:07
Last updated at: 2012-02-27T20:59:00


Comment 1 by jgillis at 2012-02-27T20:54:21

Conversion to python iterators seems fairly easy to achieve: http://reference-man.blogspot.com/2010/02/easy-python-generators-using-swig.html


Comment 2 by jgillis at 2012-02-27T20:59:00

A typical use case:

// Loop over rows
for(int i=0; i<ret.size1(); ++i){
// Loop over nonzeros
for(int el=ret.rowind(i); el<ret.rowind(i+1); ++el){
// Get column
int j=ret.col(el);

// Get the nonzero of the dense matrix
int el_dense = j+i*ret.size2();

// Save to mapping
mapping_dense[el_dense] = mapping[el];
}
}

becomes (pseudo-ish code):

// Loop over rows
for (it = ret.NZ()) {
// Get the nonzero of the dense matrix
int el_dense = it->col + (it->row)*ret.size2();

// Save to mapping
mapping_dense[it.dense] = mapping[el];
}
@jaeandersson
Copy link
Member

Looks unlikely to ever get implemented. Reopen if needed.

shrenikm-bc pushed a commit to braincorp/casadi that referenced this issue Mar 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants