|
| 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.component.compress.lib; |
| 21 | + |
| 22 | +import org.apache.commons.logging.Log; |
| 23 | +import org.apache.commons.logging.LogFactory; |
| 24 | +import org.apache.sysds.runtime.compress.CompressedMatrixBlock; |
| 25 | +import org.apache.sysds.runtime.compress.CompressedMatrixBlockFactory; |
| 26 | +import org.apache.sysds.runtime.compress.lib.CLALibReshape; |
| 27 | +import org.apache.sysds.runtime.matrix.data.LibMatrixReorg; |
| 28 | +import org.apache.sysds.runtime.matrix.data.MatrixBlock; |
| 29 | +import org.apache.sysds.test.TestUtils; |
| 30 | +import org.junit.Test; |
| 31 | + |
| 32 | +public class CLALibReshapeTests { |
| 33 | + protected static final Log LOG = LogFactory.getLog(CLALibReshapeTests.class.getName()); |
| 34 | + |
| 35 | + static{ |
| 36 | + Thread.currentThread().setName("test_reshape"); |
| 37 | + } |
| 38 | + |
| 39 | + @Test |
| 40 | + public void reshapeSimple() { |
| 41 | + MatrixBlock mb = TestUtils.generateTestMatrixBlock(1000, 5, 1, 1, 0.5, 235); |
| 42 | + MatrixBlock m2 = CompressedMatrixBlockFactory.compress(mb).getLeft(); |
| 43 | + |
| 44 | + MatrixBlock m3 = CLALibReshape.reshape((CompressedMatrixBlock) m2, 500, 10, false); |
| 45 | + MatrixBlock ref = LibMatrixReorg.reshape(mb, 500, 10, false); |
| 46 | + |
| 47 | + TestUtils.compareMatrices(ref, m3, 0); |
| 48 | + } |
| 49 | + |
| 50 | + @Test |
| 51 | + public void reshapeSimple2Rowwise() { |
| 52 | + MatrixBlock mb = TestUtils.generateTestMatrixBlock(3000, 1, 1, 1, 0.5, 235); |
| 53 | + MatrixBlock m2 = CompressedMatrixBlockFactory.compress(mb).getLeft(); |
| 54 | + |
| 55 | + MatrixBlock m3 = CLALibReshape.reshape((CompressedMatrixBlock) m2, 1500, 2, true); |
| 56 | + MatrixBlock ref = LibMatrixReorg.reshape(mb, 1500, 2, true); |
| 57 | + |
| 58 | + TestUtils.compareMatrices(ref, m3, 0); |
| 59 | + } |
| 60 | + |
| 61 | + @Test |
| 62 | + public void reshapeMulti2Rowwise() { |
| 63 | + MatrixBlock mb = TestUtils.generateTestMatrixBlock(3000, 4, 1, 1, 0.5, 235); |
| 64 | + MatrixBlock m2 = CompressedMatrixBlockFactory.compress(mb).getLeft(); |
| 65 | + |
| 66 | + MatrixBlock m3 = CLALibReshape.reshape((CompressedMatrixBlock) m2, 1500, 8, true); |
| 67 | + MatrixBlock ref = LibMatrixReorg.reshape(mb, 1500, 8, true); |
| 68 | + |
| 69 | + TestUtils.compareMatrices(ref, m3, 0); |
| 70 | + } |
| 71 | + |
| 72 | + |
| 73 | + @Test |
| 74 | + public void reshapeMulti2RowwiseSingleThread() { |
| 75 | + MatrixBlock mb = TestUtils.generateTestMatrixBlock(3000, 4, 1, 1, 0.5, 235); |
| 76 | + MatrixBlock m2 = CompressedMatrixBlockFactory.compress(mb).getLeft(); |
| 77 | + |
| 78 | + MatrixBlock m3 = CLALibReshape.reshape((CompressedMatrixBlock) m2, 1500, 8, true, 1); |
| 79 | + MatrixBlock ref = LibMatrixReorg.reshape(mb, 1500, 8, true); |
| 80 | + |
| 81 | + TestUtils.compareMatrices(ref, m3, 0); |
| 82 | + } |
| 83 | + |
| 84 | + @Test |
| 85 | + public void reshapeSimple2RowwiseNotMultiply() { |
| 86 | + MatrixBlock mb = TestUtils.generateTestMatrixBlock(3000, 2, 1, 1, 0.5, 235); |
| 87 | + MatrixBlock m2 = CompressedMatrixBlockFactory.compress(mb).getLeft(); |
| 88 | + |
| 89 | + MatrixBlock m3 = CLALibReshape.reshape((CompressedMatrixBlock) m2, 2000, 3, true); |
| 90 | + MatrixBlock ref = LibMatrixReorg.reshape(mb, 2000, 3, true); |
| 91 | + |
| 92 | + TestUtils.compareMatrices(ref, m3, 0); |
| 93 | + } |
| 94 | + |
| 95 | + @Test |
| 96 | + public void reshapeSimple2ColWise() { |
| 97 | + MatrixBlock mb = TestUtils.generateTestMatrixBlock(3000, 1, 1, 1, 0.5, 235); |
| 98 | + MatrixBlock m2 = CompressedMatrixBlockFactory.compress(mb).getLeft(); |
| 99 | + |
| 100 | + MatrixBlock m3 = CLALibReshape.reshape((CompressedMatrixBlock) m2, 1500, 2, false); |
| 101 | + MatrixBlock ref = LibMatrixReorg.reshape(mb, 1500, 2, false); |
| 102 | + |
| 103 | + TestUtils.compareMatrices(ref, m3, 0); |
| 104 | + } |
| 105 | + |
| 106 | + @Test(expected = Exception.class) |
| 107 | + public void reshapeInvalid() { |
| 108 | + MatrixBlock mb = TestUtils.generateTestMatrixBlock(1000, 5, 1, 1, 0.5, 235); |
| 109 | + MatrixBlock m2 = CompressedMatrixBlockFactory.compress(mb).getLeft(); |
| 110 | + |
| 111 | + CLALibReshape.reshape((CompressedMatrixBlock) m2, 501, 10, false); |
| 112 | + } |
| 113 | +} |
0 commit comments