Skip to content

Commit

Permalink
tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
ananyashreyjain committed Mar 19, 2019
1 parent e9638ac commit 94e8fa0
Showing 1 changed file with 140 additions and 139 deletions.
279 changes: 140 additions & 139 deletions scipy/sparse/sparsetools/csr.h
Original file line number Diff line number Diff line change
Expand Up @@ -706,9 +706,9 @@ void csr_binop_csr_general(const I n_row, const I n_col,
Cp[0] = 0;
bool addsub = false;

//checks the type of binary operation to be performed.
//checks the type of binary operation to be performed.
if((int)op(8,4) == 12 || (int)op(8,4) == 4)
addsub=true;
addsub=true;

for(I i = 0; i < n_row; i++){
I head = -2;
Expand Down Expand Up @@ -744,45 +744,45 @@ void csr_binop_csr_general(const I n_row, const I n_col,
}
}

if (!addsub)
if (!addsub)
// scan through columns where binary operations
// on A and B has contributed a non-zero entry.
for(I jj = 0; jj < length; jj++){
T result = op(A_row[head], B_row[head]);

if(result != 0){
Cj[nnz] = head;
Cx[nnz] = result;
nnz++;
}

I temp = head;
head = next[head];

next[temp] = -1;
A_row[temp] = 0;
B_row[temp] = 0;
}
else
// scan through columns where operations of addition or
for(I jj = 0; jj < length; jj++){
T result = op(A_row[head], B_row[head]);

if(result != 0){
Cj[nnz] = head;
Cx[nnz] = result;
nnz++;
}

I temp = head;
head = next[head];

next[temp] = -1;
A_row[temp] = 0;
B_row[temp] = 0;
}
else
// scan through columns where operations of addition or
// subtraction on A and B has contributed a non-zero entry.
for(I jj = 0; jj < length; jj++){
T result = op(A_row[head], B_row[head]);
//if result is zero and A_row is also zero
//implies the Bx is zero and vice-versa.
if(result != 0 || A_row[head] == 0){
Cj[nnz] = head;
Cx[nnz] = result;
nnz++;
}

I temp = head;
head = next[head];

next[temp] = -1;
A_row[temp] = 0;
B_row[temp] = 0;
}
for(I jj = 0; jj < length; jj++){
T result = op(A_row[head], B_row[head]);
//if result is zero and A_row is also zero
//implies the Bx is zero and vice-versa.
if(result != 0 || A_row[head] == 0){
Cj[nnz] = head;
Cx[nnz] = result;
nnz++;
}

I temp = head;
head = next[head];

next[temp] = -1;
A_row[temp] = 0;
B_row[temp] = 0;
}

Cp[i + 1] = nnz;
}
Expand Down Expand Up @@ -817,9 +817,9 @@ void csr_binop_csr_canonical(const I n_row, const I n_col,
I nnz = 0;
bool addsub = false;

//checks the type of binary operation to be performed.
//checks the type of binary operation to be performed.
if((int)op(8,4) == 12 || (int)op(8,4) == 4)
addsub=true;
addsub=true;

for(I i = 0; i < n_row; i++){
I A_pos = Ap[i];
Expand All @@ -828,109 +828,109 @@ void csr_binop_csr_canonical(const I n_row, const I n_col,
I B_end = Bp[i+1];

if(!addsub)
//while not finished with either row.
while(A_pos < A_end && B_pos < B_end){
I A_j = Aj[A_pos];
I B_j = Bj[B_pos];

if(A_j == B_j){
T result = op(Ax[A_pos],Bx[B_pos]);
//removes the zeros generated in
//the binary operation.
if(result != 0){
Cj[nnz] = A_j;
Cx[nnz] = result;
nnz++;
}
A_pos++;
B_pos++;
} else if (A_j < B_j) {
T result = op(Ax[A_pos],0);
if(result!=0) {
Cj[nnz] = A_j;
Cx[nnz] = result;
nnz++;
}
A_pos++;
} else {
//B_j < A_j
T result = op(0,Bx[B_pos]);
if(result!=0) {
Cj[nnz] = B_j;
Cx[nnz] = result;
nnz++;
}
B_pos++;
}
}
//operations of addition and subtraction will
//be performed in this block.
else
//while not finished with either row.
while(A_pos < A_end && B_pos < B_end){
I A_j = Aj[A_pos];
I B_j = Bj[B_pos];

if(A_j == B_j){
T result = op(Ax[A_pos],Bx[B_pos]);
//removes the implicit zeros generated in
//the binary operation.
if(result != 0 || Ax[A_pos] == 0){
Cj[nnz] = A_j;
Cx[nnz] = result;
nnz++;
}
A_pos++;
B_pos++;
} else if (A_j < B_j) {
Cj[nnz] = A_j;
Cx[nnz] = Ax[A_pos];
nnz++;
A_pos++;
} else {
//B_j < A_j
Cj[nnz] = B_j;
Cx[nnz] = Bx[B_pos];
nnz++;
B_pos++;
}
}
//while not finished with either row.
while(A_pos < A_end && B_pos < B_end){
I A_j = Aj[A_pos];
I B_j = Bj[B_pos];

if(A_j == B_j){
T result = op(Ax[A_pos],Bx[B_pos]);
//removes the zeros generated in
//the binary operation.
if(result != 0){
Cj[nnz] = A_j;
Cx[nnz] = result;
nnz++;
}
A_pos++;
B_pos++;
} else if (A_j < B_j) {
T result = op(Ax[A_pos],0);
if(result!=0) {
Cj[nnz] = A_j;
Cx[nnz] = result;
nnz++;
}
A_pos++;
} else {
//B_j < A_j
T result = op(0,Bx[B_pos]);
if(result!=0) {
Cj[nnz] = B_j;
Cx[nnz] = result;
nnz++;
}
B_pos++;
}
}
//operations of addition and subtraction will
//be performed in this block.
else
//while not finished with either row.
while(A_pos < A_end && B_pos < B_end){
I A_j = Aj[A_pos];
I B_j = Bj[B_pos];

if(A_j == B_j){
T result = op(Ax[A_pos],Bx[B_pos]);
//removes the implicit zeros generated in
//the binary operation.
if(result != 0 || Ax[A_pos] == 0){
Cj[nnz] = A_j;
Cx[nnz] = result;
nnz++;
}
A_pos++;
B_pos++;
} else if (A_j < B_j) {
Cj[nnz] = A_j;
Cx[nnz] = Ax[A_pos];
nnz++;
A_pos++;
} else {
//B_j < A_j
Cj[nnz] = B_j;
Cx[nnz] = Bx[B_pos];
nnz++;
B_pos++;
}
}

//tail
if(!addsub){
while(A_pos < A_end){
T result = op(Ax[A_pos],Bx[B_pos]);
if(result!=0) {
Cj[nnz] = Aj[A_pos];
Cx[nnz] = result;
nnz++;
}
A_pos++;
}
while(B_pos < B_end){
T result = op(Ax[A_pos],Bx[B_pos]);
if(result!=0) {
Cj[nnz] = Bj[B_pos];
Cx[nnz] = result;
nnz++;
}
B_pos++;
}
//tail for addition and subtraction
while(A_pos < A_end){
T result = op(Ax[A_pos],Bx[B_pos]);
if(result!=0) {
Cj[nnz] = Aj[A_pos];
Cx[nnz] = result;
nnz++;
}
A_pos++;
}
while(B_pos < B_end){
T result = op(Ax[A_pos],Bx[B_pos]);
if(result!=0) {
Cj[nnz] = Bj[B_pos];
Cx[nnz] = result;
nnz++;
}
B_pos++;
}
//tail for addition and subtraction
} else{
while(A_pos < A_end){
Cj[nnz] = Aj[A_pos];
Cx[nnz] = Ax[A_pos];
nnz++;
A_pos++;
}
while(B_pos < B_end){
Cj[nnz] = Bj[B_pos];
Cx[nnz] = Bx[B_pos];
nnz++;
B_pos++;
}
}
while(A_pos < A_end){
Cj[nnz] = Aj[A_pos];
Cx[nnz] = Ax[A_pos];
nnz++;
A_pos++;
}
while(B_pos < B_end){
Cj[nnz] = Bj[B_pos];
Cx[nnz] = Bx[B_pos];
nnz++;
B_pos++;
}
}

Cp[i+1] = nnz;
}
Expand Down Expand Up @@ -1715,3 +1715,4 @@ int test_throw_error() {
}

#endif

0 comments on commit 94e8fa0

Please sign in to comment.