Last active
August 29, 2015 14:15
-
-
Save Deco/9b249f8de80d07dfe4c6 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
{.experimental.} | |
type arrayUnchecked {.unchecked.} [T] = array[0..0, T] | |
type MatD[ElementT] = object | |
n: int | |
m: int | |
data: ptr arrayUnchecked[ElementT] | |
template matD(nv,mv: int, elementT: typedesc = float64): expr = | |
let size = nv*mv | |
let memPtr = alloc0(nv*mv*sizeof(elementT)) | |
let arrayPtr = cast[ptr array[0..0, elementT]](memPtr) | |
MatD[elementT](n: nv, m: mv, data: arrayPtr) | |
template `[]=`*[ElementT](mat: MatD[ElementT], index: int, value: expr) = | |
mat.data[index] = value | |
template `[]`*[ElementT](mat: MatD[ElementT], index: int): expr = | |
mat.data[index] | |
if true: | |
var a = matD(4, 4) | |
a[0] = 22 | |
echo a[0] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment