Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cat() nested transducers #576

Open
Uroc327 opened this issue Jan 21, 2025 · 0 comments
Open

Cat() nested transducers #576

Uroc327 opened this issue Jan 21, 2025 · 0 comments

Comments

@Uroc327
Copy link

Uroc327 commented Jan 21, 2025

How can I concatenate nested transducers generated by Map()s?

Consider the following example code.

using Combinatorics
using Transducers

a() = partitions(10, 3) |> MapCat(unique  permutations) |> collect
b() = partitions(10, 3) |> MapCat(permutations) |> Unique() |> collect
#c() = partitions(10, 3) |> MapCat(Unique() ∘ permutations) |> collect
#d() = partitions(10, 3) |> MapCat(part -> part |> permutations |> Unique()) |> collect

This generates all unique permutations of arrays of three integers summing to ten. Ideally, I would like to have the Unique() inside the MapCat because after Cat()ing all the permutations, there are a lot of elements because of which the buffer for checking uniqueness becomes larger than what fits into memory (for larger values than 10 and 3). Therefore, b() only works for small problems. On the other hand, using the unique function instead of the Unique() transducer allocates and collects, which is also suboptimal. Thus, I'd also like to avoid b().

The versions with Unique() inside the MapCat() throw a MethodError, though. Specifically,

ERROR: MethodError: no method matching unwrap(::Transducers.Reduction{Unique{…}, Transducers.Reduction{…}}, ::BangBang.SafeCollector{Empty{…}})
The function `unwrap` exists, but no method is defined for this combination of argument types.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant