File: tstatic_generic_typeclass.nim

package info (click to toggle)
nim 2.2.4-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,951,164 kB
  • sloc: sh: 24,599; ansic: 1,771; python: 1,493; makefile: 1,013; sql: 298; asm: 141; xml: 13
file content (30 lines) | stat: -rw-r--r-- 617 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
type MyThing[T: static int] = object
  when T == 300:
    a: int

var a = MyThing[300]()
proc doThing(myThing: MyThing): string = $myThing
proc doOtherThing[T](myThing: MyThing[T]): string = $myThing
assert doThing(a) == $a
assert doThing(MyThing[0]()) == $MyThing[0]()
assert doOtherThing(a) == "(a: 0)"

type
  Backend* = enum
    Cpu,
    Cuda

  Tensor*[B: static[Backend]; T] = object
    shape: seq[int]
    strides: seq[int]
    offset: int
    when B == Backend.Cpu:
      data: seq[T]
    else:
      data_ptr: ptr T

template shape*(t: Tensor): seq[int] =
  t.shape


assert Tensor[Cpu, int]().shape == @[]