Repository navigation
feat(dsp): pipeline stdlib with map/filter/reduce/scan + |> chaining - #398
Merged
Merged
Conversation
Add lib/stdlib/dsp.flow with functional DSP primitives that compose with the |> operator: map_f32/f64, filter_f32, reduce_f32/f64, scan_f32/f64, zip_with_f32/f64, scale_f32/f64, offset_f32, clip_f32, sum_f32/f64, dot_f32/f64. Two compiler fixes were needed to make this work: 1. Function type compatibility in the type checker. Named functions and lambdas have SemanticType with name='' while declared parameters have name='fn_...'. The __eq__ check failed on name mismatch. Added a function-to-function branch in _is_compatible that compares signatures (param types + return type) without requiring name equality. 2. Lambda-as-argument wrapping in the C generator. When a lambda is passed directly as a function argument and the parameter type is a function type (fn_...), the generator now wraps it in a fat-pointer struct via _wrap_lambda_as_fn_type. Previously this wrapping only happened for return values and variable declarations. Add examples/dsp/pipeline.flow demonstrating buf |> scale |> offset |> clip |> sum. Add tests/unit/test_dsp_pipeline.py (11 tests): map, pipe, chained pipe, reduce, scan, filter, zip_with, scale/offset/clip pipe, C codegen, f64 primitives, named function as argument. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Contributor
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
lib/stdlib/dsp.flow: functional DSP primitives (map,filter,reduce,scan,zip_with,scale,offset,clip,sum,dot) for f32 and f64, all composable with|>examples/dsp/pipeline.flow:buf |> scale |> offset |> clip |> sumdemotests/unit/test_dsp_pipeline.py: 11 tests covering map, pipe chaining, reduce, scan, filter, zip_with, C codegen, f64, named function argsTwo compiler fixes:
Type checker: function-type parameters now match named functions and lambdas.
_is_compatiblecompares signatures (param types + return type) instead of requiring synthetic name equality (fn_i32__i32vs'').C generator: lambdas passed as function arguments are wrapped in fat-pointer structs via
_wrap_lambda_as_fn_type. Previously this only happened for return values and variable declarations.Test plan
examples/dsp/pipeline.flowcompiles and runs (sum = 55, PASS)test_named_function_as_argconfirms named functions work as HOF argsGenerated with Devin