1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
|
/*
* Copyright (c) 2009-2020, Peter Abeles. All Rights Reserved.
*
* This file is part of Efficient Java Matrix Library (EJML).
*
* Licensed 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.ejml.ops;
import org.ejml.UtilEjml;
import org.ejml.data.*;
import org.ejml.dense.fixed.MatrixFeatures_DDF2;
import org.ejml.dense.fixed.MatrixFeatures_DDF3;
import org.ejml.dense.fixed.MatrixFeatures_DDF4;
import org.ejml.dense.row.MatrixFeatures_DDRM;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* @author Peter Abeles
*/
public class TestConvertMatrixData {
@Test
public void DenseMatrix() {
DMatrixRMaj A = new DMatrixRMaj(2,2,true,1,2,3,4);
FMatrixRMaj B = new FMatrixRMaj(2,2);
DMatrixRMaj C = new DMatrixRMaj(2,2);
ConvertMatrixData.convert(A,B);
ConvertMatrixData.convert(B,C);
assertTrue(MatrixFeatures_DDRM.isIdentical(A,C, UtilEjml.TEST_F64));
}
@Test
public void DMatrixFixed2x2() {
DMatrix2x2 A = new DMatrix2x2(1,2,3,4);
FMatrix2x2 B = new FMatrix2x2();
DMatrix2x2 C = new DMatrix2x2();
ConvertMatrixData.convert(A,B);
ConvertMatrixData.convert(B,C);
assertTrue(MatrixFeatures_DDF2.isIdentical(A,C, UtilEjml.TEST_F64));
}
@Test
public void DMatrixFixed3x3() {
DMatrix3x3 A = new DMatrix3x3(1,2,3,4,5,6,7,8,9);
FMatrix3x3 B = new FMatrix3x3();
DMatrix3x3 C = new DMatrix3x3();
ConvertMatrixData.convert(A,B);
ConvertMatrixData.convert(B,C);
assertTrue(MatrixFeatures_DDF3.isIdentical(A,C, UtilEjml.TEST_F64));
}
@Test
public void DMatrixFixed4x4() {
DMatrix4x4 A = new DMatrix4x4(1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6);
FMatrix4x4 B = new FMatrix4x4();
DMatrix4x4 C = new DMatrix4x4();
ConvertMatrixData.convert(A,B);
ConvertMatrixData.convert(B,C);
assertTrue(MatrixFeatures_DDF4.isIdentical(A,C, UtilEjml.TEST_F64));
}
@Test
public void DDRM_ZDRM() {
DMatrixRMaj A = new DMatrixRMaj(2,2,true,1,2,3,4);
ZMatrixRMaj B = new ZMatrixRMaj(2,2);
ConvertMatrixData.convert(A,B);
for (int row = 0; row < A.numRows; row++) {
for (int col = 0; col < A.numCols; col++) {
assertEquals(A.get(row,col),B.getReal(row,col),UtilEjml.TEST_F64);
assertEquals(0,B.getImag(row,col),UtilEjml.TEST_F64);
}
}
}
@Test
public void DDRM_CDRM() {
DMatrixRMaj A = new DMatrixRMaj(2,2,true,1,2,3,4);
CMatrixRMaj B = new CMatrixRMaj(2,2);
ConvertMatrixData.convert(A,B);
for (int row = 0; row < A.numRows; row++) {
for (int col = 0; col < A.numCols; col++) {
assertEquals(A.get(row,col),B.getReal(row,col),UtilEjml.TEST_F64);
assertEquals(0,B.getImag(row,col),UtilEjml.TEST_F64);
}
}
}
@Test
public void FDRM_ZDRM() {
FMatrixRMaj A = new FMatrixRMaj(2,2,true,1,2,3,4);
ZMatrixRMaj B = new ZMatrixRMaj(2,2);
ConvertMatrixData.convert(A,B);
for (int row = 0; row < A.numRows; row++) {
for (int col = 0; col < A.numCols; col++) {
assertEquals(A.get(row,col),B.getReal(row,col),UtilEjml.TEST_F32);
assertEquals(0,B.getImag(row,col),UtilEjml.TEST_F32);
}
}
}
@Test
public void FDRM_CDRM() {
FMatrixRMaj A = new FMatrixRMaj(2,2,true,1,2,3,4);
CMatrixRMaj B = new CMatrixRMaj(2,2);
ConvertMatrixData.convert(A,B);
for (int row = 0; row < A.numRows; row++) {
for (int col = 0; col < A.numCols; col++) {
assertEquals(A.get(row,col),B.getReal(row,col),UtilEjml.TEST_F32);
assertEquals(0,B.getImag(row,col),UtilEjml.TEST_F32);
}
}
}
}
|