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

Define unrolled_findonly #8

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "UnrolledUtilities"
uuid = "0fe1646c-419e-43be-ac14-22321958931b"
authors = ["CliMA Contributors <[email protected]>"]
version = "0.1.2"
version = "0.1.3"

[compat]
julia = "1.10"
Expand Down
8 changes: 8 additions & 0 deletions src/UnrolledUtilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export unrolled_any,
unrolled_in,
unrolled_unique,
unrolled_filter,
unrolled_findonly,
unrolled_split,
unrolled_flatten,
unrolled_flatmap,
Expand Down Expand Up @@ -104,6 +105,12 @@ struct NoInit end
ntuple(i -> itr[N + i], Val(length(itr) - N))
# When its second argument is a Val, ntuple is unrolled via Base.@ntuple.

function unrolled_findonly(f::F, values) where {F}
filtered_values = unrolled_filter(f, values)
return length(filtered_values) == 1 ? filtered_values[1] :
error("unrolled_findonly requires that exactly 1 value makes f true")
end

@static if hasfield(Method, :recursion_relation)
# Remove recursion limits for functions whose arguments are also functions.
for func in (
Expand All @@ -115,6 +122,7 @@ struct NoInit end
unrolled_reduce,
unrolled_mapreduce,
unrolled_filter,
unrolled_findonly,
unrolled_split,
unrolled_flatmap,
unrolled_applyat,
Expand Down
Loading