Basic Matrix Operations
Julia provides common linear algebra operations in the LinearAlgebra
package,
and one convenient use of Julia is to create data for tests written in other
programming languages.
julia> using LinearAlgebra
In Julia the rows of the matrices are separated by a semi-colon ;
:
julia> M1 = [0.285714 0.857143 -0.428571 0.0;
-0.857143 0.428571 0.285714 0.0;
0.428571 0.285714 0.857143 0.0;
1.0 2.0 3.0 1.0]
4×4 Matrix{Float64}:
0.285714 0.857143 -0.428571 0.0
-0.857143 0.428571 0.285714 0.0
0.428571 0.285714 0.857143 0.0
1.0 2.0 3.0 1.0
To get accurate data for the test of the Math::Inverse
function in HCCVectorMath.h
using Julia:
julia> inv(M1)
4×4 Matrix{Float64}:
0.285714 -0.857143 0.428571 -2.77556e-17
0.857143 0.428571 0.285714 2.77556e-17
-0.428571 0.285714 0.857143 0.0
-0.714288 -0.857142 -3.57143 1.0
Now, the data can be copied from the Julia console and
pasted into a unit test for the Math::Inverse
function.
BOOST_AUTO_TEST_CASE( InverseTest1 )
{
using namespace Harlinn::Common::Core::Math;
SquareMatrix<float, 4> matrix( 0.285714f, 0.857143f, -0.428571f, 0.0f,
-0.857143f, 0.428571f, 0.285714f, 0.0f,
0.428571f, 0.285714f, 0.857143f, 0.0f,
1.0f, 2.0f, 3.0f, 1.0f );
SquareMatrix<float, 4> expected( 0.285714f, -0.857143f, 0.428571f, 0.0f,
0.857143f, 0.428571f, 0.285714f, 0.0f,
-0.428571f, 0.285714f, 0.857143f, 0.0f,
-0.714286f, -0.857143f, -3.57143f, 1.0f );
auto inverse = Inverse( matrix );
auto equal = Equal( inverse.value(), expected );
BOOST_CHECK( equal );
}