|
1 | 1 | #include <ATen/ATen.h> |
| 2 | +#include <ATen/TensorIndexing.h> |
2 | 3 | #include <ATen/ops/full.h> |
3 | 4 | #include <ATen/ops/index_put.h> |
4 | 5 | #include <gtest/gtest.h> |
@@ -190,5 +191,62 @@ TEST(TensorBodyTest, IndexPutAccumulateTrue) { |
190 | 191 | file.saveFile(); |
191 | 192 | } |
192 | 193 |
|
| 194 | +TEST(TensorBodyTest, IndexPutTensorIndexNoneValue) { |
| 195 | + auto options = at::TensorOptions().dtype(at::kFloat).device(at::kCPU); |
| 196 | + at::Tensor base = at::zeros({2, 3}, options); |
| 197 | + at::Tensor values = at::full({1, 2, 3}, 6.0f, options); |
| 198 | + |
| 199 | + base.index_put_({at::indexing::None}, values); |
| 200 | + |
| 201 | + auto file_name = g_custom_param.get(); |
| 202 | + FileManerger file(file_name); |
| 203 | + file.openAppend(); |
| 204 | + file << "IndexPutTensorIndexNoneValue "; |
| 205 | + write_index_result_to_file(&file, base); |
| 206 | + file << "\n"; |
| 207 | + file.saveFile(); |
| 208 | +} |
| 209 | + |
| 210 | +TEST(TensorBodyTest, IndexPutTensorIndexTensorNoneAndSlice) { |
| 211 | + auto options = at::TensorOptions().dtype(at::kFloat).device(at::kCPU); |
| 212 | + at::Tensor base = at::zeros({3, 4}, options); |
| 213 | + at::Tensor idx = tensor_from_vector_i64({2, 0}); |
| 214 | + at::Tensor values = at::full({2, 1, 4}, 8.0f, options); |
| 215 | + |
| 216 | + base.index_put_({idx, at::indexing::None, at::indexing::Slice()}, values); |
| 217 | + |
| 218 | + auto file_name = g_custom_param.get(); |
| 219 | + FileManerger file(file_name); |
| 220 | + file.openAppend(); |
| 221 | + file << "IndexPutTensorIndexTensorNoneAndSlice "; |
| 222 | + file << std::to_string(base.dim()) << " "; |
| 223 | + file << std::to_string(base.numel()) << " "; |
| 224 | + file << std::to_string(base.sizes()[0]) << " "; |
| 225 | + file << std::to_string(base.sizes()[1]) << " "; |
| 226 | + at::Tensor cont = base.contiguous(); |
| 227 | + float* data = cont.data_ptr<float>(); |
| 228 | + file << std::to_string(data[0]) << " "; |
| 229 | + file << std::to_string(data[4]) << " "; |
| 230 | + file << std::to_string(data[8]) << " "; |
| 231 | + file << std::to_string(cont.sum().item<float>()) << " "; |
| 232 | + file << "\n"; |
| 233 | + file.saveFile(); |
| 234 | +} |
| 235 | + |
| 236 | +TEST(TensorBodyTest, IndexPutTensorIndexNoneScalar) { |
| 237 | + auto options = at::TensorOptions().dtype(at::kFloat).device(at::kCPU); |
| 238 | + at::Tensor base = at::zeros({2, 3}, options); |
| 239 | + |
| 240 | + base.index_put_({at::indexing::None}, at::Scalar(4.0)); |
| 241 | + |
| 242 | + auto file_name = g_custom_param.get(); |
| 243 | + FileManerger file(file_name); |
| 244 | + file.openAppend(); |
| 245 | + file << "IndexPutTensorIndexNoneScalar "; |
| 246 | + write_index_result_to_file(&file, base); |
| 247 | + file << "\n"; |
| 248 | + file.saveFile(); |
| 249 | +} |
| 250 | + |
193 | 251 | } // namespace test |
194 | 252 | } // namespace at |
0 commit comments