深度学习初探/02-Pytorch知识/05-Broadcast自动维度扩展
一、特点
expand automatically without copying data
二、实现方法:
1、从最后 (后面的dim默认为小维度) 开始对齐,匹配dimension,如果发生dim缺失,就在前面插入一个长度=1的dim;
2、将新dim的长度从1 expand to the same length
e.g.
f.shape = [4, 32, 14, 14]
bias.shape = [32]
step1: 手动在32后面增加2个dimension(从后往前匹配,确保能顺利匹配到32)
bias.shape = [32, 1, 1]
step2: broadcast自动填充
bias.shape = [1, 32, 1, 1]
step3: expand to the same
bias.shape = [4, 32, 14, 14]