![firedacimagenotitle02 | Embarcadero RAD Studio Delphi C++Builder Blogs](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2020/06/firedac-image-no-title02.jpg?resize=1140%2C680&ssl=1)
- Introduction
Linear Algebra library supports Windows 32 and Windows 64. It uses OpenBLAS optimized BLAS (Basic Linear Algebra Subprograms) and LAPACK (Linear Algebra Package) libraries. Installation instructions can be seen in the video below.
2. Components in the Demo and what they do
The Demo contains TMemo component for the Result, converted in Text and one TButton that calls the main functions and procedures for calculation. Clicking the ‘Test’ button calls the InitVector procedure which sets vector items with number values. There is also InitMatrix procedure, which sets matrix items with number values. Three levels of Basic Linear Algebra Subprograms are executed, using ‘cblas_dgemv’ procedure and also Linear Algebra Package, using ‘LAPACKE_dgetrf’ function. To see the Demo in action watch the below video.
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 |
Show('BLAS level 1:'); InitVector(VectorA, 1, 2, 3); InitVector(VectorB, 4, 5, 6); LeftSide := VectorToStr(VectorA) + ' . ' + VectorToStr(VectorB); Show(LeftSide + ' = ' + FloatToStr(cblas_ddot(VectorSize, @VectorA, 1, @VectorB, 1))); Alpha := 2; InitVector(VectorA, 1, 2, 3); InitVector(VectorB, 4, 5, 6); LeftSide := FloatToStr(Alpha) + ' . ' + VectorToStr(VectorA) + ' + ' + VectorToStr(VectorB); cblas_daxpy(VectorSize, Alpha, @VectorA, 1, @VectorB, 1); Show(LeftSide + ' = ' + VectorToStr(VectorB)); Show('BLAS level 2:'); Alpha := 2; Beta := 3; InitVector(VectorA, 1, 2, 3); InitVector(VectorB, 4, 5, 6); InitMatrix(MatrixA, 1, 2, 3, 4, 5, 6, 7, 8, 9); LeftSide := FloatToStr(Alpha) + ' . ' + MatrixToStr(MatrixA) + ' . ' + VectorToStr(VectorA) + ' + ' + FloatToStr(Beta) + ' . ' + VectorToStr(VectorB); cblas_dgemv(CblasRowMajor, CblasNoTrans, MatrixRows, MatrixColumns, Alpha, @MatrixA, MatrixRows, @VectorA, 1, Beta, @VectorB, 1); Show(LeftSide + ' = ' + VectorToStr(VectorB)); Show('BLAS level 3:'); Alpha := 2; Beta := 3; InitMatrix(MatrixA, 1, 2, 3, 4, 5, 6, 7, 8, 9); InitMatrix(MatrixB, 1, 0, 0, 0, 1, 0, 0, 0, 1); InitMatrix(MatrixC, 1, 1, 1, 1, 1, 1, 1, 1, 1); LeftSide := FloatToStr(Alpha) + ' . ' + MatrixToStr(MatrixB) + ' . ' + MatrixToStr(MatrixA) + ' + ' + FloatToStr(Beta) + ' . ' + MatrixToStr(MatrixC); cblas_dgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans, MatrixRows, MatrixColumns, MatrixRows, Alpha, @MatrixA, MatrixRows, @MatrixB, MatrixRows, Beta, @MatrixC, MatrixRows); Show(LeftSide + ' = ' + MatrixToStr(MatrixC)); Show('LAPACK:'); InitMatrix(MatrixA, 1, 3, 5, 2, 4, 7, 1, 1, 0); LeftSide := MatrixToStr(MatrixA); LAPACKE_dgetrf(LAPACK_ROW_MAJOR, MatrixRows, MatrixColumns, @MatrixA, MatrixRows, @PivotIndices); Show('LU decomposition: ' + LeftSide + ' => L = ' + LowerMatrixToStr(MatrixA) + ', U = ' + UpperMatrixToStr(MatrixA)); |
This is what the InitVector procedure does:
1 2 3 |
Vector[0] := Value0; Vector[1] := Value1; Vector[2] := Value2; |
This is what the InitMatrix procedure does:
1 2 3 4 5 6 7 8 9 |
Matrix[0, 0] := Value00; Matrix[0, 1] := Value01; Matrix[0, 2] := Value02; Matrix[1, 0] := Value10; Matrix[1, 1] := Value11; Matrix[1, 2] := Value12; Matrix[2, 0] := Value20; Matrix[2, 1] := Value21; Matrix[2, 2] := Value22; |
In the image below you can see calculation of three levels of BLAS and LAPACK at the end
![image32 | Embarcadero RAD Studio Delphi C++Builder Blogs](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2020/08/image-32.png?resize=578%2C312&ssl=1)
![image33 | Embarcadero RAD Studio Delphi C++Builder Blogs](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2020/08/image-33.png?resize=750%2C393&ssl=1)
You can download the Demo here.
Like what you see? You can get the Linear Algebra Component Library and over 100 other fantastic WinSoft components with our Enterprise Component Pack. For a limited time, when you purchase RAD Studio Enterprise or Architect Edition at special Upgrade Pricing, you will also get this package of third-party software worth over $13,000, including the full WinSoft Component Library, at NO EXTRA COST! Step up to RAD Studio 10.4.1 today!
Design. Code. Compile. Deploy.
Start Free Trial Upgrade Today
Free Delphi Community Edition Free C++Builder Community Edition