| 118 | } |
| 119 | |
| 120 | void RunDecoding(SampleView<CPUBackend> outputSample, ConstSampleView<CPUBackend> inputView, |
| 121 | const numpy::HeaderData &header) { |
| 122 | Tensor<CPUBackend> transposeBuffer; |
| 123 | if (header.fortran_order) { |
| 124 | transposeBuffer.Resize(outputSample.shape(), inputView.type()); |
| 125 | auto transposeBufferView = SampleView<CPUBackend>( |
| 126 | transposeBuffer.raw_mutable_data(), transposeBuffer.shape(), transposeBuffer.type()); |
| 127 | numpy::FromFortranOrder(std::move(transposeBufferView), inputView); |
| 128 | inputView = ConstSampleView<CPUBackend>(transposeBuffer.raw_data(), transposeBuffer.shape(), |
| 129 | transposeBuffer.type()); |
| 130 | } |
| 131 | |
| 132 | if (outputSample.type() != inputView.type()) { |
| 133 | // If the types do not match, we need to convert the data |
| 134 | TYPE_SWITCH(outputSample.type(), type2id, OType, NUMPY_ALLOWED_TYPES, ( |
| 135 | TYPE_SWITCH(inputView.type(), type2id, IType, NUMPY_ALLOWED_TYPES, ( |
| 136 | std::transform(inputView.data<IType>(), |
| 137 | inputView.data<IType>() + volume(inputView.shape()), |
| 138 | outputSample.mutable_data<OType>(), ConvertSat<OType, IType>);), |
| 139 | DALI_FAIL(make_string("Unsupported input type: ", inputView.type())););), |
| 140 | DALI_FAIL(make_string("Unsupported output type: ", outputSample.type()));); |
| 141 | } else { |
| 142 | // If the types match, we can just copy the data |
| 143 | auto *out_ptr = outputSample.raw_mutable_data(); |
| 144 | const auto *in_ptr = inputView.raw_data(); |
| 145 | std::memcpy(out_ptr, in_ptr, header.nbytes()); |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | |
| 150 | void NumpyDecoder::RunImpl(Workspace &ws) { |
no test coverage detected