This is an automated email from the ASF dual-hosted git repository. baunsgaard pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/systemds.git
The following commit(s) were added to refs/heads/main by this push: new 3e6e462854 [MINOR] Add general contains and specific contains nan on DenseBlock 3e6e462854 is described below commit 3e6e462854b1818893e86443aae858ae1cfc1088 Author: Sebastian Baunsgaard <baunsga...@apache.org> AuthorDate: Fri Apr 5 16:58:37 2024 +0200 [MINOR] Add general contains and specific contains nan on DenseBlock --- .../org/apache/sysds/runtime/data/DenseBlock.java | 34 ++++++++++++++++++++-- .../apache/sysds/runtime/data/DenseBlockBool.java | 2 +- .../apache/sysds/runtime/data/DenseBlockFP32.java | 2 +- .../apache/sysds/runtime/data/DenseBlockFP64.java | 2 +- .../sysds/runtime/data/DenseBlockFP64DEDUP.java | 2 +- .../apache/sysds/runtime/data/DenseBlockInt32.java | 2 +- .../apache/sysds/runtime/data/DenseBlockInt64.java | 2 +- .../apache/sysds/runtime/data/DenseBlockLBool.java | 2 +- .../apache/sysds/runtime/data/DenseBlockLFP32.java | 2 +- .../apache/sysds/runtime/data/DenseBlockLFP64.java | 2 +- .../sysds/runtime/data/DenseBlockLFP64DEDUP.java | 2 +- .../sysds/runtime/data/DenseBlockLInt32.java | 2 +- .../sysds/runtime/data/DenseBlockLInt64.java | 2 +- .../sysds/runtime/data/DenseBlockLString.java | 2 +- .../sysds/runtime/data/DenseBlockString.java | 2 +- 15 files changed, 46 insertions(+), 16 deletions(-) diff --git a/src/main/java/org/apache/sysds/runtime/data/DenseBlock.java b/src/main/java/org/apache/sysds/runtime/data/DenseBlock.java index 0a30d79250..0baf881936 100644 --- a/src/main/java/org/apache/sysds/runtime/data/DenseBlock.java +++ b/src/main/java/org/apache/sysds/runtime/data/DenseBlock.java @@ -67,6 +67,8 @@ public abstract class DenseBlock implements Serializable, Block /** * Get the ith dimensions size of the dense block. + * + * 0 is rows , 1 is cols, etc. * * @param i the number of dimension to get * @return the size of the dimension @@ -414,7 +416,7 @@ public abstract class DenseBlock implements Serializable, Block * @param toIndex ending index in block (exclusive) * @param v value */ - protected abstract void fillBlock(int bix, int fromIndex, int toIndex, double v); + public abstract void fillBlock(int bix, int fromIndex, int toIndex, double v); /** * Set a value at a position given by block index and index in that block. @@ -669,14 +671,42 @@ public abstract class DenseBlock implements Serializable, Block * @param ru row upper bound (exclusive) * @return true if pattern appears at least once, otherwise false */ + public boolean contains(double pattern, int rl, int ru) { boolean NaNpattern = Double.isNaN(pattern); int clen = _odims[0]; for(int i=rl; i<ru; i++) { double[] vals = values(i); int pos = pos(i); - for(int j=pos; j<pos+clen; j++) + for(int j=pos; j<pos+clen; j++){ if(vals[j]==pattern || (NaNpattern && Double.isNaN(vals[j]))) + return true; + } + } + return false; + } + + public boolean contains(double pattern) { + if(Double.isNaN(pattern)) + return containsNan(); + + for(int i = 0; i < numBlocks(); i++) { + double[] vals = valuesAt(i); + int len = size(i); + for(int j = 0; j < len; j++) + if(vals[j] == pattern) + return true; + } + return false; + } + + private boolean containsNan() { + for(int i = 0; i < numBlocks(); i++) { + final double[] vals = valuesAt(i); + final int len = size(i); + for(int j = 0; j < len; j++) + // nan Check is v != v + if(vals[j] != vals[j]) return true; } return false; diff --git a/src/main/java/org/apache/sysds/runtime/data/DenseBlockBool.java b/src/main/java/org/apache/sysds/runtime/data/DenseBlockBool.java index 247526701a..3d94fcf8af 100644 --- a/src/main/java/org/apache/sysds/runtime/data/DenseBlockBool.java +++ b/src/main/java/org/apache/sysds/runtime/data/DenseBlockBool.java @@ -142,7 +142,7 @@ public class DenseBlockBool extends DenseBlockDRB } @Override - protected void fillBlock(int bix, int fromIndex, int toIndex, double v) { + public void fillBlock(int bix, int fromIndex, int toIndex, double v) { _data.set(fromIndex, toIndex, v != 0); } diff --git a/src/main/java/org/apache/sysds/runtime/data/DenseBlockFP32.java b/src/main/java/org/apache/sysds/runtime/data/DenseBlockFP32.java index f435efacbd..519c17d83d 100644 --- a/src/main/java/org/apache/sysds/runtime/data/DenseBlockFP32.java +++ b/src/main/java/org/apache/sysds/runtime/data/DenseBlockFP32.java @@ -128,7 +128,7 @@ public class DenseBlockFP32 extends DenseBlockDRB } @Override - protected void fillBlock(int bix, int fromIndex, int toIndex, double v) { + public void fillBlock(int bix, int fromIndex, int toIndex, double v) { Arrays.fill(_data, fromIndex, toIndex, (float)v); } diff --git a/src/main/java/org/apache/sysds/runtime/data/DenseBlockFP64.java b/src/main/java/org/apache/sysds/runtime/data/DenseBlockFP64.java index f837e95820..eb93777fa4 100644 --- a/src/main/java/org/apache/sysds/runtime/data/DenseBlockFP64.java +++ b/src/main/java/org/apache/sysds/runtime/data/DenseBlockFP64.java @@ -135,7 +135,7 @@ public class DenseBlockFP64 extends DenseBlockDRB } @Override - protected void fillBlock(int bix, int fromIndex, int toIndex, double v) { + public void fillBlock(int bix, int fromIndex, int toIndex, double v) { Arrays.fill(_data, fromIndex, toIndex, v); } diff --git a/src/main/java/org/apache/sysds/runtime/data/DenseBlockFP64DEDUP.java b/src/main/java/org/apache/sysds/runtime/data/DenseBlockFP64DEDUP.java index af16ec3d85..2f3008c727 100644 --- a/src/main/java/org/apache/sysds/runtime/data/DenseBlockFP64DEDUP.java +++ b/src/main/java/org/apache/sysds/runtime/data/DenseBlockFP64DEDUP.java @@ -292,7 +292,7 @@ public class DenseBlockFP64DEDUP extends DenseBlockDRB } @Override - protected void fillBlock(int bix, int fromIndex, int toIndex, double v) { + public void fillBlock(int bix, int fromIndex, int toIndex, double v) { int roffset = fromIndex / _emb_size; int coffset = fromIndex % _emb_size; int r2offset = fromIndex / _emb_size; diff --git a/src/main/java/org/apache/sysds/runtime/data/DenseBlockInt32.java b/src/main/java/org/apache/sysds/runtime/data/DenseBlockInt32.java index 428c0b8f88..6f3c2a6622 100644 --- a/src/main/java/org/apache/sysds/runtime/data/DenseBlockInt32.java +++ b/src/main/java/org/apache/sysds/runtime/data/DenseBlockInt32.java @@ -128,7 +128,7 @@ public class DenseBlockInt32 extends DenseBlockDRB } @Override - protected void fillBlock(int bix, int fromIndex, int toIndex, double v) { + public void fillBlock(int bix, int fromIndex, int toIndex, double v) { Arrays.fill(_data, fromIndex, toIndex, UtilFunctions.toInt(v)); } diff --git a/src/main/java/org/apache/sysds/runtime/data/DenseBlockInt64.java b/src/main/java/org/apache/sysds/runtime/data/DenseBlockInt64.java index d61d78e2b9..ffe790e81a 100644 --- a/src/main/java/org/apache/sysds/runtime/data/DenseBlockInt64.java +++ b/src/main/java/org/apache/sysds/runtime/data/DenseBlockInt64.java @@ -129,7 +129,7 @@ public class DenseBlockInt64 extends DenseBlockDRB } @Override - protected void fillBlock(int bix, int fromIndex, int toIndex, double v) { + public void fillBlock(int bix, int fromIndex, int toIndex, double v) { Arrays.fill(_data, fromIndex, toIndex, UtilFunctions.toLong(v)); } diff --git a/src/main/java/org/apache/sysds/runtime/data/DenseBlockLBool.java b/src/main/java/org/apache/sysds/runtime/data/DenseBlockLBool.java index e49b3a9b7c..ab3bd98b9c 100644 --- a/src/main/java/org/apache/sysds/runtime/data/DenseBlockLBool.java +++ b/src/main/java/org/apache/sysds/runtime/data/DenseBlockLBool.java @@ -146,7 +146,7 @@ public class DenseBlockLBool extends DenseBlockLDRB } @Override - protected void fillBlock(int bix, int fromIndex, int toIndex, double v) { + public void fillBlock(int bix, int fromIndex, int toIndex, double v) { _blocks[bix].set(fromIndex, toIndex, v != 0); } diff --git a/src/main/java/org/apache/sysds/runtime/data/DenseBlockLFP32.java b/src/main/java/org/apache/sysds/runtime/data/DenseBlockLFP32.java index 266c9635eb..4122db2fae 100644 --- a/src/main/java/org/apache/sysds/runtime/data/DenseBlockLFP32.java +++ b/src/main/java/org/apache/sysds/runtime/data/DenseBlockLFP32.java @@ -109,7 +109,7 @@ public class DenseBlockLFP32 extends DenseBlockLDRB } @Override - protected void fillBlock(int bix, int fromIndex, int toIndex, double v) { + public void fillBlock(int bix, int fromIndex, int toIndex, double v) { Arrays.fill(_blocks[bix], fromIndex, toIndex, (float)v); } diff --git a/src/main/java/org/apache/sysds/runtime/data/DenseBlockLFP64.java b/src/main/java/org/apache/sysds/runtime/data/DenseBlockLFP64.java index 2ffac0468f..1d0bc3ccfb 100644 --- a/src/main/java/org/apache/sysds/runtime/data/DenseBlockLFP64.java +++ b/src/main/java/org/apache/sysds/runtime/data/DenseBlockLFP64.java @@ -101,7 +101,7 @@ public class DenseBlockLFP64 extends DenseBlockLDRB } @Override - protected void fillBlock(int bix, int fromIndex, int toIndex, double v) { + public void fillBlock(int bix, int fromIndex, int toIndex, double v) { Arrays.fill(_blocks[bix], fromIndex,toIndex, v); } diff --git a/src/main/java/org/apache/sysds/runtime/data/DenseBlockLFP64DEDUP.java b/src/main/java/org/apache/sysds/runtime/data/DenseBlockLFP64DEDUP.java index b12de816b2..79c02b7ac6 100644 --- a/src/main/java/org/apache/sysds/runtime/data/DenseBlockLFP64DEDUP.java +++ b/src/main/java/org/apache/sysds/runtime/data/DenseBlockLFP64DEDUP.java @@ -174,7 +174,7 @@ public class DenseBlockLFP64DEDUP extends DenseBlockLDRB{ } @Override - protected void fillBlock(int bix, int fromIndex, int toIndex, double v) { + public void fillBlock(int bix, int fromIndex, int toIndex, double v) { throw new NotImplementedException(); } diff --git a/src/main/java/org/apache/sysds/runtime/data/DenseBlockLInt32.java b/src/main/java/org/apache/sysds/runtime/data/DenseBlockLInt32.java index 826b73b142..0880440e46 100644 --- a/src/main/java/org/apache/sysds/runtime/data/DenseBlockLInt32.java +++ b/src/main/java/org/apache/sysds/runtime/data/DenseBlockLInt32.java @@ -105,7 +105,7 @@ public class DenseBlockLInt32 extends DenseBlockLDRB } @Override - protected void fillBlock(int bix, int fromIndex, int toIndex, double v) { + public void fillBlock(int bix, int fromIndex, int toIndex, double v) { Arrays.fill(_blocks[bix], fromIndex, toIndex, UtilFunctions.toInt(v)); } diff --git a/src/main/java/org/apache/sysds/runtime/data/DenseBlockLInt64.java b/src/main/java/org/apache/sysds/runtime/data/DenseBlockLInt64.java index 43228b18bc..d9ffc26176 100644 --- a/src/main/java/org/apache/sysds/runtime/data/DenseBlockLInt64.java +++ b/src/main/java/org/apache/sysds/runtime/data/DenseBlockLInt64.java @@ -105,7 +105,7 @@ public class DenseBlockLInt64 extends DenseBlockLDRB } @Override - protected void fillBlock(int bix, int fromIndex, int toIndex, double v) { + public void fillBlock(int bix, int fromIndex, int toIndex, double v) { Arrays.fill(_blocks[bix], fromIndex, toIndex, UtilFunctions.toLong(v)); } diff --git a/src/main/java/org/apache/sysds/runtime/data/DenseBlockLString.java b/src/main/java/org/apache/sysds/runtime/data/DenseBlockLString.java index 191017ae43..0ab267abec 100644 --- a/src/main/java/org/apache/sysds/runtime/data/DenseBlockLString.java +++ b/src/main/java/org/apache/sysds/runtime/data/DenseBlockLString.java @@ -105,7 +105,7 @@ public class DenseBlockLString extends DenseBlockLDRB } @Override - protected void fillBlock(int bix, int fromIndex, int toIndex, double v) { + public void fillBlock(int bix, int fromIndex, int toIndex, double v) { Arrays.fill(_blocks[bix], fromIndex, toIndex, String.valueOf(v)); } diff --git a/src/main/java/org/apache/sysds/runtime/data/DenseBlockString.java b/src/main/java/org/apache/sysds/runtime/data/DenseBlockString.java index 287c4d0f90..657a0f6559 100644 --- a/src/main/java/org/apache/sysds/runtime/data/DenseBlockString.java +++ b/src/main/java/org/apache/sysds/runtime/data/DenseBlockString.java @@ -114,7 +114,7 @@ public class DenseBlockString extends DenseBlockDRB { } @Override - protected void fillBlock(int bix, int fromIndex, int toIndex, double v) { + public void fillBlock(int bix, int fromIndex, int toIndex, double v) { Arrays.fill(_data, fromIndex, toIndex, String.valueOf(v)); }