-
Notifications
You must be signed in to change notification settings - Fork 8
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
Maximum Nesting Depth + Julia #9
Comments
@mcabbott
and then a row-wise minus reduce or minus leftFold. However, that doesn't work in Julia:
|
I believe the error is trying to say that it doesn't know the neutral element for reducing over julia> reduce(-, matrix, dims=1, init=0)
1×2 Matrix{Int64}:
-4 -4 This is closer:
but that always uses
The first is probably ill-defined due to relying on the order. It should be You could also literally subtract the whole columns, |
Yea, I found |
I think Easy to define versions (of sub-optimal efficiency): fold1(f, x::AbstractArray; dims, kw...) = mapslices(y -> foldl(f, y; kw...), x; dims);
fold2(f, x::AbstractArray; dims, kw...) = accumulate(f, x; dims, kw...)[_last(x, dims)...];
_last(x, dims) = ntuple(d -> d in dims ? (lastindex(x,d):lastindex(x,d)) : (:), ndims(x))
fold1(-, ones(Int, 2,2), dims=1)
fold2(-, ones(Int, 2,2), dims=1) # both [0 0]
fold1(-, ones(Int, 2,2), dims=1, init=0) # instead [-2 -2] |
I came across this page https://github.com/codereport/array-language-comparisons/blob/main/comparisons/leetcode/P1614_Max_Paren_Depth.md
For Julia, I'm not too sure what "no row-wise minus reduction" means, but it sounds like you are looking for
maximum(cumsum(...
, something like this:The text was updated successfully, but these errors were encountered: