diff options
| author | Marshall Lochbaum <mwlochbaum@gmail.com> | 2022-06-20 22:08:00 -0400 |
|---|---|---|
| committer | Marshall Lochbaum <mwlochbaum@gmail.com> | 2022-06-20 22:08:00 -0400 |
| commit | 1c2acf0cec24023260174541972d663f07aa923c (patch) | |
| tree | a36f6e1513b9342debd9fdeb12cc8ad91750cafa /spec/reference.bqn | |
| parent | 0f47b5d1eeeba8315e5428181197d5de77195a64 (diff) | |
Layer 4 and 5 comments
Diffstat (limited to 'spec/reference.bqn')
| -rw-r--r-- | spec/reference.bqn | 97 |
1 files changed, 57 insertions, 40 deletions
diff --git a/spec/reference.bqn b/spec/reference.bqn index d8c66f8a..4c597258 100644 --- a/spec/reference.bqn +++ b/spec/reference.bqn @@ -88,7 +88,7 @@ _foldβ{ ! 1==π© lββ vβπ© β Fβπ½ # If π¨ isn't given, start with the last cell of π© - rβπ¨ (0<l)βΆ{π©βIdentity f}βΏ{lβ©l-1βlβπ©}ββ£ π© + rβπ¨ (0<l)βΆ{π©βIdentity f}βΏ{l-β©1βlβπ©}ββ£ π© # Apply rβ©(π¨βv)F r for π¨ from l to 0 l {π¨ -β1βΈ(β£πββvβΈF)β(>β0) π©} r } @@ -220,40 +220,52 @@ Depth β IsArrayβΆ0βΏ{1+0βΒ΄DepthΒ¨β₯π©} Λ β _insert ` β _scan -DropVβ {ββπ©Β¨π¨+βπ¨-Λβ π©} -Cell β DropVββ’ +Drop1 β {ββπ©Β¨π¨+βπ¨-Λβ π©} # Drop from list +Cell β Drop1ββ’ # (-π¨)-cell shape of array π© +# Merge: if empty, append fill shape to array shape to reshape fill +# Otherwise, run all element ravels together Mergeβ(0<β ββ₯)βΆ((βΎββ’β₯β’)βFillβHasFill)βΏ{ cββ’βπ© - ! β§Β΄β₯(cβ‘β’)Β¨π© - π©ββToArrayΛββc + ! β§Β΄β₯(cβ‘β’)Β¨π© # Shapes must match + π©ββToArrayΛββc # Shape is (β’π©)βΎc, with corresponding axis structure } + +# Check if ranks/depths are valid: list of one to three integers +# Return β₯π© ValidateRanksβ{ ! 1β₯=π© - π©β©β₯π© + π©β₯β© ! (1βΈβ€β§β€β3)β π© ! β§Β΄IntΒ¨π© π© } +# Extract the appropriate ranks/depths for a call +# Use negative indexing and wrap with | _ranks β {β¨2β©ββ¨1,0β© ((β£-1+|)Λββ βΒ¨<ββ’) ValidateRanksβπ½} _depthOp_β{ - negβ0>nβπ¨πΎ_ranksπ© β Fβπ½ β Bβ{π;π¨ΛβΈπ} + n β π¨ πΎ_ranks π© + negβ0>n β Fβπ½ _dβ{ - Rβ(π+neg)_d - π¨(2β₯(negβ§πβ₯0)β¨(0βπ)β₯βββ‘)βΆ(β¨RΒ¨,Rβ(π©Λ)Β¨ββ£β©ββ¨(π¨ B r)Β¨ββ’,Fβ©)π© + Rβ(π+neg)_d # Increment + rec β 2β₯(negβ§πβ₯0)β¨(0βπ)β₯π¨βββ‘π© # Whether to recurse into π¨β£π© and π© + π¨ recβΆ(β¨RΒ¨,Rβ(π©Λ)Β¨ββ£β©ββ¨(π¨{π;π¨ΛβΈπ}r)Β¨ββ’,Fβ©) π© } π¨ n _d π© } _rankOp_β{ - kβπ¨(ββ= (0β€β’)βΆβ¨ββ-,0β-β©Β¨ πΎ_ranks)π© - Encβ{ - fβββ(β’π©)Β¨βπ¨ + kβπ¨(ββ= 0βΈβ€βΆβ¨ββ-,0β-β©Β¨ πΎ_ranks)π© # Effective frame length + # Enclose (-π¨)-cells of π©, that is, <β((=π©)-π¨) π© + EncKβ{ + fβββ(β’π©)Β¨βπ¨ # π¨ββ’π© cβΓΒ΄sβπ¨Cellπ© fβ₯ββ(β₯π©)Β¨β((sβ₯βc)+cΓβ’)Β¨βΓΒ΄f } - Encβ©(>β0Γ1+β₯β=)βΆβ¨<β’,Enc,<ββ’β© + # Use <β’ if k=0 (required to handle atoms correctly), and <ββ’ if k==π© + Encβ(>β0Γ1+β₯β=)βΆβ¨<β’,EncK,<ββ’β© > ((βk)Encπ¨) π½Β¨ ((1-Λβ )βΈβk)Encπ© } + _insertβ{ ! 1β€=π© π¨ π½Β΄ <Λπ© @@ -261,25 +273,25 @@ _insertβ{ _scanβ{ ! IsArray π© ! 1β€=π© - Fβπ½ - csβ1 Cell π© + cβΓΒ΄csβ1 Cell π© ! (csβ‘β’)π¨ - lββ rββ₯π© + lββ rββ₯π© β Fβπ½ π¨ (0<l)βΆβ’βΏ{ - cβΓΒ΄cs + # Initial cell: csβ₯π¨FΒ¨cβπ© if π¨ is given {rβ©β₯βcβΆβ¨ββ(β₯π©)βΈF,β’β©β(ββr)Β¨βl}π¨ + # For non-initial elements, apply F to index i-c and i + # Must be ordered to compute value i-c first (β’π©) β₯ r {((π¨-c)Fβ(ββπ©)π¨)π¨_amendπ©}Β΄ (l-1)-βl-c } π© } _repeat_β{ - nβπ¨πΎπ© - fββπ¨β¨π½β©ββ¨π¨π½β’β©π© - lβuβ0 - {!Intπ©β!β>|π©βlβ©lβπ©βuβ©uβπ©}β0 n - bβπ¨{πβ£}Λβ{π¨Λ{π½πβ£}}0 - iββ¨π©β©βPβBβΈ{π`iβΎβπ©} - posβπ P u - negβπ 0βΈ<βΆβ¨i,{πβΌ}βΈPβ© -l + nβπ¨πΎπ© # Repetition numbers + lβuβ0 # Min and max repetitions + {!Intπ©β!β>|π©βlββ©π©βuββ©π©}β0 n + bβπ¨{β’;π¨{πΛβΈπ}}0 # Bind π¨ to π if necessary + iββ¨π©β©βPβ{πβ£}βBβΈ{π`iβΎβπ©} # P makes a list of repetition 0, 1, β¦ + posβπ P u # Positive repetitions + negβπ 0βΈ<βΆβ¨i,{πβΌ}βΈPβ© -l # Negative repetitions (|β<β0βposβΏnegΛ)β0 n } @@ -296,6 +308,8 @@ _repeat_β{ β½ β Reverse β Rotate / β Indices β Replicate +# Multi-axis primitive: πΎ is applied to π¨ and determines the maximum +# depth of the one-axis case _onAxes_β{ Fβπ½ (πΎ<β‘)ββ£βΆ{ # One axis @@ -303,29 +317,29 @@ _onAxes_β{ π¨Fπ© }βΏ{ # Multiple axes ! 1β₯=π¨ - ! π¨β€ββ β’π© - Rβ{(βπ¨)F(1 DropV π¨)βΈRΛπ©}β{0<β π¨} + ! (β π¨)β€=π© + Rβ{(βπ¨)F(1 Drop1 π¨)βΈRΛπ©}β{0<β π¨} # Recurse, then handle one axis π¨Rπ© }βToArray } SelSubβ{ ! IsArray π¨ - ! β§Β΄β₯IntΒ¨ π¨ - ! β§Β΄β₯ π¨ (β₯β-β§<) β π© - π¨β©π¨+(β π©)Γπ¨<0 + ! β§Β΄β₯IntΒ¨ π¨ # All integers + ! β§Β΄β₯ π¨ (β₯β-β§<) β π© # In range + π¨ +β© (β π©)Γπ¨<0 # Wrap negatives cβΓΒ΄sβ1 Cell π© - ββ(β₯π©)Β¨(cΓπ¨)+βsβ₯βc + ββ(β₯π©)Β¨(cΓπ¨)+βsβ₯βc # Extend each index to a whole cell } SelectβToArrayβΈ(SelSub _onAxes_ 1) JoinToβ{ sβπ¨βββ’π© - aβ1βΒ΄kββ Β¨s - ! β§Β΄1β₯a-k - cβ(kΒ¬a)+β(βa-1)βΈβΒ¨s + aβ1βΒ΄kββ Β¨s # Argument ranks k and result rank a + ! β§Β΄1β₯a-k # Can add at most one axis + cβ(kΒ¬a)+β(βa-1)βΈβΒ¨s # Cell shapes ! β‘Β΄c - lβ+Β΄(a=k)β£βΆ1βΏ(ββ’)Β¨s + lβ+Β΄(a=k)β£βΆ1βΏ(ββ’)Β¨s # Total length (β¨lβ©βΎβc)β₯π¨βΎββ₯π© } @@ -333,14 +347,17 @@ Takeβ{ Tβ{ ! Int π¨ lββ π© + # Indices, with clamp and modulus so that fills are all l iβ(l+1)|Β―1βlβ((π¨<0)Γπ¨+l)+β|π¨ + # Don't get the fill if not needed, as it can error iβJoinToβ(1βΈCellβ₯Fill)β(β¨Β΄l=i)π© } + # Add leading 1s to shape of π© first if necessary π¨ T _onAxes_ 0 (β¨1β©β₯Λ0βπ¨-ββ β’)βΈβΎββ’βΈβ₯π© } Dropβ{ - sβ(β π¨)(β£ββ’βΎΛ1β₯Λ0β-ββ )β’π© - ((sΓΒ―1βπ¨>0)+(-s)βsβπ¨)βπ© + sβ(β π¨)(β£ββ’βΎΛ1β₯Λ0β-ββ )β’π© # Padded shape + ((sΓΒ¬βΈ-π¨>0)+(-s)βsβπ¨)βπ© # Clamp and complement, then use Take } Prefixes β {!1β€=π© β (β1+β π©)TakeΒ¨<π©} Suffixes β {!1β€=π© β (β1+β π©)DropΒ¨<π©} @@ -352,9 +369,9 @@ NudgeBack β (1β0ββ’)βΈShiftAfter Windowsβ{ ! 1β₯=π¨ - ! π¨β€ββ β’π© + ! (β π¨)β€=π© ! β§Β΄NatΒ¨β₯π¨ - sβ(β π¨)ββ’π© + sβπ¨β βΈββ’π© ! β§Β΄π¨β€1+s π¨{(βΎβ(π¨β βΈββ’π©)ββ’β₯>)<Β¨βΈββπ©Β¨s(Β¬+ββββ’)β₯π¨}β(0<β π¨)π© } @@ -447,7 +464,7 @@ ReorderAxesβ{ π©β©<β(0=β‘)π© ! 1β₯=π¨ π¨β©β₯π¨ - ! π¨β€ββ β’π© + ! (β π¨)β€=π© ! β§Β΄NatΒ¨β₯π¨ rβ(=π©)-+´¬βπ¨ ! β§Β΄π¨<r |
