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

Update set method for sparse to only add non-zero elements #145

Open
wants to merge 2 commits into
base: SNAPSHOT
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion main/ejml-core/src/org/ejml/data/DMatrixSparseCSC.java
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,9 @@ public void set( int row, int col, double val ) {
if (row < 0 || row >= numRows || col < 0 || col >= numCols)
throw new IllegalArgumentException("Outside of matrix bounds");

unsafe_set(row, col, val);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see comments for triplet below.

if (val != 0.0) {
unsafe_set(row, col, val);
}
}

@Override
Expand Down
6 changes: 4 additions & 2 deletions main/ejml-core/src/org/ejml/data/DMatrixSparseTriplet.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,9 @@ public void set( int row, int col, double value ) {
if (row < 0 || row >= numRows || col < 0 || col >= numCols)
throw new IllegalArgumentException("Outside of matrix bounds");

unsafe_set(row, col, value);
if (value != 0.0) {
unsafe_set(row, col, value);
}
}

/**
Expand All @@ -169,7 +171,7 @@ public void unsafe_set( int row, int col, double value ) {
int index = nz_index(row, col);
if (index < 0)
addItem(row, col, value);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not in the graph structure so you could check to see if it's zero here and not add it.

else {
else if (value != 0.0) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already in the graph structure so you want to update the value.

nz_value.data[index] = value;
}
}
Expand Down