You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@systemds.apache.org by GitBox <gi...@apache.org> on 2020/10/19 13:06:14 UTC

[GitHub] [systemds] OlgaOvcharenko opened a new pull request #1081: [SYSTEMDS-2548] Federated right indexing

OlgaOvcharenko opened a new pull request #1081:
URL: https://github.com/apache/systemds/pull/1081


   This PR adds federated right indexing.
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [systemds] Baunsgaard commented on a change in pull request #1081: [SYSTEMDS-2548] Federated right indexing

Posted by GitBox <gi...@apache.org>.
Baunsgaard commented on a change in pull request #1081:
URL: https://github.com/apache/systemds/pull/1081#discussion_r519772273



##########
File path: src/main/java/org/apache/sysds/runtime/instructions/fed/MatrixIndexingFEDInstruction.java
##########
@@ -0,0 +1,196 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sysds.runtime.instructions.fed;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.sysds.runtime.DMLRuntimeException;
+import org.apache.sysds.runtime.controlprogram.caching.MatrixObject;
+import org.apache.sysds.runtime.controlprogram.context.ExecutionContext;
+import org.apache.sysds.runtime.controlprogram.federated.FederatedRequest;
+import org.apache.sysds.runtime.controlprogram.federated.FederatedResponse;
+import org.apache.sysds.runtime.controlprogram.federated.FederatedUDF;
+import org.apache.sysds.runtime.controlprogram.federated.FederationMap;
+import org.apache.sysds.runtime.controlprogram.federated.FederationUtils;
+import org.apache.sysds.runtime.instructions.cp.CPOperand;
+import org.apache.sysds.runtime.instructions.cp.Data;
+import org.apache.sysds.runtime.matrix.data.MatrixBlock;
+import org.apache.sysds.runtime.util.IndexRange;
+
+public final class MatrixIndexingFEDInstruction extends IndexingFEDInstruction {
+	private static final Log LOG = LogFactory.getLog(MatrixIndexingFEDInstruction.class.getName());
+
+	public MatrixIndexingFEDInstruction(CPOperand in, CPOperand rl, CPOperand ru, CPOperand cl, CPOperand cu,
+		CPOperand out, String opcode, String istr) {
+		super(in, rl, ru, cl, cu, out, opcode, istr);
+	}
+
+	@Override
+	public void processInstruction(ExecutionContext ec) {
+		rightIndexing(ec);
+	}
+
+	private void rightIndexing (ExecutionContext ec) {
+		MatrixObject in = ec.getMatrixObject(input1);
+		FederationMap fedMapping = in.getFedMapping();
+		IndexRange ixrange = getIndexRange(ec);
+		FederationMap.FType fedType = fedMapping.getType();
+		Map <String, IndexRange> ixs = new HashMap<>();
+
+		long[] lastEndDim = new long[2];
+		long[] lastBeginDim = new long[2];
+
+		for (int i = 0; i < fedMapping.getFederatedRanges().length; i++) {
+			long rs = fedMapping.getFederatedRanges()[i].getBeginDims()[0], re = fedMapping.getFederatedRanges()[i]
+				.getEndDims()[0], cs = fedMapping.getFederatedRanges()[i].getBeginDims()[1], ce = fedMapping.getFederatedRanges()[i].getEndDims()[1];
+
+			long rsn = 0, ren = 0, csn = 0, cen = 0;
+
+			switch(fedType) {
+				case ROW:

Review comment:
       I Still don't get why you would need different handling depending on row, column or other.
   I would assume that one implementation should be sufficient, and then afterwards detect which type the result federated object is.

##########
File path: src/main/java/org/apache/sysds/runtime/instructions/fed/MatrixIndexingFEDInstruction.java
##########
@@ -0,0 +1,196 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sysds.runtime.instructions.fed;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.sysds.runtime.DMLRuntimeException;
+import org.apache.sysds.runtime.controlprogram.caching.MatrixObject;
+import org.apache.sysds.runtime.controlprogram.context.ExecutionContext;
+import org.apache.sysds.runtime.controlprogram.federated.FederatedRequest;
+import org.apache.sysds.runtime.controlprogram.federated.FederatedResponse;
+import org.apache.sysds.runtime.controlprogram.federated.FederatedUDF;
+import org.apache.sysds.runtime.controlprogram.federated.FederationMap;
+import org.apache.sysds.runtime.controlprogram.federated.FederationUtils;
+import org.apache.sysds.runtime.instructions.cp.CPOperand;
+import org.apache.sysds.runtime.instructions.cp.Data;
+import org.apache.sysds.runtime.matrix.data.MatrixBlock;
+import org.apache.sysds.runtime.util.IndexRange;
+
+public final class MatrixIndexingFEDInstruction extends IndexingFEDInstruction {
+	private static final Log LOG = LogFactory.getLog(MatrixIndexingFEDInstruction.class.getName());
+
+	public MatrixIndexingFEDInstruction(CPOperand in, CPOperand rl, CPOperand ru, CPOperand cl, CPOperand cu,
+		CPOperand out, String opcode, String istr) {
+		super(in, rl, ru, cl, cu, out, opcode, istr);
+	}
+
+	@Override
+	public void processInstruction(ExecutionContext ec) {
+		rightIndexing(ec);
+	}
+
+	private void rightIndexing (ExecutionContext ec) {
+		MatrixObject in = ec.getMatrixObject(input1);
+		FederationMap fedMapping = in.getFedMapping();
+		IndexRange ixrange = getIndexRange(ec);
+		FederationMap.FType fedType = fedMapping.getType();
+		Map <String, IndexRange> ixs = new HashMap<>();
+
+		long[] lastEndDim = new long[2];
+		long[] lastBeginDim = new long[2];
+
+		for (int i = 0; i < fedMapping.getFederatedRanges().length; i++) {
+			long rs = fedMapping.getFederatedRanges()[i].getBeginDims()[0], re = fedMapping.getFederatedRanges()[i]
+				.getEndDims()[0], cs = fedMapping.getFederatedRanges()[i].getBeginDims()[1], ce = fedMapping.getFederatedRanges()[i].getEndDims()[1];
+
+			long rsn = 0, ren = 0, csn = 0, cen = 0;
+
+			switch(fedType) {
+				case ROW:
+					rsn = (ixrange.rowStart >= rs && ixrange.rowStart < re) ? (ixrange.rowStart - rs) : 0;
+					ren = (ixrange.rowEnd >= rs && ixrange.rowEnd < re) ? (ixrange.rowEnd - rs) : (re - rs - 1);
+					csn = ixrange.colStart;
+					cen = ixrange.colEnd;
+
+					if((ixrange.rowStart < re) && (ixrange.rowEnd >= rs)) {
+						fedMapping.getFederatedRanges()[i].setBeginDim(0, i != 0 ? fedMapping.getFederatedRanges()[i - 1].getEndDims()[0] : 0);
+						fedMapping.getFederatedRanges()[i].setEndDim(0, ren - rsn + 1 + (i == 0 ? 0 : fedMapping.getFederatedRanges()[i - 1].getEndDims()[0]));
+						fedMapping.getFederatedRanges()[i].setEndDim(1, cen - csn + 1);
+					}
+					else {
+						fedMapping.getFederatedRanges()[i].setBeginDim(0, i != 0 ? fedMapping.getFederatedRanges()[i - 1].getEndDims()[0] : 0);
+						fedMapping.getFederatedRanges()[i].setEndDim(0, fedMapping.getFederatedRanges()[i].getBeginDims()[0]);
+						fedMapping.getFederatedRanges()[i].setEndDim(1, cen - csn + 1);
+						rsn = -1;
+						ren = rsn;
+						csn = rsn;
+						cen = rsn;
+					}
+
+					break;
+				case COL:
+					rsn = ixrange.rowStart;
+					ren = ixrange.rowEnd;
+					csn = (ixrange.colStart >= cs && ixrange.colStart < ce) ? (ixrange.colStart - cs) : 0;
+					cen = (ixrange.colEnd >= cs && ixrange.colEnd < ce) ? (ixrange.colEnd - cs) : (ce - cs - 1);
+					if((ixrange.colStart < ce) && (ixrange.colEnd >= cs)) {
+						fedMapping.getFederatedRanges()[i].setBeginDim(1, i != 0 ? fedMapping.getFederatedRanges()[i - 1].getEndDims()[1] : 0);
+						fedMapping.getFederatedRanges()[i].setEndDim(0, ren - rsn + 1);
+						fedMapping.getFederatedRanges()[i].setEndDim(1, cen - csn + 1 + (i == 0 ? 0 : fedMapping.getFederatedRanges()[i - 1].getEndDims()[1]));
+					}
+					else {
+						fedMapping.getFederatedRanges()[i].setBeginDim(1, i != 0 ? fedMapping.getFederatedRanges()[i - 1].getEndDims()[1] : 0);
+						fedMapping.getFederatedRanges()[i].setEndDim(0, ren - rsn + 1);
+						fedMapping.getFederatedRanges()[i].setEndDim(1, fedMapping.getFederatedRanges()[i].getBeginDims()[1]);
+						rsn = -1;
+						ren = rsn;
+						csn = rsn;
+						cen = rsn;
+					}
+					break;
+				case OTHER:
+					rsn = (ixrange.rowStart >= rs && ixrange.rowStart < re) ? (ixrange.rowStart - rs) : 0;
+					ren = (ixrange.rowEnd >= rs && ixrange.rowEnd < re) ? (ixrange.rowEnd - rs) : (re - rs - 1);
+					csn = (ixrange.colStart >= cs && ixrange.colStart < ce) ? (ixrange.colStart - cs) : 0;
+					cen = (ixrange.colEnd >= cs && ixrange.colEnd < ce) ? (ixrange.colEnd - cs) : (ce - cs - 1);
+
+					if((ixrange.colStart < ce) && (ixrange.colEnd >= cs) && (ixrange.rowStart < re) && (ixrange.rowEnd >= rs)) {
+						if (fedMapping.getFederatedRanges()[i-1].getSize() != 0 || lastEndDim[0] + lastEndDim[1] == 0) {
+							fedMapping.getFederatedRanges()[i].setBeginDim(0, i != 0 ? fedMapping.getFederatedRanges()[i - 1].getEndDims()[0] : 0);
+							fedMapping.getFederatedRanges()[i].setBeginDim(1, i != 0 ? fedMapping.getFederatedRanges()[i - 1].getEndDims()[1] : 0);
+							fedMapping.getFederatedRanges()[i].setEndDim(0, ren - rsn + 1 + (i == 0 ? 0 : fedMapping.getFederatedRanges()[i - 1].getEndDims()[0]));
+							fedMapping.getFederatedRanges()[i].setEndDim(1, cen - csn + 1 + (i == 0 ? 0 : fedMapping.getFederatedRanges()[i - 1].getEndDims()[1]));
+						} else {
+							fedMapping.getFederatedRanges()[i].setBeginDim(0, 1 + ren - rsn + lastBeginDim[0]);
+							fedMapping.getFederatedRanges()[i].setBeginDim(1, cen - csn + lastBeginDim[1]);
+							fedMapping.getFederatedRanges()[i].setEndDim(0, 1 + ren - rsn + lastEndDim[0]);
+							fedMapping.getFederatedRanges()[i].setEndDim(1, cen - csn + lastEndDim[1]);
+						}
+						lastEndDim = fedMapping.getFederatedRanges()[i].getEndDims();
+						lastBeginDim = fedMapping.getFederatedRanges()[i].getBeginDims();
+					}
+					else {
+						fedMapping.getFederatedRanges()[i].setBeginDim(0, i != 0 ? fedMapping.getFederatedRanges()[i - 1].getEndDims()[0] : 0);
+						fedMapping.getFederatedRanges()[i].setEndDim(0, fedMapping.getFederatedRanges()[i].getBeginDims()[0]);
+
+						fedMapping.getFederatedRanges()[i].setBeginDim(1, i != 0 ? fedMapping.getFederatedRanges()[i - 1].getEndDims()[1] : 0);
+						fedMapping.getFederatedRanges()[i].setEndDim(1, fedMapping.getFederatedRanges()[i].getBeginDims()[1]);
+
+						rsn = -1;
+						ren = rsn;
+						csn = rsn;
+						cen = rsn;
+					}
+			}
+			ixs.put(fedMapping.getFederatedRanges()[i].toString(), new IndexRange(rsn, ren, csn, cen));
+		}
+//		List<MatrixBlock> mb = new ArrayList<>();
+		long varID = FederationUtils.getNextFedDataID();
+		FederationMap sortedMapping = fedMapping.mapParallel(varID, (range, data) -> {
+			try {
+				FederatedResponse response = data
+					.executeFederatedOperation(new FederatedRequest(FederatedRequest.RequestType.EXEC_UDF, -1,
+						new SliceMatrix(data.getVarID(), varID, ixs.get(range.toString())))).get();

Review comment:
       I think you can use the Federated Range object it self to look up the entries, instead of the to string of it.
   

##########
File path: src/test/scripts/functions/federated/indexing/FederatedRightIndexFullTest.dml
##########
@@ -0,0 +1,37 @@
+#-------------------------------------------------------------
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#-------------------------------------------------------------
+
+from = $from;
+to = $to;
+
+if ($rP) {
+    A = federated(addresses=list($in_X1, $in_X2, $in_X3, $in_X4),
+        ranges=list(list(0, 0), list($rows/4, $cols), list($rows/4, 0), list(2*$rows/4, $cols),
+    		list(2*$rows/4, 0), list(3*$rows/4, $cols), list(3*$rows/4, 0), list($rows, $cols)));
+} else {
+    A = federated(addresses=list($in_X1, $in_X2, $in_X3, $in_X4),
+            ranges=list(list(0, 0), list($rows, $cols/4), list(0,$cols/4), list($rows, $cols/2),
+            	list(0,$cols/2), list($rows, 3*($cols/4)), list(0, 3*($cols/4)), list($rows, $cols)));
+}
+
+s = A[from:to, from:to];
+
+write(s, $out_S);

Review comment:
       newline

##########
File path: src/test/java/org/apache/sysds/test/functions/federated/algorithms/FederatedBivarTest.java
##########
@@ -57,11 +58,13 @@ public void setUp() {
 	}
 
 	@Test
+	@Ignore

Review comment:
       should these still be ignored

##########
File path: src/test/scripts/functions/federated/indexing/FederatedRightIndexFullTestReference.dml
##########
@@ -0,0 +1,30 @@
+#-------------------------------------------------------------
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#-------------------------------------------------------------
+
+from = $5;
+to = $6;
+
+if($7) { A = rbind(read($1), read($2), read($3), read($4)); }
+else { A = cbind(read($1), read($2), read($3), read($4)); }
+
+s = A[from:to, from:to];
+
+write(s, $8);

Review comment:
       newline

##########
File path: src/test/scripts/functions/federated/indexing/FederatedRightIndexLeftTest.dml
##########
@@ -0,0 +1,37 @@
+#-------------------------------------------------------------
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#-------------------------------------------------------------
+
+from = $from;
+to = $to;
+
+if ($rP) {
+    A = federated(addresses=list($in_X1, $in_X2, $in_X3, $in_X4),
+        ranges=list(list(0, 0), list($rows/4, $cols), list($rows/4, 0), list(2*$rows/4, $cols),
+    		list(2*$rows/4, 0), list(3*$rows/4, $cols), list(3*$rows/4, 0), list($rows, $cols)));
+} else {
+    A = federated(addresses=list($in_X1, $in_X2, $in_X3, $in_X4),
+            ranges=list(list(0, 0), list($rows, $cols/4), list(0,$cols/4), list($rows, $cols/2),
+            	list(0,$cols/2), list($rows, 3*($cols/4)), list(0, 3*($cols/4)), list($rows, $cols)));
+}
+
+s = A[from:to,];
+
+write(s, $out_S);

Review comment:
       newline

##########
File path: src/main/java/org/apache/sysds/runtime/instructions/fed/MatrixIndexingFEDInstruction.java
##########
@@ -0,0 +1,196 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sysds.runtime.instructions.fed;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.sysds.runtime.DMLRuntimeException;
+import org.apache.sysds.runtime.controlprogram.caching.MatrixObject;
+import org.apache.sysds.runtime.controlprogram.context.ExecutionContext;
+import org.apache.sysds.runtime.controlprogram.federated.FederatedRequest;
+import org.apache.sysds.runtime.controlprogram.federated.FederatedResponse;
+import org.apache.sysds.runtime.controlprogram.federated.FederatedUDF;
+import org.apache.sysds.runtime.controlprogram.federated.FederationMap;
+import org.apache.sysds.runtime.controlprogram.federated.FederationUtils;
+import org.apache.sysds.runtime.instructions.cp.CPOperand;
+import org.apache.sysds.runtime.instructions.cp.Data;
+import org.apache.sysds.runtime.matrix.data.MatrixBlock;
+import org.apache.sysds.runtime.util.IndexRange;
+
+public final class MatrixIndexingFEDInstruction extends IndexingFEDInstruction {
+	private static final Log LOG = LogFactory.getLog(MatrixIndexingFEDInstruction.class.getName());
+
+	public MatrixIndexingFEDInstruction(CPOperand in, CPOperand rl, CPOperand ru, CPOperand cl, CPOperand cu,
+		CPOperand out, String opcode, String istr) {
+		super(in, rl, ru, cl, cu, out, opcode, istr);
+	}
+
+	@Override
+	public void processInstruction(ExecutionContext ec) {
+		rightIndexing(ec);
+	}
+
+	private void rightIndexing (ExecutionContext ec) {
+		MatrixObject in = ec.getMatrixObject(input1);
+		FederationMap fedMapping = in.getFedMapping();
+		IndexRange ixrange = getIndexRange(ec);
+		FederationMap.FType fedType = fedMapping.getType();
+		Map <String, IndexRange> ixs = new HashMap<>();
+
+		long[] lastEndDim = new long[2];
+		long[] lastBeginDim = new long[2];
+
+		for (int i = 0; i < fedMapping.getFederatedRanges().length; i++) {
+			long rs = fedMapping.getFederatedRanges()[i].getBeginDims()[0], re = fedMapping.getFederatedRanges()[i]
+				.getEndDims()[0], cs = fedMapping.getFederatedRanges()[i].getBeginDims()[1], ce = fedMapping.getFederatedRanges()[i].getEndDims()[1];
+
+			long rsn = 0, ren = 0, csn = 0, cen = 0;
+
+			switch(fedType) {
+				case ROW:
+					rsn = (ixrange.rowStart >= rs && ixrange.rowStart < re) ? (ixrange.rowStart - rs) : 0;
+					ren = (ixrange.rowEnd >= rs && ixrange.rowEnd < re) ? (ixrange.rowEnd - rs) : (re - rs - 1);
+					csn = ixrange.colStart;
+					cen = ixrange.colEnd;
+
+					if((ixrange.rowStart < re) && (ixrange.rowEnd >= rs)) {
+						fedMapping.getFederatedRanges()[i].setBeginDim(0, i != 0 ? fedMapping.getFederatedRanges()[i - 1].getEndDims()[0] : 0);
+						fedMapping.getFederatedRanges()[i].setEndDim(0, ren - rsn + 1 + (i == 0 ? 0 : fedMapping.getFederatedRanges()[i - 1].getEndDims()[0]));
+						fedMapping.getFederatedRanges()[i].setEndDim(1, cen - csn + 1);
+					}
+					else {
+						fedMapping.getFederatedRanges()[i].setBeginDim(0, i != 0 ? fedMapping.getFederatedRanges()[i - 1].getEndDims()[0] : 0);
+						fedMapping.getFederatedRanges()[i].setEndDim(0, fedMapping.getFederatedRanges()[i].getBeginDims()[0]);
+						fedMapping.getFederatedRanges()[i].setEndDim(1, cen - csn + 1);
+						rsn = -1;
+						ren = rsn;
+						csn = rsn;
+						cen = rsn;
+					}
+
+					break;
+				case COL:
+					rsn = ixrange.rowStart;
+					ren = ixrange.rowEnd;
+					csn = (ixrange.colStart >= cs && ixrange.colStart < ce) ? (ixrange.colStart - cs) : 0;
+					cen = (ixrange.colEnd >= cs && ixrange.colEnd < ce) ? (ixrange.colEnd - cs) : (ce - cs - 1);
+					if((ixrange.colStart < ce) && (ixrange.colEnd >= cs)) {
+						fedMapping.getFederatedRanges()[i].setBeginDim(1, i != 0 ? fedMapping.getFederatedRanges()[i - 1].getEndDims()[1] : 0);
+						fedMapping.getFederatedRanges()[i].setEndDim(0, ren - rsn + 1);
+						fedMapping.getFederatedRanges()[i].setEndDim(1, cen - csn + 1 + (i == 0 ? 0 : fedMapping.getFederatedRanges()[i - 1].getEndDims()[1]));
+					}
+					else {
+						fedMapping.getFederatedRanges()[i].setBeginDim(1, i != 0 ? fedMapping.getFederatedRanges()[i - 1].getEndDims()[1] : 0);
+						fedMapping.getFederatedRanges()[i].setEndDim(0, ren - rsn + 1);
+						fedMapping.getFederatedRanges()[i].setEndDim(1, fedMapping.getFederatedRanges()[i].getBeginDims()[1]);
+						rsn = -1;
+						ren = rsn;
+						csn = rsn;
+						cen = rsn;
+					}
+					break;
+				case OTHER:
+					rsn = (ixrange.rowStart >= rs && ixrange.rowStart < re) ? (ixrange.rowStart - rs) : 0;
+					ren = (ixrange.rowEnd >= rs && ixrange.rowEnd < re) ? (ixrange.rowEnd - rs) : (re - rs - 1);
+					csn = (ixrange.colStart >= cs && ixrange.colStart < ce) ? (ixrange.colStart - cs) : 0;
+					cen = (ixrange.colEnd >= cs && ixrange.colEnd < ce) ? (ixrange.colEnd - cs) : (ce - cs - 1);
+
+					if((ixrange.colStart < ce) && (ixrange.colEnd >= cs) && (ixrange.rowStart < re) && (ixrange.rowEnd >= rs)) {
+						if (fedMapping.getFederatedRanges()[i-1].getSize() != 0 || lastEndDim[0] + lastEndDim[1] == 0) {
+							fedMapping.getFederatedRanges()[i].setBeginDim(0, i != 0 ? fedMapping.getFederatedRanges()[i - 1].getEndDims()[0] : 0);
+							fedMapping.getFederatedRanges()[i].setBeginDim(1, i != 0 ? fedMapping.getFederatedRanges()[i - 1].getEndDims()[1] : 0);
+							fedMapping.getFederatedRanges()[i].setEndDim(0, ren - rsn + 1 + (i == 0 ? 0 : fedMapping.getFederatedRanges()[i - 1].getEndDims()[0]));
+							fedMapping.getFederatedRanges()[i].setEndDim(1, cen - csn + 1 + (i == 0 ? 0 : fedMapping.getFederatedRanges()[i - 1].getEndDims()[1]));
+						} else {
+							fedMapping.getFederatedRanges()[i].setBeginDim(0, 1 + ren - rsn + lastBeginDim[0]);
+							fedMapping.getFederatedRanges()[i].setBeginDim(1, cen - csn + lastBeginDim[1]);
+							fedMapping.getFederatedRanges()[i].setEndDim(0, 1 + ren - rsn + lastEndDim[0]);
+							fedMapping.getFederatedRanges()[i].setEndDim(1, cen - csn + lastEndDim[1]);
+						}
+						lastEndDim = fedMapping.getFederatedRanges()[i].getEndDims();
+						lastBeginDim = fedMapping.getFederatedRanges()[i].getBeginDims();
+					}
+					else {
+						fedMapping.getFederatedRanges()[i].setBeginDim(0, i != 0 ? fedMapping.getFederatedRanges()[i - 1].getEndDims()[0] : 0);
+						fedMapping.getFederatedRanges()[i].setEndDim(0, fedMapping.getFederatedRanges()[i].getBeginDims()[0]);
+
+						fedMapping.getFederatedRanges()[i].setBeginDim(1, i != 0 ? fedMapping.getFederatedRanges()[i - 1].getEndDims()[1] : 0);
+						fedMapping.getFederatedRanges()[i].setEndDim(1, fedMapping.getFederatedRanges()[i].getBeginDims()[1]);
+
+						rsn = -1;
+						ren = rsn;
+						csn = rsn;
+						cen = rsn;
+					}
+			}
+			ixs.put(fedMapping.getFederatedRanges()[i].toString(), new IndexRange(rsn, ren, csn, cen));
+		}
+//		List<MatrixBlock> mb = new ArrayList<>();
+		long varID = FederationUtils.getNextFedDataID();
+		FederationMap sortedMapping = fedMapping.mapParallel(varID, (range, data) -> {
+			try {
+				FederatedResponse response = data
+					.executeFederatedOperation(new FederatedRequest(FederatedRequest.RequestType.EXEC_UDF, -1,
+						new SliceMatrix(data.getVarID(), varID, ixs.get(range.toString())))).get();
+//				mb.add((MatrixBlock) response.getData()[0]);
+				if(!response.isSuccessful())
+					response.throwExceptionFromResponse();
+			}
+			catch(Exception e) {
+				throw new DMLRuntimeException(e);
+			}
+			return null;
+		});
+
+
+		MatrixObject sorted = ec.getMatrixObject(output);
+		sorted.getDataCharacteristics().set(fedMapping.getMaxIndexInRange(0), fedMapping.getMaxIndexInRange(1), (int) in.getBlocksize());
+		sorted.setFedMapping(sortedMapping);

Review comment:
       sorted mapping? is it really sorted?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [systemds] OlgaOvcharenko commented on pull request #1081: [SYSTEMDS-2548] Federated right indexing

Posted by GitBox <gi...@apache.org>.
OlgaOvcharenko commented on pull request #1081:
URL: https://github.com/apache/systemds/pull/1081#issuecomment-721239204


   Added @Ignore to federated bivar test, sinc the fed cov, groupedagg instructions are not implemented yet and cm is in different PR.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [systemds] OlgaOvcharenko closed pull request #1081: [SYSTEMDS-2548] Federated right indexing

Posted by GitBox <gi...@apache.org>.
OlgaOvcharenko closed pull request #1081:
URL: https://github.com/apache/systemds/pull/1081


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org