diff --git a/src/main/java/org/apache/sysds/runtime/compress/colgroup/mapping/AMapToData.java b/src/main/java/org/apache/sysds/runtime/compress/colgroup/mapping/AMapToData.java index 683c231709e..5724509eac3 100644 --- a/src/main/java/org/apache/sysds/runtime/compress/colgroup/mapping/AMapToData.java +++ b/src/main/java/org/apache/sysds/runtime/compress/colgroup/mapping/AMapToData.java @@ -119,6 +119,18 @@ public void set(int n, Integer v) { */ public abstract void set(int n, int v); + /** + * set a range of values from another map. + * + * The given tm must only contain supported values, and it is not verified. + * + * @param l lower bound + * @param u upper bound (not inclusive) + * @param off offset to take values from tm + * @param tm the other map to copy values from + */ + public abstract void set(int l, int u, int off, AMapToData tm); + /** * Set the index to the value and get the contained value after. * diff --git a/src/main/java/org/apache/sysds/runtime/compress/colgroup/mapping/MapToBit.java b/src/main/java/org/apache/sysds/runtime/compress/colgroup/mapping/MapToBit.java index 1f37b71cbfa..9fd862bfd90 100644 --- a/src/main/java/org/apache/sysds/runtime/compress/colgroup/mapping/MapToBit.java +++ b/src/main/java/org/apache/sysds/runtime/compress/colgroup/mapping/MapToBit.java @@ -145,6 +145,13 @@ public void set(int n, int v) { _data[wIdx] &= ~(1L << n); } + @Override + public void set(int l, int u, int off, AMapToData tm){ + for(int i = l; i < u; i++, off++) { + set(i, tm.getIndex(off)); + } + } + @Override public int setAndGet(int n, int v) { set(n, v); diff --git a/src/main/java/org/apache/sysds/runtime/compress/colgroup/mapping/MapToByte.java b/src/main/java/org/apache/sysds/runtime/compress/colgroup/mapping/MapToByte.java index 413e1665176..3243f6e849a 100644 --- a/src/main/java/org/apache/sysds/runtime/compress/colgroup/mapping/MapToByte.java +++ b/src/main/java/org/apache/sysds/runtime/compress/colgroup/mapping/MapToByte.java @@ -95,6 +95,23 @@ public void set(int n, int v) { _data[n] = (byte) v; } + @Override + public void set(int l, int u, int off, AMapToData tm){ + if(tm instanceof MapToByte){ + MapToByte tbm = (MapToByte)tm; + byte[] tbv = tbm._data; + for(int i = l; i < u; i++, off++) { + _data[i] = tbv[off]; + } + } + else{ + + for(int i = l; i < u; i++, off++) { + _data[i] = (byte)tm.getIndex(off); + } + } + } + @Override public int setAndGet(int n, int v) { _data[n] = (byte) v; diff --git a/src/main/java/org/apache/sysds/runtime/compress/colgroup/mapping/MapToChar.java b/src/main/java/org/apache/sysds/runtime/compress/colgroup/mapping/MapToChar.java index c9d5c3b19fe..50e327ba5a2 100644 --- a/src/main/java/org/apache/sysds/runtime/compress/colgroup/mapping/MapToChar.java +++ b/src/main/java/org/apache/sysds/runtime/compress/colgroup/mapping/MapToChar.java @@ -100,6 +100,22 @@ public void set(int n, char v) { _data[n] = v; } + @Override + public void set(int l, int u, int off, AMapToData tm) { + if(tm instanceof MapToChar) { + MapToChar tbm = (MapToChar) tm; + char[] tbv = tbm._data; + for(int i = l; i < u; i++, off++) { + _data[i] = tbv[off]; + } + } + else { + for(int i = l; i < u; i++, off++) { + set(i, tm.getIndex(off)); + } + } + } + @Override public int setAndGet(int n, int v) { return _data[n] = (char) v; diff --git a/src/main/java/org/apache/sysds/runtime/compress/colgroup/mapping/MapToCharPByte.java b/src/main/java/org/apache/sysds/runtime/compress/colgroup/mapping/MapToCharPByte.java index c3d35ef4d68..4eca0754667 100644 --- a/src/main/java/org/apache/sysds/runtime/compress/colgroup/mapping/MapToCharPByte.java +++ b/src/main/java/org/apache/sysds/runtime/compress/colgroup/mapping/MapToCharPByte.java @@ -101,6 +101,13 @@ public void set(int n, int v) { _data_b[n] = (byte) (m >> 16); } + @Override + public void set(int l, int u, int off, AMapToData tm){ + for(int i = l; i < u; i++, off++) { + set(i, tm.getIndex(off)); + } + } + @Override public int setAndGet(int n, int v) { int m = v & 0xffffff; diff --git a/src/main/java/org/apache/sysds/runtime/compress/colgroup/mapping/MapToInt.java b/src/main/java/org/apache/sysds/runtime/compress/colgroup/mapping/MapToInt.java index e514cd07bd9..0d9a5ba2697 100644 --- a/src/main/java/org/apache/sysds/runtime/compress/colgroup/mapping/MapToInt.java +++ b/src/main/java/org/apache/sysds/runtime/compress/colgroup/mapping/MapToInt.java @@ -91,6 +91,13 @@ public void set(int n, int v) { _data[n] = v; } + @Override + public void set(int l, int u, int off, AMapToData tm){ + for(int i = l; i < u; i++, off++) { + set(i, tm.getIndex(off)); + } + } + @Override public int setAndGet(int n, int v) { return _data[n] = v; diff --git a/src/main/java/org/apache/sysds/runtime/compress/colgroup/mapping/MapToZero.java b/src/main/java/org/apache/sysds/runtime/compress/colgroup/mapping/MapToZero.java index c469e407c74..b76228ca0bb 100644 --- a/src/main/java/org/apache/sysds/runtime/compress/colgroup/mapping/MapToZero.java +++ b/src/main/java/org/apache/sysds/runtime/compress/colgroup/mapping/MapToZero.java @@ -74,6 +74,11 @@ public void set(int n, int v) { // do nothing } + @Override + public void set(int l, int u, int off, AMapToData tm){ + // do nothing + } + @Override public int setAndGet(int n, int v) { return 0; diff --git a/src/main/java/org/apache/sysds/runtime/frame/data/columns/DDCArray.java b/src/main/java/org/apache/sysds/runtime/frame/data/columns/DDCArray.java index eb3d98df5f1..7556d52978e 100644 --- a/src/main/java/org/apache/sysds/runtime/frame/data/columns/DDCArray.java +++ b/src/main/java/org/apache/sysds/runtime/frame/data/columns/DDCArray.java @@ -295,10 +295,7 @@ public void set(int rl, int ru, Array value, int rlSrc) { "\nmap1 unique: " + (map.getUnique()) + // "\nmap2 unique: " + (dc.map.getUnique())); - final AMapToData tm = dc.map; - for(int i = rl, off = rlSrc; i <= ru; i++, off++) { - map.set(i, tm.getIndex(off)); - } + map.set(rl, ru + 1, rlSrc, dc.map); } else throw new DMLCompressionException("Invalid to set value in CompressedArray");