This file contains hidden or 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
| import macros | |
| type Conv2DLayer[T] = object | |
| data: T | |
| type Context[T] = ref object | |
| data: T | |
| #################################### |
This file contains hidden or 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
| import macros, tables, hashes | |
| import ../src/tensor/backend/metadataArray | |
| type TopoShape = DynamicStackArray[int] | |
| ## TopoShape is compatible but conceptually different from a MetadataArray | |
| ## TopoShape does not store the batch size information for tensors | |
| ## and is used to describe layers shape |
This file contains hidden or 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
| import ../src/arraymancer, random | |
| randomize(42) | |
| let | |
| ctx = newContext Tensor[float32] # Autograd/neural network graph | |
| n = 32 # Batch size | |
| let | |
| x_train = read_mnist_images("build/train-images.idx3-ubyte").astype(float32) / 255'f32 |
This file contains hidden or 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
| type | |
| TrainableLayer = object {.inheritable.} | |
| ## Layer with trainable parameters | |
| weight: int | |
| bias: int | |
| Conv2DLayer{.final.} = object of TrainableLayer | |
| LinearLayer{.final.} = object of TrainableLayer |
This file contains hidden or 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
| import random, sequtils, times | |
| type | |
| Op = enum | |
| Halt # = 0x0000 | |
| Inc # = 0x0100 | |
| Dec # = 0x0110 | |
| Mul2 # = 0x0230 | |
| Div2 # = 0x0240 | |
| Add7 # = 0x0307 |
This file contains hidden or 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
| macro myzip(x: ForLoopStmt): untyped = | |
| x.expectKind nnkForStmt | |
| result = newStmtList() | |
| echo x.treeRepr | |
| echo "\n##################" | |
| # Count the number of idents: | |
| var ident_count = 1 | |
| while x[ident_count + 1].kind == nnkIdent: | |
| inc ident_count |
This file contains hidden or 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
| import macros, ../src/arraymancer | |
| # Transforms | |
| dumpTree: | |
| network model_name: | |
| context: ctx | |
| input_shape: [1, 28, 28] # Real shape [N, 1, 28, 28] | |
| layers: |
This file contains hidden or 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
| import macros, typetraits | |
| ####################################################### | |
| static: echo "########################################" | |
| static: echo "### zip Tree ###" | |
| dumpTree: | |
| iterator zip(a: seq[int], b: seq[bool]): (int,bool) {.noSideEffect.} = | |
| let len = min(a.len, b.len) |
This file contains hidden or 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
| # Mpint | |
| # Copyright 2018 Status Research & Development GmbH | |
| # Licensed under either of | |
| # | |
| # * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) | |
| # * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) | |
| # | |
| # at your option. This file may not be copied, modified, or distributed except according to those terms. | |
| import ./uint_type, macros |
This file contains hidden or 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
| func `shl`*(x: MpUintImpl, y: SomeInteger): MpUintImpl {.inline.}= | |
| ## Compute the `shift left` operation of x and y | |
| # Note: inlining this poses codegen/aliasing issue when doing `x = x shl 1` | |
| # TODO: would it be better to reimplement this using an array of bytes/uint64 | |
| # That opens up to endianness issues. | |
| const halfSize = size_mpuintimpl(x) div 2 | |
| let defect = halfSize - int(y) |