Skip to content

Instantly share code, notes, and snippets.

@BitPuffin
Created December 5, 2013 13:04
Show Gist options
  • Save BitPuffin/7804827 to your computer and use it in GitHub Desktop.
Save BitPuffin/7804827 to your computer and use it in GitHub Desktop.
proc identity[T; N](): TMatrix[T, N, N] {.noSideEffect.} =
## Returns the identity matrix given the specified params
## This proc is unnecessarily inefficient for now because of
## the compiler
for i in N.low..N.high():
for j in N.low..N.high():
if i == j:
result[i][j] = 1.T
else:
result[i][j] = 0.T
echo(identity[float32, range[0..2]]())
[1.0000000000000000e+00, 0.0000000000000000e+00, 0.0000000000000000e+00]
[0.0000000000000000e+00, 1.0000000000000000e+00, 0.0000000000000000e+00]
[0.0000000000000000e+00, 0.0000000000000000e+00, 1.0000000000000000e+00]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment