@@ -234,6 +234,20 @@ TEST_F(TensorPtrMakerTest, CreateFull) {
234
234
EXPECT_EQ (tensor4->size (1 ), 5 );
235
235
EXPECT_EQ (tensor4->scalar_type (), executorch::aten::ScalarType::Double);
236
236
EXPECT_EQ (tensor4->const_data_ptr <double >()[0 ], 11 );
237
+
238
+ auto tensor5 = full ({4 , 5 }, 13 , executorch::aten::ScalarType::Half);
239
+ EXPECT_EQ (tensor5->dim (), 2 );
240
+ EXPECT_EQ (tensor5->size (0 ), 4 );
241
+ EXPECT_EQ (tensor5->size (1 ), 5 );
242
+ EXPECT_EQ (tensor5->scalar_type (), executorch::aten::ScalarType::Half);
243
+ EXPECT_EQ (tensor5->const_data_ptr <executorch::aten::Half>()[0 ], 13 );
244
+
245
+ auto tensor6 = full ({4 , 5 }, 15 , executorch::aten::ScalarType::BFloat16);
246
+ EXPECT_EQ (tensor6->dim (), 2 );
247
+ EXPECT_EQ (tensor6->size (0 ), 4 );
248
+ EXPECT_EQ (tensor6->size (1 ), 5 );
249
+ EXPECT_EQ (tensor6->scalar_type (), executorch::aten::ScalarType::BFloat16);
250
+ EXPECT_EQ (tensor6->const_data_ptr <executorch::aten::BFloat16>()[0 ], 15 );
237
251
}
238
252
239
253
TEST_F (TensorPtrMakerTest, CreateScalar) {
@@ -363,6 +377,36 @@ TEST_F(TensorPtrMakerTest, CreateRandTensorWithDoubleType) {
363
377
}
364
378
}
365
379
380
+ TEST_F (TensorPtrMakerTest, CreateRandTensorWithHalfType) {
381
+ auto tensor = rand ({4 , 5 }, executorch::aten::ScalarType::Half);
382
+
383
+ EXPECT_EQ (tensor->dim (), 2 );
384
+ EXPECT_EQ (tensor->size (0 ), 4 );
385
+ EXPECT_EQ (tensor->size (1 ), 5 );
386
+ EXPECT_EQ (tensor->scalar_type (), executorch::aten::ScalarType::Half);
387
+
388
+ for (auto i = 0 ; i < tensor->numel (); ++i) {
389
+ auto val = tensor->const_data_ptr <executorch::aten::Half>()[i];
390
+ EXPECT_GE (val, 0.0 );
391
+ EXPECT_LT (val, 1.0 );
392
+ }
393
+ }
394
+
395
+ TEST_F (TensorPtrMakerTest, CreateRandTensorWithBFloatType) {
396
+ auto tensor = rand ({4 , 5 }, executorch::aten::ScalarType::BFloat16);
397
+
398
+ EXPECT_EQ (tensor->dim (), 2 );
399
+ EXPECT_EQ (tensor->size (0 ), 4 );
400
+ EXPECT_EQ (tensor->size (1 ), 5 );
401
+ EXPECT_EQ (tensor->scalar_type (), executorch::aten::ScalarType::BFloat16);
402
+
403
+ for (auto i = 0 ; i < tensor->numel (); ++i) {
404
+ auto val = tensor->const_data_ptr <executorch::aten::BFloat16>()[i];
405
+ EXPECT_GE (val, 0.0 );
406
+ EXPECT_LT (val, 1.0 );
407
+ }
408
+ }
409
+
366
410
TEST_F (TensorPtrMakerTest, CreateRandnTensor) {
367
411
auto tensor = randn ({100 , 100 });
368
412
0 commit comments