Source code for maxframe.tensor.misc.broadcast_arrays

# Copyright 1999-2026 Alibaba Group Holding Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from maxframe.core import ExecutableTuple
from maxframe.tensor.datasource import tensor as astensor
from maxframe.tensor.misc.broadcast_to import broadcast_to
from maxframe.tensor.utils import broadcast_shape
from maxframe.utils import check_unexpected_kwargs


[docs] def broadcast_arrays(*args, **kwargs): """ Broadcast any number of arrays against each other. Parameters ---------- `*args` : array_likes The tensors to broadcast. Returns ------- broadcasted : list of tensors Examples -------- >>> import maxframe.tensor as mt >>> x = mt.array([[1,2,3]]) >>> y = mt.array([[1],[2],[3]]) >>> mt.broadcast_arrays(x, y).execute() [array([[1, 2, 3], [1, 2, 3], [1, 2, 3]]), array([[1, 1, 1], [2, 2, 2], [3, 3, 3]])] """ check_unexpected_kwargs(kwargs) args = [astensor(arg) for arg in args] shape = broadcast_shape(*[arg.shape for arg in args]) return ExecutableTuple([broadcast_to(a, shape) for a in args])