// 3rd_party_lib:matrix4cj/target/matrix4cj
// 3rd_party_lib_ohos:matrix4cj/target/aarch64-linux-ohos/matrix4cj
package matrix4cj.tests.HLT.LEVEL1
import matrix4cj.*
import std.math.*
import std.unittest.*
import std.unittest.testmacro.*
@Test
public class TestMatrix6 {
@TestCase
func L1_Test_Matrix_arrayLeftDivide_01(): Unit {
var matrix01 = Matrix(
[
[1.80, 2.88, 2.05, -0.89],
[5.25, -2.95, -0.95, -3.80],
[1.58, -2.69, -2.90, -1.04],
[-1.11, -0.66, -0.59, 0.80]
]
)
var result = matrix01.elementWise() / matrix01
var expected_matrix = Matrix(
[
[1.0, 1.0, 1.0, 1.0],
[1.0, 1.0, 1.0, 1.0],
[1.0, 1.0, 1.0, 1.0],
[1.0, 1.0, 1.0, 1.0]
]
)
@Assert(result.rowNum,expected_matrix.rowNum)
@Assert(result.colNum,expected_matrix.colNum)
var rows = result.rowNum
var cols = result.colNum
for (i in 0..rows) {
for (j in 0..cols) {
@Assert(abs(expected_matrix.get(i,j)-result.get(i,j))<1e-6,true)
@Assert(abs(expected_matrix.get(i,j)-matrix01.get(i,j))<1e-6,false)
}
}
}
@TestCase
func L1_Test_Matrix_arrayLeftDivideEquals_01(): Unit {
var matrix01 = Matrix(
[
[1.80, 2.88, 2.05, -0.89],
[5.25, -2.95, -0.95, -3.80],
[1.58, -2.69, -2.90, -1.04],
[-1.11, -0.66, -0.59, 0.80]
]
)
matrix01 = matrix01.elementWise() / matrix01
var result = matrix01
var expected_matrix = Matrix(
[
[1.0, 1.0, 1.0, 1.0],
[1.0, 1.0, 1.0, 1.0],
[1.0, 1.0, 1.0, 1.0],
[1.0, 1.0, 1.0, 1.0]
]
)
@Assert(result.rowNum,expected_matrix.rowNum)
@Assert(result.colNum,expected_matrix.colNum)
var rows = result.rowNum
var cols = result.colNum
for (i in 0..rows) {
for (j in 0..cols) {
@Assert(abs(expected_matrix.get(i,j)-result.get(i,j))<1e-6,true)
@Assert(abs(expected_matrix.get(i,j)-matrix01.get(i,j))<1e-6,true)
}
}
}
@TestCase
func L1_Test_Matrix_arrayRightDivide_01(): Unit {
var matrix01 = Matrix(
[
[1.80, 2.88, 2.05, -0.89],
[5.25, -2.95, -0.95, -3.80],
[1.58, -2.69, -2.90, -1.04],
[-1.11, -0.66, -0.59, 0.80]
]
)
var result = matrix01.elementWise() / (matrix01)
var expected_matrix = Matrix(
[
[1.0, 1.0, 1.0, 1.0],
[1.0, 1.0, 1.0, 1.0],
[1.0, 1.0, 1.0, 1.0],
[1.0, 1.0, 1.0, 1.0]
]
)
@Assert(result.rowNum,expected_matrix.rowNum)
@Assert(result.colNum,expected_matrix.colNum)
var rows = result.rowNum
var cols = result.colNum
for (i in 0..rows) {
for (j in 0..cols) {
@Assert(abs(expected_matrix.get(i,j)-result.get(i,j))<1e-6,true)
@Assert(abs(expected_matrix.get(i,j)-matrix01.get(i,j))<1e-6,false)
}
}
}
@TestCase
func L1_Test_Matrix_arrayRightDivideEquals_01(): Unit {
var matrix01 = Matrix(
[
[1.80, 2.88, 2.05, -0.89],
[5.25, -2.95, -0.95, -3.80],
[1.58, -2.69, -2.90, -1.04],
[-1.11, -0.66, -0.59, 0.80]
]
)
matrix01 = matrix01.elementWise() / (matrix01)
var result = matrix01
var expected_matrix = Matrix(
[
[1.0, 1.0, 1.0, 1.0],
[1.0, 1.0, 1.0, 1.0],
[1.0, 1.0, 1.0, 1.0],
[1.0, 1.0, 1.0, 1.0]
]
)
@Assert(result.rowNum,expected_matrix.rowNum)
@Assert(result.colNum,expected_matrix.colNum)
var rows = result.rowNum
var cols = result.colNum
for (i in 0..rows) {
for (j in 0..cols) {
@Assert(abs(expected_matrix.get(i,j)-result.get(i,j))<1e-6,true)
@Assert(abs(expected_matrix.get(i,j)-matrix01.get(i,j))<1e-6,true)
}
}
}
@TestCase
func L1_Test_Matrix_plus_01(): Unit {
var matrix01 = Matrix(
[
[1.80, 2.88, 2.05, -0.89],
[5.25, -2.95, -0.95, -3.80],
[1.58, -2.69, -2.90, -1.04],
[-1.11, -0.66, -0.59, 0.80]
]
)
var matrix02 = Matrix(
[
[1.80, 2.88, 2.05, -0.89],
[5.25, -2.95, -0.95, -3.80],
[1.58, -2.69, -2.90, -1.04],
[-1.11, -0.66, -0.59, 0.80]
]
)
var result = matrix01 + (matrix02)
var expected_matrix = Matrix(
[
[3.6, 5.76, 4.1, -1.78],
[10.5, -5.9, -1.9, -7.6],
[3.16, -5.38, -5.8, -2.08],
[-2.22, -1.32, -1.18, 1.6]
]
)
@Assert(result.rowNum,expected_matrix.rowNum)
@Assert(result.colNum,expected_matrix.colNum)
var rows = result.rowNum
var cols = result.colNum
for (i in 0..rows) {
for (j in 0..cols) {
@Assert(abs(expected_matrix.get(i,j)-result.get(i,j))<1e-6,true)
@Assert(abs(expected_matrix.get(i,j)-matrix01.get(i,j))<1e-6,false)
}
}
}
@TestCase
func L1_Test_Matrix_plusEquals_01(): Unit {
var matrix01 = Matrix(
[
[1.80, 2.88, 2.05, -0.89],
[5.25, -2.95, -0.95, -3.80],
[1.58, -2.69, -2.90, -1.04],
[-1.11, -0.66, -0.59, 0.80]
]
)
var matrix02 = Matrix(
[
[1.80, 2.88, 2.05, -0.89],
[5.25, -2.95, -0.95, -3.80],
[1.58, -2.69, -2.90, -1.04],
[-1.11, -0.66, -0.59, 0.80]
]
)
matrix01 += (matrix02)
var result = matrix01
var expected_matrix = Matrix(
[
[3.6, 5.76, 4.1, -1.78],
[10.5, -5.9, -1.9, -7.6],
[3.16, -5.38, -5.8, -2.08],
[-2.22, -1.32, -1.18, 1.6]
]
)
@Assert(result.rowNum,expected_matrix.rowNum)
@Assert(result.colNum,expected_matrix.colNum)
var rows = result.rowNum
var cols = result.colNum
for (i in 0..rows) {
for (j in 0..cols) {
@Assert(abs(expected_matrix.get(i,j)-result.get(i,j))<1e-6,true)
@Assert(abs(expected_matrix.get(i,j)-matrix01.get(i,j))<1e-6,true)
}
}
}
@TestCase
func L1_Test_Matrix_arrayTimes_01(): Unit {
var matrix01 = Matrix(
[
[1.80, 2.88, 2.05, -0.89],
[5.25, -2.95, -0.95, -3.80],
[1.58, -2.69, -2.90, -1.04],
[-1.11, -0.66, -0.59, 0.80]
]
)
var matrix02 = Matrix(
[
[1.80, 2.88, 2.05, -0.89],
[5.25, -2.95, -0.95, -3.80],
[1.58, -2.69, -2.90, -1.04],
[-1.11, -0.66, -0.59, 0.80]
]
)
var result = matrix01.elementWise() * (matrix02)
var expected_matrix = Matrix(
[
[3.24, 8.2944, 4.2025, 0.7921],
[27.5625, 8.7025, 0.9025, 14.44],
[2.4964000000000004, 7.2360999999999995, 8.41, 1.0816000000000001],
[1.2321000000000002, 0.43560000000000004, 0.34809999999999997, 0.6400000000000001]
]
)
@Assert(result.rowNum,expected_matrix.rowNum)
@Assert(result.colNum,expected_matrix.colNum)
var rows = result.rowNum
var cols = result.colNum
for (i in 0..rows) {
for (j in 0..cols) {
@Assert(abs(expected_matrix.get(i,j)-result.get(i,j))<1e-6,true)
@Assert(abs(expected_matrix.get(i,j)-matrix01.get(i,j))<1e-6,false)
}
}
}
@TestCase
func L1_Test_Matrix_arrayTimesEquals_01(): Unit {
var matrix01 = Matrix(
[
[1.80, 2.88, 2.05, -0.89],
[5.25, -2.95, -0.95, -3.80],
[1.58, -2.69, -2.90, -1.04],
[-1.11, -0.66, -0.59, 0.80]
]
)
var matrix02 = Matrix(
[
[1.80, 2.88, 2.05, -0.89],
[5.25, -2.95, -0.95, -3.80],
[1.58, -2.69, -2.90, -1.04],
[-1.11, -0.66, -0.59, 0.80]
]
)
matrix01 *= matrix02.elementWise()
var result = matrix01
var expected_matrix = Matrix(
[
[3.24, 8.2944, 4.2025, 0.7921],
[27.5625, 8.7025, 0.9025, 14.44],
[2.4964000000000004, 7.2360999999999995, 8.41, 1.0816000000000001],
[1.2321000000000002, 0.43560000000000004, 0.34809999999999997, 0.6400000000000001]
]
)
@Assert(result.rowNum,expected_matrix.rowNum)
@Assert(result.colNum,expected_matrix.colNum)
var rows = result.rowNum
var cols = result.colNum
for (i in 0..rows) {
for (j in 0..cols) {
@Assert(abs(expected_matrix.get(i,j)-result.get(i,j))<1e-6,true)
@Assert(abs(expected_matrix.get(i,j)-matrix01.get(i,j))<1e-6,true)
}
}
}
}