-Arraymancer Tutorial - First steps
-
-A remake of the original tutorial using nimib: https://mratsim.github.io/Arraymancer/tuto.first_steps.html
-I will note differences with the original in quoted sections.
-
-Tensor properties
-Tensors have the following properties:
-
-rank
: 0 for scalar (cannot be stored), 1 for vector, 2 for matrices, N for N dimensional arrays
-shape
: a sequence of the tensor dimensions along each axis
-
-Next properties are technical and there for completeness:
-
-stride
: a sequence of numbers of steps to get the next item along a dimension
-offset
: the first element of the tensor
-
-import
- arraymancer, sugar, sequtils
-
-let d = [[1, 2, 3], [4, 5, 6]].toTensor()
-echo d
-Tensor[system.int] of shape [2, 3]" on backend "Cpu"
-|1 2 3|
-|4 5 6|
-
-
-
-message changed, it was: Tensor of shape 2x3 of type "int" on backend "Cpu"
-
-dump d.rank
-dump d.shape
-dump d.strides
-dump d.offset
-d.rank = 2
-d.shape = [2, 3]
-d.strides = [3, 1]
-d.offset = 0
-
-
-echo of shape and strides changed (dropped @)
-
-Tensor creation
-The canonical way to initialize a tensor is by converting a seq of seq of ... or an array of array of ...
-into a tensor using toTensor
.
-toTensor
supports deep nested sequences and arrays, even sequences of array of sequences.
-let c = [[[1, 2, 3], [4, 5, 6]], [[11, 22, 33], [44, 55, 66]],
- [[111, 222, 333], [444, 555, 666]],
- [[1111, 2222, 3333], [4444, 5555, 6666]]].toTensor()
-echo c
-Tensor[system.int] of shape [4, 2, 3]" on backend "Cpu"
-| | 1 2 3 | 11 22 33 | 111 222 333 | 1111 2222 3333|
-| | 4 5 6 | 44 55 66 | 444 555 666 | 4444 5555 6666|
-
-
-
-I am not sure where the additional pipes come from, maybe a bug?
-
-newTensor
procedure can be used to initialize a tensor of a specific
-shape with a default value. (0 for numbers, false for bool...)
-zeros
and ones
procedures create a new tensor filled with 0 and
-1 respectively.
-zeros_like
and ones_like
take an input tensor and output a
-tensor of the same shape but filled with 0 and 1 respectively.
-let e = newTensor[bool]([2, 3])
-dump e
-e = Tensor[system.bool] of shape [2, 3]" on backend "Cpu"
-|false false false|
-|false false false|
-
-
-let f = zeros[float]([4, 3])
-dump f
-f = Tensor[system.float] of shape [4, 3]" on backend "Cpu"
-|0.0 0.0 0.0|
-|0.0 0.0 0.0|
-|0.0 0.0 0.0|
-|0.0 0.0 0.0|
-
-
-let g = ones[float]([4, 3])
-dump g
-g = Tensor[system.float] of shape [4, 3]" on backend "Cpu"
-|1.0 1.0 1.0|
-|1.0 1.0 1.0|
-|1.0 1.0 1.0|
-|1.0 1.0 1.0|
-
-
-let tmp = [[1, 2], [3, 4]].toTensor()
-let h = tmp.zeros_like
-dump h
-h = Tensor[system.int] of shape [2, 2]" on backend "Cpu"
-|0 0|
-|0 0|
-
-
-let i = tmp.ones_like
-dump i
-i = Tensor[system.int] of shape [2, 2]" on backend "Cpu"
-|1 1|
-|1 1|
-
-
-Accessing and modifying a value
-Tensors value can be retrieved or set with array brackets.
-var a = toSeq(1 .. 24).toTensor().reshape(2, 3, 4)
-echo a
-Tensor[system.int] of shape [2, 3, 4]" on backend "Cpu"
-| | 1 2 3 4 | 13 14 15 16|
-| | 5 6 7 8 | 17 18 19 20|
-| | 9 10 11 12 | 21 22 23 24|
-
-
-dump a[1, 1, 1]
-echo a
-a[1, 1, 1] = 18
-Tensor[system.int] of shape [2, 3, 4]" on backend "Cpu"
-| | 1 2 3 4 | 13 14 15 16|
-| | 5 6 7 8 | 17 18 19 20|
-| | 9 10 11 12 | 21 22 23 24|
-
-
-a[1, 1, 1] = 999
-echo a
-Tensor[system.int] of shape [2, 3, 4]" on backend "Cpu"
-| | 1 2 3 4 | 13 14 15 16|
-| | 5 6 7 8 | 17 999 19 20|
-| | 9 10 11 12 | 21 22 23 24|
-
-
-Copying
-Warning ⚠: When you do the following, both tensors a
and b
will share data.
-Full copy must be explicitly requested via the clone
function.
-let a = toSeq(1 .. 24).toTensor().reshape(2, 3, 4)
-var b = a
-var c = clone(a)
-Here modifying b
WILL modify a
.
-
-adding an example of modification and an example of clone:
-
-dump a[1, 0, 0]
-c[1, 0, 0] = 0
-dump a[1, 0, 0]
-b[1, 0, 0] = 0
-dump a[1, 0, 0]
-a[1, 0, 0] = 13
-a[1, 0, 0] = 13
-a[1, 0, 0] = 0
-
-This behaviour is the same as Numpy and Julia,
-reasons can be found in the following
-under the hood article.
-
-
-
-import nimib
-
-
-
-nbInit
-nbText: """
-# Arraymancer Tutorial - First steps
-
-> A remake of the original tutorial using nimib: <https://mratsim.github.io/Arraymancer/tuto.first_steps.html>
->
-> I will note differences with the original in quoted sections.
-
-## Tensor properties
-
-Tensors have the following properties:
-- `rank`: 0 for scalar (cannot be stored), 1 for vector, 2 for matrices, *N* for *N* dimensional arrays
-- `shape`: a sequence of the tensor dimensions along each axis
-
-Next properties are technical and there for completeness:
-- `stride`: a sequence of numbers of steps to get the next item along a dimension
-- `offset`: the first element of the tensor
-"""
-
-nbCode:
- import arraymancer, sugar, sequtils
-
- let d = [[1, 2, 3], [4, 5, 6]].toTensor()
-
- echo d
-
-nbText: """> message changed, it was: `Tensor of shape 2x3 of type "int" on backend "Cpu"`"""
-
-nbCode:
- dump d.rank
- dump d.shape
- dump d.strides
- dump d.offset
-nbText: "> echo of shape and strides changed (dropped @)"
-
-nbText: """
-## Tensor creation
-The canonical way to initialize a tensor is by converting a seq of seq of ... or an array of array of ...
-into a tensor using `toTensor`.
-`toTensor` supports deep nested sequences and arrays, even sequences of array of sequences.
-"""
-
-nbCode:
- let c = [
- [
- [1,2,3],
- [4,5,6]
- ],
- [
- [11,22,33],
- [44,55,66]
- ],
- [
- [111,222,333],
- [444,555,666]
- ],
- [
- [1111,2222,3333],
- [4444,5555,6666]
- ]
- ].toTensor()
- echo c
-nbText: "> I am not sure where the additional pipes come from, maybe a bug?"
-nbText: """
-`newTensor` procedure can be used to initialize a tensor of a specific
-shape with a default value. (0 for numbers, false for bool...)
-
-`zeros` and `ones` procedures create a new tensor filled with 0 and
-1 respectively.
-
-`zeros_like` and `ones_like` take an input tensor and output a
-tensor of the same shape but filled with 0 and 1 respectively.
-"""
-nbCode:
- let e = newTensor[bool]([2, 3])
- dump e
-nbCode:
- let f = zeros[float]([4, 3])
- dump f
-nbCode:
- let g = ones[float]([4, 3])
- dump g
-nbCode:
- let tmp = [[1,2],[3,4]].toTensor()
- let h = tmp.zeros_like
- dump h
-nbCode:
- let i = tmp.ones_like
- dump i
-
-nbText: """
-## Accessing and modifying a value
-
-Tensors value can be retrieved or set with array brackets.
-"""
-
-nbCode:
- var a = toSeq(1..24).toTensor().reshape(2,3,4)
- echo a
-nbCode:
- dump a[1, 1, 1]
- echo a
-nbCode:
- a[1, 1, 1] = 999
- echo a
-nbText: """
-## Copying
-
-Warning ⚠: When you do the following, both tensors `a` and `b` will share data.
-Full copy must be explicitly requested via the `clone` function.
-"""
-block:
- nbCode:
- let a = toSeq(1..24).toTensor().reshape(2,3,4)
- var b = a
- var c = clone(a)
- nbText: """
- Here modifying `b` WILL modify `a`.
-
- > adding an example of modification and an example of clone:
- """
-
- nbCode:
- dump a[1, 0, 0]
- c[1, 0, 0] = 0
- dump a[1, 0, 0]
- b[1, 0, 0] = 0
- dump a[1, 0, 0]
-nbText: """
-This behaviour is the same as Numpy and Julia,
-reasons can be found in the following
-[under the hood article](https://mratsim.github.io/Arraymancer/uth.copy_semantics.html).
-"""
-nbShow
-
-
\ No newline at end of file
diff --git a/drafts/city_in_a_bottle.html b/drafts/city_in_a_bottle.html
deleted file mode 100644
index 4adbc82..0000000
--- a/drafts/city_in_a_bottle.html
+++ /dev/null
@@ -1,114 +0,0 @@
-
-
-
-
-import nimib
-
-nbInit
-
-nbText: """# City in a bottle
-> example of usage of `nbRawOutput`
-
-How do I embed a tweet like [this great tweet](https://twitter.com/killedbyapixel/status/1517294627996545024) in nimib?
-
-Easy! Just go in the top right corner of the tweet (⋮), click on "Embed Tweet", copy the code
-and use `nbRawOutput` (see source by clicking "Show Source" button below)
-"""
-nbRawOutput: """<blockquote class="twitter-tweet"><p lang="en" dir="ltr">A City in a Bottle 🌆<br><br><canvas style=width:99% id=c onclick=setInterval('for(c.width=w=99,++t,i=6e3;i--;c.getContext`2d`.fillRect(i%w,i/w|0,1-d*Z/w+s,1))for(a=i%w/50-1,s=b=1-i/4e3,X=t,Y=Z=d=1;++Z<w&(Y<6-(32<Z&27<X%w&&X/9^Z/8)*8%46||d|(s=(X&Y&Z)%3/Z,a=b=1,d=Z/w));Y-=b)X+=a',t=9)> <a href="https://t.co/N3WElPqtMY">pic.twitter.com/N3WElPqtMY</a></p>— Frank Force 🌻 (@KilledByAPixel) <a href="https://twitter.com/KilledByAPixel/status/1517294627996545024?ref_src=twsrc%5Etfw">April 22, 2022</a></blockquote> <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>"""
-
-nbText: "And we can use `nbRawOutput` also to visualize the canvas code. The only adjustment I made is to add a solid border. Click inside to start the animation."
-nbRawOutput: """<canvas style="width:99%; border:1px solid #000000;" id=c onclick=setInterval('for(c.width=w=99,++t,i=6e3;i--;c.getContext`2d`.fillRect(i%w,i/w|0,1-d*Z/w+s,1))for(a=i%w/50-1,s=b=1-i/4e3,X=t,Y=Z=d=1;++Z<w&(Y<6-(32<Z&27<X%w&&X/9^Z/8)*8%46||d|(s=(X&Y&Z)%3/Z,a=b=1,d=Z/w));Y-=b)X+=a',t=9)></canvas>"""
-
-nbText: """Not sure why, but after you click a big white vertical area is created.
-
-Anyhoo, enjoy another tweet that links to a great Observable document that explains the code
-(I guess that now we should be able to reproduce that observable document in nimib...):
-"""
-nbRawOutput: """<blockquote class="twitter-tweet"><p lang="en" dir="ltr">If you'd like to learn how the code works, I recommend checking out this amazing breakdown by <a href="https://twitter.com/DanielDarabos?ref_src=twsrc%5Etfw">@DanielDarabos</a> that reorganizes and comments the code and provides controls to play with it.<a href="https://t.co/SVtC0yF0gJ">https://t.co/SVtC0yF0gJ</a></p>— Frank Force 🌻 (@KilledByAPixel) <a href="https://twitter.com/KilledByAPixel/status/1529838360235220992?ref_src=twsrc%5Etfw">May 26, 2022</a></blockquote> <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>"""
-
-nbText: "And actually this content was inspired by the following tweet exchange that brought back in my timeline the amazing city in a bottle:"
-nbRawOutput: """<blockquote class="twitter-tweet"><p lang="en" dir="ltr">It has its limits! I tried running <a href="https://twitter.com/KilledByAPixel?ref_src=twsrc%5Etfw">@KilledByAPixel</a>'s amazing City in a Bottle tweet-length shader through it, and GPT-3 replied with the equivalent of a ¯\_(ツ)_/¯ <a href="https://t.co/n1c4oNEwNC">https://t.co/n1c4oNEwNC</a> <a href="https://t.co/FeYixu7JS6">pic.twitter.com/FeYixu7JS6</a></p>— Andy Baio (@waxpancake) <a href="https://twitter.com/waxpancake/status/1546634381183164416?ref_src=twsrc%5Etfw">July 11, 2022</a></blockquote> <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>"""
-
-nbText: "Do I like Twitter? Oh, boy..."
-nbRawOutput: """<blockquote class="twitter-tweet"><p lang="en" dir="ltr">Oh, boy! West Coast, <a href="https://twitter.com/hashtag/YoungSheldon?src=hash&ref_src=twsrc%5Etfw">#YoungSheldon</a> starts now! <a href="https://t.co/bpSn7NySME">pic.twitter.com/bpSn7NySME</a></p>— Young Sheldon (@YoungSheldon) <a href="https://twitter.com/YoungSheldon/status/1081045053798273024?ref_src=twsrc%5Etfw">January 4, 2019</a></blockquote> <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>"""
-
-nbSave
-
-
\ No newline at end of file
diff --git a/drafts/city_in_a_bottle.nim b/drafts/city_in_a_bottle.nim
deleted file mode 100644
index 906fbf5..0000000
--- a/drafts/city_in_a_bottle.nim
+++ /dev/null
@@ -1,31 +0,0 @@
-import nimib
-
-nbInit
-
-nbText: """# City in a bottle
-> example of usage of `nbRawOutput`
-
-How do I embed a tweet like [this great tweet](https://twitter.com/killedbyapixel/status/1517294627996545024) in nimib?
-
-Easy! Just go in the top right corner of the tweet (⋮), click on "Embed Tweet", copy the code
-and use `nbRawOutput` (see source by clicking "Show Source" button below)
-"""
-nbRawOutput: """ """
-
-nbText: "And we can use `nbRawOutput` also to visualize the canvas code. The only adjustment I made is to add a solid border. Click inside to start the animation."
-nbRawOutput: """