Created
December 5, 2013 13:04
-
-
Save BitPuffin/7804827 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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