[xquery-talk] Matrix Multiplication (JSONiq)
Hermann Stamm-Wilbrandt
STAMMW at de.ibm.com
Sat Feb 1 15:33:21 PST 2014
Last Sylvester there was a thread on Matrix Multiplication in XQuery:
http://markmail.org/message/7q7qnbbnjo7cljzv?q=list:com.x-query.talk+matrix
+multiplication
The biggest problem identified was that XQuery does not allow for efficient
representation of 2+dimensional arrays.
JSON does provide 2+dimensional arrays for free.
I did not measure performance yet, but this JSONiq script looks very
similar to what would be done in C:
http://try.zorba.io/queries/xquery/jFd3Q8f82HuZGzcYDzQpdN4SdfY=
declare variable $A := [
[1,2],
[3,4],
[5,6],
[7,8]
];
declare variable $B := [
[1,2,3],
[4,5,6]
];
[
for $i in 1 to count(jn:members($A)) return
[
for $k in 1 to count(jn:members($B(1))) return
fn:sum(
for $j in 1 to count(jn:members($B)) return
$A($i)($j) * $B($j)($k)
)
]
]
And much simpler than in XSLT:
http://rosettacode.org/wiki/Matrix_multiplication#XSLT_1.0:
Mit besten Gruessen / Best wishes,
Hermann Stamm-Wilbrandt
Level 3 support for XML Compiler team and Fixpack team lead
WebSphere DataPower SOA Appliances
https://www.ibm.com/developerworks/mydeveloperworks/blogs/HermannSW/
https://twitter.com/HermannSW/
http://stamm-wilbrandt.de/GraphvizFiddle/
----------------------------------------------------------------------
IBM Deutschland Research & Development GmbH
Vorsitzende des Aufsichtsrats: Martina Koederitz
Geschaeftsfuehrung: Dirk Wittkopp
Sitz der Gesellschaft: Boeblingen
Registergericht: Amtsgericht Stuttgart, HRB 243294
More information about the talk
mailing list