## SPDX-FileCopyrightText: Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.# SPDX-License-Identifier: Apache-2.0#"""Block implementing upsampling"""importtensorflowastffromtensorflow.experimental.numpyimportswapaxesfromsionna.phyimportBlockfromsionna.phy.utilsimportflatten_last_dims
[docs]classUpsampling(Block):"""Upsampling(samples_per_symbol, axis=-1, precision=None, **kwargs) Upsamples a tensor along a specified axis by inserting zeros between samples Parameters ---------- samples_per_symbol: `int` Upsampling factor. If ``samples_per_symbol`` is equal to `n`, then the upsampled axis will be `n`-times longer. axis: `int`, (default -1) Dimension to be up-sampled. Must not be the first dimension. precision : `None` (default) | "single" | "double" Precision used for internal calculations and outputs. If set to `None`, :attr:`~sionna.phy.config.Config.precision` is used. Input ----- x : [...,n,...], `tf.float` or `tf.complex` Tensor to be upsampled. `n` is the size of the `axis` dimension. Output ------ y : [...,n*samples_per_symbol,...], `tf.float` or `tf.complex` Upsampled tensor """def__init__(self,samples_per_symbol,axis=-1,precision=None,**kwargs):super().__init__(precision=precision,**kwargs)self._samples_per_symbol=samples_per_symbolself._axis=axisdefbuild(self,input_shape):paddings=[]for_inrange(len(input_shape)):paddings.append([0,0])paddings.append([0,self._samples_per_symbol-1])self._paddings=paddingsdefcall(self,inputs):x=swapaxes(inputs,self._axis,-1)x=tf.expand_dims(x,-1)x=tf.pad(x,self._paddings,constant_values=tf.cast(0,dtype=x.dtype))x=flatten_last_dims(x,2)x=swapaxes(x,-1,self._axis)returnx