Skip to content

Commit 0967536

Browse files
committed
fix formatting
1 parent cf13f72 commit 0967536

File tree

2 files changed

+129
-129
lines changed

2 files changed

+129
-129
lines changed

src/main/java/org/apache/sysds/runtime/instructions/ooc/TransposeOOCInstruction.java

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -37,54 +37,54 @@
3737

3838
public class TransposeOOCInstruction extends ComputationOOCInstruction {
3939

40-
protected TransposeOOCInstruction(OOCType type, ReorgOperator op, CPOperand in1, CPOperand out, String opcode, String istr) {
41-
super(type, op, in1, out, opcode, istr);
40+
protected TransposeOOCInstruction(OOCType type, ReorgOperator op, CPOperand in1, CPOperand out, String opcode, String istr) {
41+
super(type, op, in1, out, opcode, istr);
4242

43-
}
43+
}
4444

45-
public static TransposeOOCInstruction parseInstruction(String str) {
46-
String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
47-
InstructionUtils.checkNumFields(parts, 2);
48-
String opcode = parts[0];
49-
CPOperand in1 = new CPOperand(parts[1]);
50-
CPOperand out = new CPOperand(parts[2]);
45+
public static TransposeOOCInstruction parseInstruction(String str) {
46+
String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
47+
InstructionUtils.checkNumFields(parts, 2);
48+
String opcode = parts[0];
49+
CPOperand in1 = new CPOperand(parts[1]);
50+
CPOperand out = new CPOperand(parts[2]);
5151

52-
ReorgOperator reorg = new ReorgOperator(SwapIndex.getSwapIndexFnObject());
53-
return new TransposeOOCInstruction(OOCType.Reorg, reorg, in1, out, opcode, str);
54-
}
52+
ReorgOperator reorg = new ReorgOperator(SwapIndex.getSwapIndexFnObject());
53+
return new TransposeOOCInstruction(OOCType.Reorg, reorg, in1, out, opcode, str);
54+
}
5555

56-
public void processInstruction( ExecutionContext ec ) {
56+
public void processInstruction( ExecutionContext ec ) {
5757

58-
// Create thread and process the transpose operation
59-
MatrixObject min = ec.getMatrixObject(input1);
60-
LocalTaskQueue<IndexedMatrixValue> qIn = min.getStreamHandle();
61-
LocalTaskQueue<IndexedMatrixValue> qOut = new LocalTaskQueue<>();
62-
ec.getMatrixObject(output).setStreamHandle(qOut);
58+
// Create thread and process the transpose operation
59+
MatrixObject min = ec.getMatrixObject(input1);
60+
LocalTaskQueue<IndexedMatrixValue> qIn = min.getStreamHandle();
61+
LocalTaskQueue<IndexedMatrixValue> qOut = new LocalTaskQueue<>();
62+
ec.getMatrixObject(output).setStreamHandle(qOut);
6363

6464

65-
ExecutorService pool = CommonThreadPool.get();
66-
try {
67-
pool.submit(() -> {
68-
IndexedMatrixValue tmp = null;
69-
try {
70-
while ((tmp = qIn.dequeueTask()) != LocalTaskQueue.NO_MORE_TASKS) {
71-
MatrixBlock inBlock = (MatrixBlock)tmp.getValue();
72-
long oldRowIdx = tmp.getIndexes().getRowIndex();
73-
long oldColIdx = tmp.getIndexes().getColumnIndex();
65+
ExecutorService pool = CommonThreadPool.get();
66+
try {
67+
pool.submit(() -> {
68+
IndexedMatrixValue tmp = null;
69+
try {
70+
while ((tmp = qIn.dequeueTask()) != LocalTaskQueue.NO_MORE_TASKS) {
71+
MatrixBlock inBlock = (MatrixBlock)tmp.getValue();
72+
long oldRowIdx = tmp.getIndexes().getRowIndex();
73+
long oldColIdx = tmp.getIndexes().getColumnIndex();
7474

75-
MatrixBlock outBlock = inBlock.reorgOperations((ReorgOperator) _optr, new MatrixBlock(), -1, -1, -1);
76-
qOut.enqueueTask(new IndexedMatrixValue(new MatrixIndexes(oldColIdx, oldRowIdx), outBlock));
77-
}
78-
qOut.closeInput();
79-
}
80-
catch(Exception ex) {
81-
throw new DMLRuntimeException(ex);
82-
}
83-
});
84-
} catch (Exception ex) {
85-
throw new DMLRuntimeException(ex);
86-
} finally {
87-
pool.shutdown();
88-
}
89-
}
75+
MatrixBlock outBlock = inBlock.reorgOperations((ReorgOperator) _optr, new MatrixBlock(), -1, -1, -1);
76+
qOut.enqueueTask(new IndexedMatrixValue(new MatrixIndexes(oldColIdx, oldRowIdx), outBlock));
77+
}
78+
qOut.closeInput();
79+
}
80+
catch(Exception ex) {
81+
throw new DMLRuntimeException(ex);
82+
}
83+
});
84+
} catch (Exception ex) {
85+
throw new DMLRuntimeException(ex);
86+
} finally {
87+
pool.shutdown();
88+
}
89+
}
9090
}

src/test/java/org/apache/sysds/test/functions/ooc/TransposeTest.java

Lines changed: 87 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -37,97 +37,97 @@
3737
import java.io.IOException;
3838

3939
public class TransposeTest extends AutomatedTestBase {
40-
private final static String TEST_NAME1 = "Transpose";
41-
private final static String TEST_DIR = "functions/ooc/";
42-
private final static String TEST_CLASS_DIR = TEST_DIR + TransposeTest.class.getSimpleName() + "/";
43-
private final static double eps = 1e-10;
44-
private static final String INPUT_NAME = "X";
45-
private static final String OUTPUT_NAME = "res";
46-
47-
private final static int rows = 1000;
48-
private final static int cols_wide = 1000;
49-
private final static int cols_skinny = 500;
50-
51-
private final static double sparsity1 = 0.7;
52-
private final static double sparsity2 = 0.1;
53-
54-
@Override
55-
public void setUp() {
56-
TestUtils.clearAssertionInformation();
57-
TestConfiguration config = new TestConfiguration(TEST_CLASS_DIR, TEST_NAME1);
58-
addTestConfiguration(TEST_NAME1, config);
59-
}
60-
61-
@Test
62-
public void testTranspose1() {
63-
runTransposeTest(cols_wide, false);
64-
}
40+
private final static String TEST_NAME1 = "Transpose";
41+
private final static String TEST_DIR = "functions/ooc/";
42+
private final static String TEST_CLASS_DIR = TEST_DIR + TransposeTest.class.getSimpleName() + "/";
43+
private final static double eps = 1e-10;
44+
private static final String INPUT_NAME = "X";
45+
private static final String OUTPUT_NAME = "res";
46+
47+
private final static int rows = 1000;
48+
private final static int cols_wide = 1000;
49+
private final static int cols_skinny = 500;
50+
51+
private final static double sparsity1 = 0.7;
52+
private final static double sparsity2 = 0.1;
53+
54+
@Override
55+
public void setUp() {
56+
TestUtils.clearAssertionInformation();
57+
TestConfiguration config = new TestConfiguration(TEST_CLASS_DIR, TEST_NAME1);
58+
addTestConfiguration(TEST_NAME1, config);
59+
}
60+
61+
@Test
62+
public void testTranspose1() {
63+
runTransposeTest(cols_wide, false);
64+
}
6565

6666
// @Test
6767
// public void testTranspose2() {
6868
// runTransposeTest(cols_skinny, false);
6969
// }
7070

71-
private void runTransposeTest(int cols, boolean sparse )
72-
{
73-
Types.ExecMode platformOld = setExecMode(Types.ExecMode.SINGLE_NODE);
74-
75-
try
76-
{
77-
getAndLoadTestConfiguration(TEST_NAME1);
78-
String HOME = SCRIPT_DIR + TEST_DIR;
79-
fullDMLScriptName = HOME + TEST_NAME1 + ".dml";
80-
programArgs = new String[]{"-explain", "-stats", "-ooc",
81-
"-args", input(INPUT_NAME), output(OUTPUT_NAME)};
82-
83-
// 1. Generate the data as MatrixBlock object
84-
double[][] A_data = getRandomMatrix(rows, cols, 0, 1, sparse?sparsity2:sparsity1, 10);
85-
86-
// 2. Convert the double arrays to MatrixBlock object
87-
MatrixBlock A_mb = DataConverter.convertToMatrixBlock(A_data);
88-
89-
// 3. Create a binary matrix writer
90-
MatrixWriter writer = MatrixWriterFactory.createMatrixWriter(Types.FileFormat.BINARY);
91-
92-
// 4. Write matrix A to a binary SequenceFile
93-
writer.writeMatrixToHDFS(A_mb, input(INPUT_NAME), rows, cols, 1000, A_mb.getNonZeros());
94-
HDFSTool.writeMetaDataFile(input(INPUT_NAME + ".mtd"), Types.ValueType.FP64,
95-
new MatrixCharacteristics(rows, cols, 1000, A_mb.getNonZeros()), Types.FileFormat.BINARY);
96-
97-
boolean exceptionExpected = false;
98-
runTest(true, exceptionExpected, null, -1);
99-
100-
double[][] C1 = readMatrix(output(OUTPUT_NAME), Types.FileFormat.BINARY, rows, cols, 1000, 1000);
101-
double result = 0.0;
102-
for(int i = 0; i < rows; i++) { // verify the results with Java
103-
double expected = 0.0;
104-
for(int j = 0; j < cols; j++) {
105-
expected = A_mb.get(i, j);
106-
result = C1[j][i];
107-
Assert.assertEquals(expected, result, eps);
108-
}
109-
110-
}
111-
112-
String prefix = Instruction.OOC_INST_PREFIX;
113-
Assert.assertTrue("OOC wasn't used for RBLK",
114-
heavyHittersContainsString(prefix + Opcodes.RBLK));
115-
Assert.assertTrue("OOC wasn't used for TRANSPOSE",
116-
heavyHittersContainsString(prefix + Opcodes.TRANSPOSE));
117-
}
118-
catch (IOException e) {
119-
throw new RuntimeException(e);
120-
}
121-
finally {
122-
resetExecMode(platformOld);
123-
}
124-
}
125-
126-
private static double[][] readMatrix(String fname, Types.FileFormat fmt, long rows, long cols, int brows, int bcols )
127-
throws IOException
128-
{
129-
MatrixBlock mb = DataConverter.readMatrixFromHDFS(fname, fmt, rows, cols, brows, bcols);
130-
double[][] C = DataConverter.convertToDoubleMatrix(mb);
131-
return C;
132-
}
71+
private void runTransposeTest(int cols, boolean sparse )
72+
{
73+
Types.ExecMode platformOld = setExecMode(Types.ExecMode.SINGLE_NODE);
74+
75+
try
76+
{
77+
getAndLoadTestConfiguration(TEST_NAME1);
78+
String HOME = SCRIPT_DIR + TEST_DIR;
79+
fullDMLScriptName = HOME + TEST_NAME1 + ".dml";
80+
programArgs = new String[]{"-explain", "-stats", "-ooc",
81+
"-args", input(INPUT_NAME), output(OUTPUT_NAME)};
82+
83+
// 1. Generate the data as MatrixBlock object
84+
double[][] A_data = getRandomMatrix(rows, cols, 0, 1, sparse?sparsity2:sparsity1, 10);
85+
86+
// 2. Convert the double arrays to MatrixBlock object
87+
MatrixBlock A_mb = DataConverter.convertToMatrixBlock(A_data);
88+
89+
// 3. Create a binary matrix writer
90+
MatrixWriter writer = MatrixWriterFactory.createMatrixWriter(Types.FileFormat.BINARY);
91+
92+
// 4. Write matrix A to a binary SequenceFile
93+
writer.writeMatrixToHDFS(A_mb, input(INPUT_NAME), rows, cols, 1000, A_mb.getNonZeros());
94+
HDFSTool.writeMetaDataFile(input(INPUT_NAME + ".mtd"), Types.ValueType.FP64,
95+
new MatrixCharacteristics(rows, cols, 1000, A_mb.getNonZeros()), Types.FileFormat.BINARY);
96+
97+
boolean exceptionExpected = false;
98+
runTest(true, exceptionExpected, null, -1);
99+
100+
double[][] C1 = readMatrix(output(OUTPUT_NAME), Types.FileFormat.BINARY, rows, cols, 1000, 1000);
101+
double result = 0.0;
102+
for(int i = 0; i < rows; i++) { // verify the results with Java
103+
double expected = 0.0;
104+
for(int j = 0; j < cols; j++) {
105+
expected = A_mb.get(i, j);
106+
result = C1[j][i];
107+
Assert.assertEquals(expected, result, eps);
108+
}
109+
110+
}
111+
112+
String prefix = Instruction.OOC_INST_PREFIX;
113+
Assert.assertTrue("OOC wasn't used for RBLK",
114+
heavyHittersContainsString(prefix + Opcodes.RBLK));
115+
Assert.assertTrue("OOC wasn't used for TRANSPOSE",
116+
heavyHittersContainsString(prefix + Opcodes.TRANSPOSE));
117+
}
118+
catch (IOException e) {
119+
throw new RuntimeException(e);
120+
}
121+
finally {
122+
resetExecMode(platformOld);
123+
}
124+
}
125+
126+
private static double[][] readMatrix(String fname, Types.FileFormat fmt, long rows, long cols, int brows, int bcols )
127+
throws IOException
128+
{
129+
MatrixBlock mb = DataConverter.readMatrixFromHDFS(fname, fmt, rows, cols, brows, bcols);
130+
double[][] C = DataConverter.convertToDoubleMatrix(mb);
131+
return C;
132+
}
133133
}

0 commit comments

Comments
 (0)