@@ -154,21 +154,24 @@ TEST(PrintEvalueTest, NaNDouble) {
154
154
155
155
TEST (PrintEvalueTest, EmptyString) {
156
156
std::string str = " " ;
157
- EValue value (str.c_str (), str.size ());
157
+ ArrayRef<char > str_ref (const_cast <char *>(str.c_str ()), str.size ());
158
+ EValue value (&str_ref);
158
159
expect_output (value, " \"\" " );
159
160
}
160
161
161
162
TEST (PrintEvalueTest, BasicString) {
162
163
// No escaping required.
163
164
std::string str = " Test Data" ;
164
- EValue value (str.c_str (), str.size ());
165
+ ArrayRef<char > str_ref (const_cast <char *>(str.c_str ()), str.size ());
166
+ EValue value (&str_ref);
165
167
expect_output (value, " \" Test Data\" " );
166
168
}
167
169
168
170
TEST (PrintEvalueTest, EscapedString) {
169
171
// Contains characters that need to be escaped.
170
172
std::string str = " double quote: \" backslash: \\ " ;
171
- EValue value (str.c_str (), str.size ());
173
+ ArrayRef<char > str_ref (const_cast <char *>(str.c_str ()), str.size ());
174
+ EValue value (&str_ref);
172
175
expect_output (value, " \" double quote: \\\" backslash: \\\\\" " );
173
176
}
174
177
@@ -267,31 +270,38 @@ TEST(PrintEvalueTest, UnelidedBoolLists) {
267
270
// case; the other scalar types use the same underlying code, so they don't
268
271
// need to test this again.
269
272
{
270
- EValue value (ArrayRef<bool >(list.data (), static_cast <size_t >(0ul )));
273
+ ArrayRef<bool > bool_ref (list.data (), static_cast <size_t >(0ul );
274
+ EValue value (&bool_ref));
271
275
expect_output (value, " (len=0)[]" );
272
276
}
273
277
{
274
- EValue value (ArrayRef<bool >(list.data (), 1 ));
278
+ ArrayRef<bool > bool_ref (list.data (), 1 );
279
+ EValue value (&bool_ref);
275
280
expect_output (value, " (len=1)[True]" );
276
281
}
277
282
{
278
- EValue value (ArrayRef<bool >(list.data (), 2 ));
283
+ ArrayRef<bool > bool_ref (list.data (), 2 );
284
+ EValue value (&bool_ref);
279
285
expect_output (value, " (len=2)[True, False]" );
280
286
}
281
287
{
282
- EValue value (ArrayRef<bool >(list.data (), 3 ));
288
+ ArrayRef<bool > bool_ref (list.data (), 3 );
289
+ EValue value (&bool_ref);
283
290
expect_output (value, " (len=3)[True, False, True]" );
284
291
}
285
292
{
286
- EValue value (ArrayRef<bool >(list.data (), 4 ));
293
+ ArrayRef<bool > bool_ref (list.data (), 4 );
294
+ EValue value (&bool_ref);
287
295
expect_output (value, " (len=4)[True, False, True, False]" );
288
296
}
289
297
{
290
- EValue value (ArrayRef<bool >(list.data (), 5 ));
298
+ ArrayRef<bool > bool_ref (list.data (), 5 );
299
+ EValue value (&bool_ref);
291
300
expect_output (value, " (len=5)[True, False, True, False, True]" );
292
301
}
293
302
{
294
- EValue value (ArrayRef<bool >(list.data (), 6 ));
303
+ ArrayRef<bool > bool_ref (list.data (), 6 );
304
+ EValue value (&bool_ref);
295
305
expect_output (value, " (len=6)[True, False, True, False, True, False]" );
296
306
}
297
307
}
@@ -302,16 +312,19 @@ TEST(PrintEvalueTest, ElidedBoolLists) {
302
312
303
313
{
304
314
// Default edge items is 3, so the shortest elided list length is 7.
305
- EValue value (ArrayRef<bool >(list.data (), 7 ));
315
+ ArrayRef<bool > bool_ref (list.data (), 7 );
316
+ EValue value (&bool_ref);
306
317
expect_output (value, " (len=7)[True, False, True, ..., True, False, True]" );
307
318
}
308
319
{
309
- EValue value (ArrayRef<bool >(list.data (), 8 ));
320
+ ArrayRef<bool > bool_ref (list.data (), 8 );
321
+ EValue value (&bool_ref);
310
322
expect_output (value, " (len=8)[True, False, True, ..., False, True, False]" );
311
323
}
312
324
{
313
325
// Multi-digit length.
314
- EValue value (ArrayRef<bool >(list.data (), 10 ));
326
+ ArrayRef<bool > bool_ref (list.data (), 10 );
327
+ EValue value (&bool_ref);
315
328
expect_output (
316
329
value, " (len=10)[True, False, True, ..., False, True, False]" );
317
330
}
@@ -342,19 +355,19 @@ TEST(PrintEvalueTest, UnelidedIntLists) {
342
355
{
343
356
BoxedEvalueList<int64_t > list (
344
357
wrapped_values.data (), unwrapped_values.data (), 0 );
345
- EValue value (list);
358
+ EValue value (& list);
346
359
expect_output (value, " (len=0)[]" );
347
360
}
348
361
{
349
362
BoxedEvalueList<int64_t > list (
350
363
wrapped_values.data (), unwrapped_values.data (), 3 );
351
- EValue value (list);
364
+ EValue value (& list);
352
365
expect_output (value, " (len=3)[-2, -1, 0]" );
353
366
}
354
367
{
355
368
BoxedEvalueList<int64_t > list (
356
369
wrapped_values.data (), unwrapped_values.data (), 6 );
357
- EValue value (list);
370
+ EValue value (& list);
358
371
expect_output (value, " (len=6)[-2, -1, 0, 1, 2, 3]" );
359
372
}
360
373
}
@@ -392,20 +405,20 @@ TEST(PrintEvalueTest, ElidedIntLists) {
392
405
// Default edge items is 3, so the shortest elided list length is 7.
393
406
BoxedEvalueList<int64_t > list (
394
407
wrapped_values.data (), unwrapped_values.data (), 7 );
395
- EValue value (list);
408
+ EValue value (& list);
396
409
expect_output (value, " (len=7)[-4, -3, -2, ..., 0, 1, 2]" );
397
410
}
398
411
{
399
412
BoxedEvalueList<int64_t > list (
400
413
wrapped_values.data (), unwrapped_values.data (), 8 );
401
- EValue value (list);
414
+ EValue value (& list);
402
415
expect_output (value, " (len=8)[-4, -3, -2, ..., 1, 2, 3]" );
403
416
}
404
417
{
405
418
// Multi-digit length.
406
419
BoxedEvalueList<int64_t > list (
407
420
wrapped_values.data (), unwrapped_values.data (), 10 );
408
- EValue value (list);
421
+ EValue value (& list);
409
422
expect_output (value, " (len=10)[-4, -3, -2, ..., 3, 4, 5]" );
410
423
}
411
424
}
@@ -419,15 +432,18 @@ TEST(PrintEvalueTest, UnelidedDoubleLists) {
419
432
std::array<double , 6 > list = {-2.2 , -1 , 0 , INFINITY, NAN, 3.3 };
420
433
421
434
{
422
- EValue value (ArrayRef<double >(list.data (), static_cast <size_t >(0ul )));
435
+ ArrayRef<double > double_ref (list.data (), static_cast <size_t >(0ul );
436
+ EValue value (&double_ref));
423
437
expect_output (value, " (len=0)[]" );
424
438
}
425
439
{
426
- EValue value (ArrayRef<double >(list.data (), 3 ));
440
+ ArrayRef<double > double_ref (list.data (), 3 );
441
+ EValue value (&double_ref);
427
442
expect_output (value, " (len=3)[-2.2, -1., 0.]" );
428
443
}
429
444
{
430
- EValue value (ArrayRef<double >(list.data (), 6 ));
445
+ ArrayRef<double > double_ref (list.data (), 6 );
446
+ EValue value (&double_ref);
431
447
expect_output (value, " (len=6)[-2.2, -1., 0., inf, nan, 3.3]" );
432
448
}
433
449
}
@@ -438,16 +454,19 @@ TEST(PrintEvalueTest, ElidedDoubleLists) {
438
454
439
455
{
440
456
// Default edge items is 3, so the shortest elided list length is 7.
441
- EValue value (ArrayRef<double >(list.data (), 7 ));
457
+ ArrayRef<double > double_ref (list.data (), 7 );
458
+ EValue value (&double_ref);
442
459
expect_output (value, " (len=7)[-4.4, -3., -2.2, ..., 0., inf, nan]" );
443
460
}
444
461
{
445
- EValue value (ArrayRef<double >(list.data (), 8 ));
462
+ ArrayRef<double > double_ref (list.data (), 8 );
463
+ EValue value (&double_ref);
446
464
expect_output (value, " (len=8)[-4.4, -3., -2.2, ..., inf, nan, 3.3]" );
447
465
}
448
466
{
449
467
// Multi-digit length.
450
- EValue value (ArrayRef<double >(list.data (), 10 ));
468
+ ArrayRef<double > double_ref (list.data (), 10 );
469
+ EValue value (&double_ref);
451
470
expect_output (value, " (len=10)[-4.4, -3., -2.2, ..., 3.3, 4., 5.5]" );
452
471
}
453
472
}
@@ -503,7 +522,7 @@ void expect_tensor_list_output(size_t num_tensors, const char* expected) {
503
522
ASSERT_LE (num_tensors, wrapped_values.size ());
504
523
BoxedEvalueList<executorch::aten::Tensor> list (
505
524
wrapped_values.data (), unwrapped_values, num_tensors);
506
- EValue value (list);
525
+ EValue value (& list);
507
526
expect_output (value, expected);
508
527
}
509
528
@@ -579,7 +598,7 @@ void expect_list_optional_tensor_output(
579
598
ASSERT_LE (num_tensors, wrapped_values.size ());
580
599
BoxedEvalueList<std::optional<executorch::aten::Tensor>> list (
581
600
wrapped_values.data (), unwrapped_values, num_tensors);
582
- EValue value (list);
601
+ EValue value (& list);
583
602
expect_output (value, expected);
584
603
}
585
604
@@ -628,7 +647,8 @@ TEST(PrintEvalueTest, UnknownTag) {
628
647
629
648
TEST (PrintEvalueTest, EdgeItemsOverride) {
630
649
std::array<double , 7 > list = {-3.0 , -2.2 , -1 , 0 , 3.3 , 4.0 , 5.5 };
631
- EValue value (ArrayRef<double >(list.data (), 7 ));
650
+ ArrayRef<double > double_ref (list.data (), 7 );
651
+ EValue value (&double_ref);
632
652
633
653
{
634
654
// Default edge items is 3, so this should elide.
@@ -653,7 +673,8 @@ TEST(PrintEvalueTest, EdgeItemsOverride) {
653
673
654
674
TEST (PrintEvalueTest, EdgeItemsDefaults) {
655
675
std::array<double , 7 > list = {-3.0 , -2.2 , -1 , 0 , 3.3 , 4.0 , 5.5 };
656
- EValue value (ArrayRef<double >(list.data (), 7 ));
676
+ ArrayRef<double > double_ref (list.data (), 7 );
677
+ EValue value (&double_ref);
657
678
658
679
{
659
680
// Default edge items is 3, so this should elide.
@@ -680,7 +701,8 @@ TEST(PrintEvalueTest, EdgeItemsDefaults) {
680
701
681
702
TEST (PrintEvalueTest, EdgeItemsSingleStream) {
682
703
std::array<double , 7 > list = {-3.0 , -2.2 , -1 , 0 , 3.3 , 4.0 , 5.5 };
683
- EValue value (ArrayRef<double >(list.data (), 7 ));
704
+ ArrayRef<double > double_ref (list.data (), 7 );
705
+ EValue value (&double_ref);
684
706
std::ostringstream os_before;
685
707
686
708
// Print to the same stream multiple times, showing that evalue_edge_items
@@ -750,7 +772,8 @@ TEST(PrintEvalueTest, ListWrapping) {
750
772
751
773
{
752
774
// Should elide by default and print on a single line.
753
- EValue value (ArrayRef<double >(list.data (), list.size ()));
775
+ ArrayRef<double > double_ref (list.data (), list.size ());
776
+ EValue value (&double_ref);
754
777
755
778
std::ostringstream os;
756
779
os << value;
@@ -759,7 +782,8 @@ TEST(PrintEvalueTest, ListWrapping) {
759
782
{
760
783
// Exactly the per-line length should not wrap when increasing the number of
761
784
// edge items to disable elision.
762
- EValue value (ArrayRef<double >(list.data (), kItemsPerLine ));
785
+ ArrayRef<double > double_ref (list.data (), kItemsPerLine );
786
+ EValue value (&double_ref);
763
787
764
788
std::ostringstream os;
765
789
os << torch::executor::util::evalue_edge_items (1000 ) << value;
@@ -768,7 +792,8 @@ TEST(PrintEvalueTest, ListWrapping) {
768
792
}
769
793
{
770
794
// One more than the per-line length should wrap; no elision.
771
- EValue value (ArrayRef<double >(list.data (), kItemsPerLine + 1 ));
795
+ ArrayRef<double > double_ref (list.data (), kItemsPerLine + 1 );
796
+ EValue value (&double_ref);
772
797
773
798
std::ostringstream os;
774
799
os << torch::executor::util::evalue_edge_items (1000 ) << value;
@@ -781,7 +806,8 @@ TEST(PrintEvalueTest, ListWrapping) {
781
806
}
782
807
{
783
808
// Exactly twice the per-line length, without elision.
784
- EValue value (ArrayRef<double >(list.data (), kItemsPerLine * 2 ));
809
+ ArrayRef<double > double_ref (list.data (), kItemsPerLine * 2 );
810
+ EValue value (&double_ref);
785
811
786
812
std::ostringstream os;
787
813
os << torch::executor::util::evalue_edge_items (1000 ) << value;
@@ -795,7 +821,8 @@ TEST(PrintEvalueTest, ListWrapping) {
795
821
}
796
822
{
797
823
// Exactly one whole line, with elision.
798
- EValue value (ArrayRef<double >(list.data (), kItemsPerLine * 3 ));
824
+ ArrayRef<double > double_ref (list.data (), kItemsPerLine * 3 );
825
+ EValue value (&double_ref);
799
826
800
827
std::ostringstream os;
801
828
os << torch::executor::util::evalue_edge_items (kItemsPerLine ) << value;
@@ -810,7 +837,8 @@ TEST(PrintEvalueTest, ListWrapping) {
810
837
}
811
838
{
812
839
// Edge item count slightly larger than per-line length, with elision.
813
- EValue value (ArrayRef<double >(list.data (), kItemsPerLine * 3 ));
840
+ ArrayRef<double > double_ref (list.data (), kItemsPerLine * 3 );
841
+ EValue value (&double_ref);
814
842
815
843
std::ostringstream os;
816
844
os << torch::executor::util::evalue_edge_items (kItemsPerLine + 1 ) << value;
@@ -829,7 +857,8 @@ TEST(PrintEvalueTest, ListWrapping) {
829
857
}
830
858
{
831
859
// Large wrapped, ragged, elided example.
832
- EValue value (ArrayRef<double >(list.data (), list.size ()));
860
+ ArrayRef<double > double_ref (list.data (), list.size ());
861
+ EValue value (&double_ref);
833
862
834
863
std::ostringstream os;
835
864
os << torch::executor::util::evalue_edge_items (33 ) << value;
@@ -946,7 +975,7 @@ TEST(PrintEvalueTest, WrappedTensorLists) {
946
975
// Demonstrate the formatting when printing a list with multiple tensors.
947
976
BoxedEvalueList<executorch::aten::Tensor> list (
948
977
wrapped_values.data (), unwrapped_values, wrapped_values.size ());
949
- EValue value (list);
978
+ EValue value (& list);
950
979
951
980
std::ostringstream os;
952
981
os << torch::executor::util::evalue_edge_items (15 ) << value;
0 commit comments