Skip to content

Commit

Permalink
Define tile so it can be overloaded (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
mtfishman authored Jan 16, 2025
1 parent eaf3cb3 commit 6429367
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "MapBroadcast"
uuid = "ebd9b9da-f48d-417c-9660-449667d60261"
authors = ["ITensor developers <[email protected]> and contributors"]
version = "0.1.5"
version = "0.1.6"

[deps]
BlockArrays = "8e7c35d0-a365-5155-bbbb-fb81a777f24e"
Expand Down
7 changes: 4 additions & 3 deletions src/MapBroadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ function promote_shape(ax, args::AbstractArray...)
return promote_shape_tile(ax, args...)
end
function promote_shape_tile(common_axes, args::AbstractArray...)
return map(arg -> tile_to_shape(arg, common_axes), args)
return map(arg -> tile(arg, common_axes), args)
end

using BlockArrays: mortar
Expand All @@ -110,8 +110,9 @@ function extend(t::Tuple, value, length)
end

# Handles logic of expanding singleton dimensions
# to match an array shape in broadcasting.
function tile_to_shape(a::AbstractArray, ax)
# to match an array shape in broadcasting
# by tiling or repeating the input array.
function tile(a::AbstractArray, ax)
axes(a) == ax && return a
# Must be one-based for now.
@assert all(isone, first.(ax))
Expand Down

0 comments on commit 6429367

Please sign in to comment.