{"id":18047115,"url":"https://github.com/jw3126/reducewindows.jl","last_synced_at":"2025-04-10T05:05:40.287Z","repository":{"id":156692311,"uuid":"631716714","full_name":"jw3126/ReduceWindows.jl","owner":"jw3126","description":"Apply reduce over sliding windows","archived":false,"fork":false,"pushed_at":"2023-10-21T18:09:03.000Z","size":153,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-10T05:05:29.758Z","etag":null,"topics":["arrays","julia","stencil"],"latest_commit_sha":null,"homepage":"","language":"Julia","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jw3126.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-04-23T22:10:25.000Z","updated_at":"2024-12-26T03:04:11.000Z","dependencies_parsed_at":null,"dependency_job_id":"c927276a-9b9c-4b17-89ad-ba4cd59aa3a8","html_url":"https://github.com/jw3126/ReduceWindows.jl","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jw3126%2FReduceWindows.jl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jw3126%2FReduceWindows.jl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jw3126%2FReduceWindows.jl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jw3126%2FReduceWindows.jl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jw3126","download_url":"https://codeload.github.com/jw3126/ReduceWindows.jl/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248161273,"owners_count":21057555,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["arrays","julia","stencil"],"created_at":"2024-10-30T19:10:23.299Z","updated_at":"2025-04-10T05:05:40.256Z","avatar_url":"https://github.com/jw3126.png","language":"Julia","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ReduceWindows\n\n[![Build Status](https://github.com/jw3126/ReduceWindows.jl/actions/workflows/CI.yml/badge.svg?branch=main)](https://github.com/jw3126/ReduceWindows.jl/actions/workflows/CI.yml?query=branch%3Amain)\n[![Coverage](https://codecov.io/gh/jw3126/ReduceWindows.jl/branch/main/graph/badge.svg)](https://codecov.io/gh/jw3126/ReduceWindows.jl)\n\nApply `reduce` over a sliding window.\n\n# Usage\n```julia\nusing ReduceWindows\nx = [1,2,3,4,5]\nreduce_window(+, x, (-1:1,))\n# [3, 6, 9, 12, 9]\nreduce_window(max, x, (-1:1,))\n# [2, 3, 4, 5, 5]\nreduce_window(min, x, (-3:0,))\n# [1, 1, 1, 1, 2]\n\nx = [1 2 3; 4 5 6]\nreduce_window(*, x, (0:1,0:1))\n# 40  180  18\n# 20   30   6\n```\n\n# Speed\nThis package has very competitive performance, especially for large windows.\n```julia\narr = randn(500,500)\nwindow = (-50:50, -50:50)\nusing ImageFiltering: mapwindow\nmapwindow(maximum, arr, window) # warmup\nout1 = @showtime mapwindow(maximum, arr, window)\n\nusing ReduceWindows\nreduce_window(max, arr, window) # warmup\nout2 = @showtime reduce_window(max, arr, window)\n@assert out1 == out2\n```\n```\nmapwindow(maximum, arr, window): 2.075822 seconds (1.26 M allocations: 227.561 MiB, 0.76% gc time)\nreduce_window(max, arr, window): 0.002320 seconds (14 allocations: 7.630 MiB)\n```\nNaively reducing a windows of size `k` over an array of size `n` is `O(k*n)`. \nHowever the algorithm implemented here is `O(log(k)*n)` making it practical to reduce over large windows.\nThis packages also ships an `O(n)` algorithm, for extremly large windows or very costly ops.\n```julia\narr = randn(500,500)\nwindow = (-50:50, -50:50)\nusing ImageFiltering: mapwindow\nusing ReduceWindows\nconst OPCOUNT = Ref(0)\nfunction mymax(x,y)\n    OPCOUNT[] += 1\n    max(x,y)\nend\n\nmapwindow(w-\u003ereduce(mymax, w), arr, window)\nopcount_naive = OPCOUNT[]\nOPCOUNT[] = 0\nreduce_window(mymax, arr, window)\nopcount_reduce_window = OPCOUNT[]\n@show opcount_naive\n@show opcount_reduce_window\n```\n```\nopcount_naive = 2550010200\nopcount_reduce_window = 4775000\n```\n# Alternatives\n\n* [ImageFiltering.jl](https://github.com/JuliaImages/ImageFiltering.jl) much more features than this packge, but slow for large windows.\n* [MeanFilters.jl](https://github.com/jw3126/MeanFilters.jl) fast, lightwight but very narrow usecase.\n* [StaticKernels.jl](https://github.com/stev47/StaticKernels.jl) has very good performance for small windows.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjw3126%2Freducewindows.jl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjw3126%2Freducewindows.jl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjw3126%2Freducewindows.jl/lists"}