From 64293671f26bdbf6a78f08bff1217d1df239ce77 Mon Sep 17 00:00:00 2001 From: Matt Fishman Date: Thu, 16 Jan 2025 12:48:32 -0500 Subject: [PATCH] Define `tile` so it can be overloaded (#2) --- Project.toml | 2 +- src/MapBroadcast.jl | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Project.toml b/Project.toml index d445fda..babb24c 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "MapBroadcast" uuid = "ebd9b9da-f48d-417c-9660-449667d60261" authors = ["ITensor developers and contributors"] -version = "0.1.5" +version = "0.1.6" [deps] BlockArrays = "8e7c35d0-a365-5155-bbbb-fb81a777f24e" diff --git a/src/MapBroadcast.jl b/src/MapBroadcast.jl index ae76717..207c36b 100644 --- a/src/MapBroadcast.jl +++ b/src/MapBroadcast.jl @@ -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 @@ -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))