In-place broadcasting into a `VectorOfArray` mishandles arrays with fewer dimensions
Maintainer thường phản hồi trong vòng 3 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 45/100
Hướng nghiên cứu
Start with unpack_voa in src/vector_of_array.jl, which slices every array argument along its last dimension, and with the BroadcastStyle methods for VectorOfArrayStyle that route v .= ... through it. The FastBroadcast extension's fast_materialize! for AbstractVectorOfSArray depends on the same slicing. Done means each case in the issue's table (vector, 1×2, fill(2.0), and 3×2 arguments, with both Vector and SVector inner arrays) matches Array(v) broadcasting, with tests added.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Since v4, a VectorOfArray is a proper AbstractArray (VectorOfArray([[1, 2, 3], [4, 5, 6]]) is a 3×2 array whose columns are the inner arrays), so broadcasting should match broadcasting with Array(v). In-place broadcasting into a VectorOfArray only does so if every array argument has the same number of dimensions as the VectorOfArray. Otherwise it errors or silently returns wrong results:
using RecursiveArrayTools
v = VectorOfArray([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]])
v .= v .+ [10.0, 20.0, 30.0]
Array(v)
# 3×2 Matrix{Float64}:
# 11.0 24.0
# 12.0 25.0
# 13.0 26.0
#
# but Array(v) .+ [10.0, 20.0, 30.0] is
# 11.0 14.0
# 22.0 25.0
# 33.0 36.0
For the same v (and the same with SVectors as inner arrays):
x |
v .= x .+ 1 |
v .= v .+ x |
|---|---|---|
[10.0, 20.0, 30.0] |
error¹ | wrong result (see above) |
[10.0 20.0] (1×2) |
error¹ | ✓ |
fill(2.0) |
ArgumentError: tuple length should be ≥ 0, got -1 |
same error |
3×2 Matrix |
✓ | ✓ |
¹ DimensionMismatch: destination axes (Base.OneTo(3),) are not compatible with source axes ... with Vectors as inner arrays; MethodError: Cannot convert an object of type ... to an object of type Float64 with SVectors.
Out-of-place broadcasting such as v .+ x gives the correct results for vectors and matrices x (the broadcast style becomes DefaultArrayStyle{2}, so Base handles it). It fails only for fill(2.0), because BroadcastStyle(::VectorOfArrayStyle, ::DefaultArrayStyle{0}) returns the VectorOfArrayStyle, which treats zero-dimensional arrays like scalars.
The cause is unpack_voa (src/vector_of_array.jl):
function unpack_voa(x::AbstractArray{T, N}, i) where {T, N}
return @view x[ntuple(x -> Colon(), N - 1)..., i]
end
It slices every array argument along its own last dimension, as if that dimension indexed the inner arrays. That holds only if ndims(x) equals the number of dimensions of the VectorOfArray. With Base's broadcasting semantics, an argument with fewer dimensions should be broadcast across the inner arrays as a whole (zero-dimensional arrays like scalars), and an argument whose last dimension has size 1 should not be indexed with i.
The FastBroadcast extension relies on the same assumption: fast_materialize!(::Serial, dst::AbstractVectorOfSArray, bc) builds each inner SArray from unpack_voa(bc, i) and needs exactly length(dst.u[i]) elements. For example, with FastBroadcast 1.4.0:
using RecursiveArrayTools, StaticArrays, FastBroadcast
v = VectorOfArray([SVector(1.0, 2.0, 3.0), SVector(4.0, 5.0, 6.0)])
x = [10.0, 20.0, 30.0]
@.. v = x + 1 # ERROR: Generator produced too few elements: Expected exactly 3 elements, but got 1
RecursiveArrayTools 4.5.3, Julia 1.13.1.
🤖 Generated with Claude Code
- Ngôn ngữ chính
- Julia
- Star
- 234
- Fork
- 77
- Merge trung bình
- 1 ngày 16 giờ
- Pull request đã merge (30 ngày)
- 11
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của SciML/RecursiveArrayTools.jl
-
Docs: usage of j vs iĐang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 68/100
SciML/RecursiveArrayTools.jl#255 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
ArrayPartition of GPU arrays: norm, dot, Vector, any scalar-index; no KernelAbstractions.get_backendĐang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 45/100
SciML/RecursiveArrayTools.jl#676 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 67/100
SciML/RecursiveArrayTools.jl#675 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
Độ khó 4/5 1-2 ngày Mức phù hợp với người mới 57/100
SciML/RecursiveArrayTools.jl#674 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
JET: similar_type(::Any) no-matching-method in RecursiveArrayToolsRaggedArrays (pre-existing QA red)Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
SciML/RecursiveArrayTools.jl#620 ·
Maintainer thường phản hồi trong vòng 3 ngày
Tất cả issue của SciML/RecursiveArrayTools.jl
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
oscar-system/GAP.jl#1455 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
SciML/OrdinaryDiffEq.jl#4875 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
documentation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
SciML/NonlinearSolve.jl#1372 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Truncated discrete ccdf and logccdf return incorrect values at the lower atomCó thể đã có người làm @vera-rubin đã nhận 1 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
JuliaStats/Distributions.jl#2095 ·