|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +package org.apache.sysds.test.functions.builtin.part2; |
| 21 | + |
| 22 | +import java.util.HashMap; |
| 23 | + |
| 24 | +import org.junit.Test; |
| 25 | + |
| 26 | +import org.apache.sysds.common.Types.ExecMode; |
| 27 | +import org.apache.sysds.common.Types.ExecType; |
| 28 | +import org.apache.sysds.runtime.matrix.data.MatrixValue.CellIndex; |
| 29 | +import org.apache.sysds.test.AutomatedTestBase; |
| 30 | +import org.apache.sysds.test.TestConfiguration; |
| 31 | +import org.apache.sysds.test.TestUtils; |
| 32 | + |
| 33 | +public class BuiltinScaleRobustTest extends AutomatedTestBase { |
| 34 | + private final static String TEST_NAME = "scaleRobust"; |
| 35 | + private final static String TEST_DIR = "functions/builtin/"; |
| 36 | + private final static String TEST_CLASS_DIR = TEST_DIR + BuiltinScaleRobustTest.class.getSimpleName() + "/"; |
| 37 | + private final static double eps = 1e-10; |
| 38 | + private final static int rows = 70; |
| 39 | + private final static int cols = 50; |
| 40 | + |
| 41 | + |
| 42 | + @Override |
| 43 | + public void setUp() { |
| 44 | + addTestConfiguration(TEST_NAME, new TestConfiguration(TEST_CLASS_DIR, TEST_NAME, new String[]{"B"})); |
| 45 | + } |
| 46 | + |
| 47 | + @Test |
| 48 | + public void testScaleRobustDenseCP() { |
| 49 | + runTest(false, ExecType.CP); |
| 50 | + } |
| 51 | + |
| 52 | + private void runTest(boolean sparse, ExecType et) { |
| 53 | + ExecMode old = setExecMode(et); |
| 54 | + try { |
| 55 | + loadTestConfiguration(getTestConfiguration(TEST_NAME)); |
| 56 | + double sparsity = sparse ? 0.1 : 0.9; |
| 57 | + String HOME = SCRIPT_DIR + TEST_DIR; |
| 58 | + fullDMLScriptName = HOME + TEST_NAME + ".dml"; |
| 59 | + fullRScriptName = HOME + TEST_NAME + ".R"; |
| 60 | + programArgs = new String[]{"-args", input("A"), output("B")}; |
| 61 | + programArgs = new String[]{"-exec", "singlenode", "-args", input("A"), output("B")}; |
| 62 | + rCmd = "Rscript " + fullRScriptName + " " + inputDir() + " " + expectedDir(); |
| 63 | + |
| 64 | + double[][] A = getRandomMatrix(rows, cols, -10, 10, sparsity, 7); |
| 65 | + writeInputMatrixWithMTD("A", A, true); |
| 66 | + |
| 67 | + // Run DML |
| 68 | + runTest(true, false, null, -1); |
| 69 | + |
| 70 | + // Run R |
| 71 | + runRScript(true); |
| 72 | + |
| 73 | + // Read matrices and compare |
| 74 | + HashMap<CellIndex, Double> dmlfile = readDMLMatrixFromOutputDir("B"); |
| 75 | + HashMap<CellIndex, Double> rfile = readRMatrixFromExpectedDir("B"); |
| 76 | + TestUtils.compareMatrices(dmlfile, rfile, eps, "DML", "R"); |
| 77 | + } catch (Exception e) { |
| 78 | + throw new RuntimeException(e); |
| 79 | + } finally { |
| 80 | + resetExecMode(old); |
| 81 | + } |
| 82 | + } |
| 83 | +} |
0 commit comments