Skip to content

Commit

Permalink
[MINOR] Add LibReplace for MatrixBlock
Browse files Browse the repository at this point in the history
Adds a Lib class for replace.

The main benefit in this commit is when we perform
replacement on a sparse matrix, and the output is dense.

after:

```
java -jar target/systemds-3.3.0-SNAPSHOT-perf.jar 17 10000 10000 0.1 16
Profiling started
                        replaceZero,  132.883+-  9.335 ms,
                         replaceOne,   59.612+-  3.295 ms,
                         replaceNaN,   10.651+-  0.470 ms,
```

before:

```
java -jar target/systemds-3.3.0-SNAPSHOT-perf.jar 17 10000 10000 0.1 16
Profiling started
                        replaceZero,  228.727+- 11.965 ms,
                         replaceOne,  163.212+-  4.993 ms,
                         replaceNaN,   10.602+-  0.437 ms,
```

Closes apache#2043
  • Loading branch information
Baunsgaard committed Jul 4, 2024
1 parent a95effa commit 3537383
Show file tree
Hide file tree
Showing 19 changed files with 400 additions and 87 deletions.
7 changes: 7 additions & 0 deletions src/main/java/org/apache/sysds/runtime/data/DenseBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,13 @@ public final long size() {
*/
public abstract void fillBlock(int bix, int fromIndex, int toIndex, double v);

/**
* Fill the DenseBlock row index with the value specified.
* @param r The row to fill
* @param v The value to fill it with.
*/
public abstract void fillRow(int r, double v);

/**
* Set a value at a position given by block index and index in that block.
* @param bix block index
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,13 @@ public void fillBlock(int bix, int fromIndex, int toIndex, double v) {
_data.set(fromIndex, toIndex, v != 0);
}

@Override
public void fillRow(int r, double v){
int start = pos(r);
int end = start + getDim(1);
_data.set(start, end, v != 0);
}

@Override
protected void setInternal(int bix, int ix, double v) {
_data.set(ix, v != 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,13 @@ public void fillBlock(int bix, int fromIndex, int toIndex, double v) {
Arrays.fill(_data, fromIndex, toIndex, (float)v);
}

@Override
public void fillRow(int r, double v){
int start = pos(r);
int end = start + getDim(1);
Arrays.fill(_data, start, end, (float)v);
}

@Override
protected void setInternal(int bix, int ix, double v) {
_data[ix] = (float)v;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,14 @@ public void fillBlock(int bix, int fromIndex, int toIndex, double v) {
Arrays.fill(_data, fromIndex, toIndex, v);
}

@Override
public void fillRow(int r, double v){
int start = pos(r);
int end = start + getDim(1);
Arrays.fill(_data, start, end, v);
}


@Override
protected void setInternal(int bix, int ix, double v) {
_data[ix] = v;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,12 @@ public void fillBlock(int bix, int fromIndex, int toIndex, double v) {
}
}

@Override
public void fillRow(int r, double v){
throw new NotImplementedException();
}


@Override
protected void setInternal(int bix, int ix, double v) {
set(bix, ix, v);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,13 @@ public void fillBlock(int bix, int fromIndex, int toIndex, double v) {
Arrays.fill(_data, fromIndex, toIndex, UtilFunctions.toInt(v));
}

@Override
public void fillRow(int r, double v){
int start = pos(r);
int end = start + getDim(1);
Arrays.fill(_data, start, end, UtilFunctions.toInt(v));
}

@Override
protected void setInternal(int bix, int ix, double v) {
_data[ix] = UtilFunctions.toInt(v);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,14 @@ public void fillBlock(int bix, int fromIndex, int toIndex, double v) {
Arrays.fill(_data, fromIndex, toIndex, UtilFunctions.toLong(v));
}

@Override
public void fillRow(int r, double v){
int start = pos(r);
int end = start + getDim(1);
Arrays.fill(_data, start, end, UtilFunctions.toLong(v));
}


@Override
protected void setInternal(int bix, int ix, double v) {
_data[ix] = UtilFunctions.toLong(v);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,13 @@ public void fillBlock(int bix, int fromIndex, int toIndex, double v) {
_blocks[bix].set(fromIndex, toIndex, v != 0);
}

@Override
public void fillRow(int r, double v){
int start = pos(r);
int end = start + getDim(1);
_blocks[index(r)].set(start, end, v != 0);
}

@Override
public DenseBlock set(String s) {
boolean b = Boolean.parseBoolean(s);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,13 @@ public void fillBlock(int bix, int fromIndex, int toIndex, double v) {
Arrays.fill(_blocks[bix], fromIndex, toIndex, (float)v);
}

@Override
public void fillRow(int r, double v){
int start = pos(r);
int end = start + getDim(1);
Arrays.fill(_blocks[index(r)],start, end, (float)v);
}

@Override
public DenseBlock set(int r, int c, double v) {
_blocks[index(r)][pos(r, c)] = (float)v;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,13 @@ public void fillBlock(int bix, int fromIndex, int toIndex, double v) {
Arrays.fill(_blocks[bix], fromIndex,toIndex, v);
}

@Override
public void fillRow(int r, double v){
int start = pos(r);
int end = start + getDim(1);
Arrays.fill(_blocks[index(r)],start, end, v);
}

@Override
public DenseBlock set(int r, int c, double v) {
_blocks[index(r)][pos(r, c)] = v;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@ public void fillBlock(int bix, int fromIndex, int toIndex, double v) {
throw new NotImplementedException();
}

@Override
public void fillRow(int r, double v){
throw new NotImplementedException();
}

@Override
protected void setInternal(int bix, int ix, double v) {
throw new NotImplementedException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,13 @@ public void fillBlock(int bix, int fromIndex, int toIndex, double v) {
Arrays.fill(_blocks[bix], fromIndex, toIndex, UtilFunctions.toInt(v));
}

@Override
public void fillRow(int r, double v){
int start = pos(r);
int end = start + getDim(1);
Arrays.fill(_blocks[index(r)], start, end, UtilFunctions.toInt(v));
}

@Override
public DenseBlock set(int r, int c, double v) {
_blocks[index(r)][pos(r, c)] = UtilFunctions.toInt(v);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,13 @@ public void fillBlock(int bix, int fromIndex, int toIndex, double v) {
Arrays.fill(_blocks[bix], fromIndex, toIndex, UtilFunctions.toLong(v));
}

@Override
public void fillRow(int r, double v){
int start = pos(r);
int end = start + getDim(1);
Arrays.fill(_blocks[index(r)], start, end, UtilFunctions.toLong(v));
}

@Override
public DenseBlock set(int r, int c, double v) {
_blocks[index(r)][pos(r, c)] = UtilFunctions.toLong(v);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,13 @@ public void fillBlock(int bix, int fromIndex, int toIndex, double v) {
Arrays.fill(_blocks[bix], fromIndex, toIndex, String.valueOf(v));
}

@Override
public void fillRow(int r, double v){
int start = pos(r);
int end = start + getDim(1);
Arrays.fill(_blocks[index(r)], start, end, String.valueOf(v));
}

@Override
public DenseBlock set(String s) {
for (int i = 0; i < numBlocks() - 1; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,14 @@ public void fillBlock(int bix, int fromIndex, int toIndex, double v) {
Arrays.fill(_data, fromIndex, toIndex, String.valueOf(v));
}

@Override
public void fillRow(int r, double v){
int start = pos(r);
int end = start + getDim(1);
Arrays.fill(_data, start, end, String.valueOf(v));
}


@Override
protected void setInternal(int bix, int ix, double v) {
_data[ix] = String.valueOf(v);
Expand Down
Loading

0 comments on commit 3537383

Please sign in to comment.