7.20 Multiply matrices using Cartesian product
Calculate result of multiplying matrices through filtering Cartesian product.
Matrix |
---|
row |
col |
value |
Below is the computing problem’s mathematical formula:
Use xjoin() function to calculate Cartesian product and filter the result according to the specified condition.
SPL script:
A | |
---|---|
1 | =connect(“db”) |
2 | =A1.query(“select * from MatrixA”) |
3 | =A1.query@x(“select * from MatrixB”) |
4 | =xjoin(A2:A; A3:B, A.col==A3.row) |
5 | =A4.groups(A.row:row,B.col:col;sum(A.value * B.value):value) |
A1 Connect to the database.
A2 Query MatrixA table.
A3 Query MatrixB table.
A4 Use xjoin() function to calculate Cartesian product while performing the conditional filtering.
A5 Group A4’s records and calculate value at each intersection of row and column.
Execution result:
row | col | value |
---|---|---|
1 | 1 | 14 |
1 | 2 | 32 |
2 | 1 | 32 |
2 | 2 | 77 |
SPL Official Website 👉 https://www.scudata.com
SPL Feedback and Help 👉 https://www.reddit.com/r/esProc_SPL
SPL Learning Material 👉 https://c.scudata.com
SPL Source Code and Package 👉 https://github.com/SPLWare/esProc
Discord 👉 https://discord.gg/cFTcUNs7
Youtube 👉 https://www.youtube.com/@esProc_SPL