MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / make_full_if_none

Function make_full_if_none

imperative/python/megengine/functional/nn.py:1281–1300  ·  view source on GitHub ↗
(x, value)

Source from the content-addressed store, hash-verified

1279 """
1280
1281 def make_full_if_none(x, value):
1282 x_ndim = None if x is None else x.ndim
1283 # in general case, x will be returned here directly
1284 if x_ndim is not None and x_ndim != 1:
1285 return x
1286
1287 C = inp.shape[1]
1288 pshape = (1, C, 1, 1)
1289
1290 if x is None:
1291 x = Const(value, inp.dtype, inp.device)
1292 shape = astensor1d(pshape, inp, dtype="int32", device=inp.device)
1293 (result,) = apply(builtin.Broadcast(), x, shape)
1294 result.format = inp.format
1295 return result
1296 else:
1297 assert x_ndim == 1
1298 shape = astensor1d(pshape, inp, dtype="int32", device=inp.device)
1299 (result,) = apply(builtin.Reshape(), x, shape)
1300 return result
1301
1302 has_mean = running_mean is not None
1303 has_var = running_var is not None

Callers 1

batch_normFunction · 0.85

Calls 5

astensor1dFunction · 0.85
BroadcastMethod · 0.80
ReshapeMethod · 0.80
ConstClass · 0.50
applyFunction · 0.50

Tested by

no test coverage detected