()
| 153 | |
| 154 | |
| 155 | def test_tensorbatch_wrap_buffers(): |
| 156 | # from cuda buffer, without layout |
| 157 | buffers = [ |
| 158 | util.to_cuda_buffer(np.ones(rand_shape(3), dtype=np.int32)) for _ in range(10) |
| 159 | ] |
| 160 | batch = cvcuda.as_tensors(buffers) |
| 161 | assert batch.capacity == len(buffers) |
| 162 | assert len(batch) == len(buffers) |
| 163 | assert batch.dtype == np.int32 |
| 164 | assert batch.layout is None |
| 165 | assert batch.ndim == 3 |
| 166 | |
| 167 | # from torch tensor, with layout |
| 168 | buffers = [rand_torch_tensor(np.int16, 4) for i in range(5)] |
| 169 | batch = cvcuda.as_tensors(buffers, layout="NHWC") |
| 170 | assert batch.capacity == len(buffers) |
| 171 | assert len(batch) == len(buffers) |
| 172 | assert batch.dtype == np.int16 |
| 173 | assert batch.layout == "NHWC" |
| 174 | assert batch.ndim == 4 |
| 175 | |
| 176 | # mismatching rank |
| 177 | with t.raises( |
| 178 | RuntimeError, |
| 179 | match="NVCV_ERROR_INVALID_ARGUMENT: " |
| 180 | "Trying to add a tensor to a tensor batch with an inconsistent rank.", |
| 181 | ): |
| 182 | buffers = [rand_torch_tensor(np.int16, 3), rand_torch_tensor(np.int16, 4)] |
| 183 | cvcuda.as_tensors(buffers) |
| 184 | |
| 185 | # mismatching dtype |
| 186 | with t.raises( |
| 187 | RuntimeError, |
| 188 | match="NVCV_ERROR_INVALID_ARGUMENT: " |
| 189 | "Trying to add a tensor to a tensor batch with an inconsistent type.", |
| 190 | ): |
| 191 | buffers = [rand_torch_tensor(np.int16, 3), rand_torch_tensor(np.int32, 3)] |
| 192 | cvcuda.as_tensors(buffers) |
| 193 | |
| 194 | # invalid types |
| 195 | with t.raises( |
| 196 | RuntimeError, |
| 197 | match="Input buffer doesn't provide cuda_array_interface or DLPack interfaces.", |
| 198 | ): |
| 199 | buffers = [[1, 2, 3]] |
| 200 | cvcuda.as_tensors(buffers) |
| 201 | |
| 202 | |
| 203 | def test_tensorbatch_errors(): |
nothing calls this directly
no test coverage detected