Skip to content

Fix promotion fallbacks with non-concrete types - #174

Closed
odow wants to merge 1 commit into
masterfrom
od/more-union-fixes
Closed

odow wants to merge 1 commit into
masterfrom
od/more-union-fixes

Conversation

@odow

@odow odow commented Nov 17, 2022

Copy link
Copy Markdown
Member

Related to #171.

I don't know about this fix. It feels like a kludge.

The core issue is that Base is forgiving about the types of containers in linear algebra. It often just does things based on their run-time value. But because MA tries to pre-allocate things, it guesses what will happen from the eltype, e.g., in Vector{T}. The problem is that if T is non-concrete a call to zero will fail, even though the vector will probably contain concrete runtime values that support the operation.

@codecov

codecov Bot commented Nov 17, 2022 •

Copy link
Copy Markdown

Codecov Report

Base: 83.66% // Head: 83.47% // Decreases project coverage by -0.19% ⚠️

Coverage data is based on head (f8f8c4f) compared to base (201aafb).
Patch coverage: 37.50% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #174      +/-   ##
==========================================
- Coverage   83.66%   83.47%   -0.20%     
==========================================
  Files          20       20              
  Lines        1898     1906       +8     
==========================================
+ Hits         1588     1591       +3     
- Misses        310      315       +5     
Impacted Files Coverage Δ
src/interface.jl 88.65% <37.50%> (-3.08%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@odow

odow commented Nov 17, 2022

Copy link
Copy Markdown
Member Author

Hmm. This isn't sufficient, because MA.operate(*, Any[1 2], Any[1, 2]) and yet

julia> Any[1 2] * Any[1, 2]
1-element Vector{Any}:
 5

@odow

odow commented Nov 17, 2022

Copy link
Copy Markdown
Member Author

The core issue is that

# Does what `LinearAlgebra/src/matmul.jl` does for abstract matrices and
# vectors: estimate the resulting element type, allocate the resulting array but
# it redirects to `mul_to!` instead of `LinearAlgebra.mul!`.
function operate(
::typeof(*),
A::AbstractMatrix{S},
B::AbstractVector{T},
) where {T,S}
C = undef_array(promote_array_mul(typeof(A), typeof(B)), axes(A, 1))
return operate_to!(C, *, A, B)
end
function operate(
::typeof(*),
A::AbstractMatrix{S},
B::AbstractMatrix{T},
) where {T,S}
C = undef_array(
promote_array_mul(typeof(A), typeof(B)),
axes(A, 1),
axes(B, 2),
)
return operate_to!(C, *, A, B)
end

is not a valid fallback for unknown types.

@odow

odow commented Nov 17, 2022

Copy link
Copy Markdown
Member Author

This is the wrong fix. See #175

@odow odow closed this Nov 17, 2022
@odow
odow deleted the od/more-union-fixes branch November 17, 2022 03:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant