RosettaCodeData/Task/Matrix-exponentiation-operator/Chapel/matrix-exponentiation-operator-1.chpl
2026-04-30 12:34:36 -04:00

12 lines
264 B
Chapel

proc **(a, e) {
// create result matrix of same dimensions
var r:[a.domain] a.eltType;
// and initialize to identity matrix
forall ij in r.domain do
r(ij) = if ij(1) == ij(2) then 1 else 0;
for 1..e do
r *= a;
return r;
}