t15836_2.nim 683 B

123456789101112131415161718192021222324252627
  1. discard """
  2. action: "compile"
  3. disabled: true
  4. """
  5. import std/sugar
  6. type Tensor[T] = object
  7. x: T
  8. proc numerical_gradient*[T](input: T, f: (proc(x: T): T), h = T(1e-5)): T {.inline.} =
  9. result = default(T)
  10. proc numerical_gradient*[T](input: Tensor[T], f: (proc(x: Tensor[T]): T), h = T(1e-5)): Tensor[T] {.noinit.} =
  11. result = default(Tensor[T])
  12. proc conv2d*[T](input: Tensor[T]): Tensor[T] {.inline.} =
  13. result = default(Tensor[T])
  14. proc sum*[T](arg: Tensor[T]): T = default(T)
  15. proc sum*[T](arg: Tensor[T], axis: int): Tensor[T] {.noinit.} = default(Tensor[T])
  16. let dinput = Tensor[int](x: 1)
  17. let target_grad_input = dinput.numerical_gradient(
  18. x => conv2d(x).sum())