aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMarshall Lochbaum <mwlochbaum@gmail.com>2021-06-29 21:59:56 -0400
committerMarshall Lochbaum <mwlochbaum@gmail.com>2021-06-29 22:00:11 -0400
commitfaeda7748572e1ae761f033138542a9c1fcd70a1 (patch)
treed37265ac1d4f7f52707ddaeee04d584e57c779e5 /src
parent51c7b645beddec634011e205c11c6af14311ef44 (diff)
Fix performance problems with empty results in Range and Windows
Diffstat (limited to 'src')
-rw-r--r--src/r1.bqn15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/r1.bqn b/src/r1.bqn
index f1eb209f..49c752a9 100644
--- a/src/r1.bqn
+++ b/src/r1.bqn
@@ -557,10 +557,10 @@ ShiftAfter←{
(≢𝕩) ⥊ (m↓d) ∾ 𝕨{(Fill𝕩)⌜↕𝕨}⟜𝕩⊘(n⊸-⊸↓⟜Deshape˜)m
} _fillBy_ (⊢⊘IF)
-Range←{
- I←{"↕𝕩: 𝕩 must consist of natural numbers"!Nat𝕩⋄↕𝕩}
- M←{"↕𝕩: 𝕩 must be a number or list"!1==𝕩⋄(0⌜𝕩)Fill 0⊸Fill⌜(<⟨⟩)Pair⊸∾⌜´I⌜𝕩}
- IsArray◶I‿M 𝕩
+RangeCheck ← "↕𝕩: 𝕩 must consist of natural numbers"!Nat
+Range ← IsArray◶(↕⊣RangeCheck)‿{
+ "↕𝕩: 𝕩 must be a number or list"!1==𝕩 ⋄ RangeCheck⌜𝕩
+ (0⌜𝕩)Fill 0⊸Fill⌜(0<1×´⊢)◶⟨⥊⟜⟨⟩,(<⟨⟩)Pair⊸∾⌜´↕⌜⟩𝕩
}
Windows←{
"𝕨↕𝕩: 𝕨 must have rank at most 1" ! 1≥=𝕨
@@ -572,8 +572,11 @@ Windows←{
l←(r↑s)(1+-)¨𝕨
"𝕨↕𝕩: Window length 𝕨 must be at most axis length plus one" ! ×´0⊸≤⌜l
k←1×´t←r↓s
- str ← Reverse ×`⟨k⟩∾s⊏˜{𝕩⊸-⌜↕𝕩}r-1
- (⥊𝕩) ⊏˜ k +⌜⟜(t⥊↕)˜⍟(1-=⟜1) l +⌜○(+⌜´str{𝕨⊸×⌜↕𝕩}¨⊢) 𝕨
+ Win ← {
+ str ← Reverse ×`⟨k⟩∾s⊏˜{𝕩⊸-⌜↕𝕩}r-1
+ (⥊𝕩) ⊏˜ k +⌜⟜(t⥊↕)˜⍟(1-=⟜1) l +⌜○(+⌜´str{𝕨⊸×⌜↕𝕩}¨⊢) 𝕨
+ }
+ 𝕨 (0<(k×´l)×´⊣)◶⟨{⟨⟩⥊˜l∾𝕨∾t},Win⟩ 𝕩
}_fillBy_⊢⍟(0<r)𝕩
}