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

[WIP] operate! with add_dot #220

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 src/implementations/BigInt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ function operate_to!(
return operate!(op, output, c...)
end

function operate!(op::Function, x::BigInt, args::Vararg{Any,N}) where {N}
function operate_fallback!(op::Function, x::BigInt, args::Vararg{Any,N}) where {N}
return operate_to!(x, op, x, args...)
end

Expand Down
2 changes: 1 addition & 1 deletion src/interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ function promote_operation_fallback(
::Type{<:AbstractArray{A}},
::Type{<:AbstractArray{B}},
) where {A,B}
C = promote_operation(*, A, B)
C = promote_operation(LinearAlgebra.dot, A, B)
return promote_operation(+, C, C)
end

Expand Down
17 changes: 11 additions & 6 deletions src/reduce.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,21 @@ end

_concrete_eltype(x) = isempty(x) ? eltype(x) : typeof(first(x))

function fused_map_reduce(op::F, args::Vararg{Any,N}) where {F<:Function,N}
_check_same_length(args...)

function operate!(op::typeof(add_dot), output, args::Vararg{Any,N}) where {N}
T = promote_map_reduce(op, _concrete_eltype.(args)...)
accumulator = neutral_element(reduce_op(op), T)
buffer = buffer_for(op, T, eltype.(args)...)
for I in zip(eachindex.(args)...)
accumulator =
buffered_operate!!(buffer, op, accumulator, getindex.(args, I)...)
output = buffered_operate!!(buffer, op, output, getindex.(args, I)...)
end
return accumulator
return output
end

function fused_map_reduce(op::F, args::Vararg{Any,N}) where {F<:Function,N}
_check_same_length(args...)
T = promote_map_reduce(op, _concrete_eltype.(args)...)
accumulator = neutral_element(reduce_op(op), T)
return operate!(op, accumulator, args...)
end

function operate(::typeof(sum), a::AbstractArray)
Expand Down