| 29 | namespace { |
| 30 | |
| 31 | void checkTensorList(std::vector<Tensor> &tensorList, int64_t (&outputShape)[4], nvcv::TensorLayout &layout, |
| 32 | nvcv::DataType &dtype) |
| 33 | { |
| 34 | int32_t totalTensors = 0; |
| 35 | |
| 36 | if (tensorList.size() == 0) |
| 37 | { |
| 38 | throw std::runtime_error("Invalid input tensor list"); |
| 39 | } |
| 40 | |
| 41 | for (auto &tensor : tensorList) |
| 42 | { |
| 43 | if (tensor.shape().rank() < 3 || tensor.shape().rank() > 4) |
| 44 | { |
| 45 | throw std::runtime_error("Invalid input tensor shape"); |
| 46 | } |
| 47 | if (tensor.shape().rank() == 4) |
| 48 | { |
| 49 | totalTensors += tensor.shape()[0]; |
| 50 | outputShape[1] = tensor.shape()[1]; |
| 51 | outputShape[2] = tensor.shape()[2]; |
| 52 | outputShape[3] = tensor.shape()[3]; |
| 53 | } |
| 54 | else |
| 55 | { |
| 56 | totalTensors++; |
| 57 | outputShape[1] = tensor.shape()[0]; |
| 58 | outputShape[2] = tensor.shape()[1]; |
| 59 | outputShape[3] = tensor.shape()[2]; |
| 60 | } |
| 61 | |
| 62 | if (tensor.shape().layout() == nvcv::TENSOR_CHW || tensor.shape().layout() == nvcv::TENSOR_NCHW) |
| 63 | layout = nvcv::TENSOR_NCHW; |
| 64 | else |
| 65 | layout = nvcv::TENSOR_NHWC; |
| 66 | } |
| 67 | outputShape[0] = totalTensors; // set N to total number of tensors |
| 68 | dtype = tensorList[0].dtype(); |
| 69 | } |
| 70 | |
| 71 | Tensor StackIntoInternal(Tensor &output, std::vector<Tensor> &tensorList, std::optional<Stream> pstream, |
| 72 | int32_t numberOfTensors) |