@@ -368,3 +368,90 @@ TEMPLATE_TEST_CASE(
368368    CHECK (X.ids ()[i] == Z.ids ()[i]);
369369  }
370370}
371+ 
372+ TEST_CASE (" tdb_matrix_with_ids: time travel"  , " [tdb_matrix_with_ids]"  ) {
373+   tiledb::Context ctx;
374+   std::string tmp_matrix_uri =
375+       (std::filesystem::temp_directory_path () / " tmp_tdb_matrix"  ).string ();
376+   std::string tmp_ids_uri =
377+       (std::filesystem::temp_directory_path () / " tmp_ids_vector"  ).string ();
378+ 
379+   int  offset = 13 ;
380+ 
381+   size_t  Mrows = 40 ;
382+   size_t  Ncols = 20 ;
383+ 
384+   tiledb::VFS vfs (ctx);
385+   if  (vfs.is_dir (tmp_matrix_uri)) {
386+     vfs.remove_dir (tmp_matrix_uri);
387+   }
388+   if  (vfs.is_dir (tmp_ids_uri)) {
389+     vfs.remove_dir (tmp_ids_uri);
390+   }
391+ 
392+   auto  X = ColMajorMatrixWithIds<float , uint64_t , size_t >(Mrows, Ncols);
393+   fill_and_write_matrix (
394+       ctx,
395+       X,
396+       tmp_matrix_uri,
397+       tmp_ids_uri,
398+       Mrows,
399+       Ncols,
400+       offset,
401+       TemporalPolicy{TimeTravel, 50 });
402+ 
403+   {
404+     //  We can load the matrix at the creation timestamp.
405+     auto  Y = tdbColMajorPreLoadMatrixWithIds<float , uint64_t , size_t >(
406+         ctx, tmp_matrix_uri, tmp_ids_uri, 0 , TemporalPolicy{TimeTravel, 50 });
407+     CHECK (num_vectors (Y) == num_vectors (X));
408+     CHECK (dimension (Y) == dimension (X));
409+     CHECK (std::equal (
410+         X.data (), X.data () + dimension (X) * num_vectors (X), Y.data ()));
411+     for  (size_t  i = 0 ; i < Mrows; ++i) {
412+       for  (size_t  j = 0 ; j < Ncols; ++j) {
413+         CHECK (X (i, j) == Y (i, j));
414+       }
415+     }
416+   }
417+ 
418+   {
419+     //  We can load the matrix at a later timestamp.
420+     auto  Y = tdbColMajorPreLoadMatrixWithIds<float , uint64_t , size_t >(
421+         ctx, tmp_matrix_uri, tmp_ids_uri, 0 , TemporalPolicy{TimeTravel, 100 });
422+     CHECK (num_vectors (Y) == num_vectors (X));
423+     CHECK (dimension (Y) == dimension (X));
424+     CHECK (std::equal (
425+         X.data (), X.data () + dimension (X) * num_vectors (X), Y.data ()));
426+     for  (size_t  i = 0 ; i < Mrows; ++i) {
427+       for  (size_t  j = 0 ; j < Ncols; ++j) {
428+         CHECK (X (i, j) == Y (i, j));
429+       }
430+     }
431+   }
432+ 
433+   {
434+     //  We get no data if we load the matrix at an earlier timestamp.
435+     auto  Y = tdbColMajorPreLoadMatrixWithIds<float , uint64_t , size_t >(
436+         ctx, tmp_matrix_uri, tmp_ids_uri, 0 , TemporalPolicy{TimeTravel, 5 });
437+     CHECK (num_vectors (Y) == 0 );
438+     CHECK (dimension (Y) == 0 );
439+     CHECK (Y.size () == 0 );
440+   }
441+ 
442+   {
443+     //  We get no data if we load the matrix at an earlier timestamp, even if we
444+     //  specify we want to read 4 rows and 2 cols.
445+     auto  Y = tdbColMajorPreLoadMatrixWithIds<float , uint64_t , size_t >(
446+         ctx,
447+         tmp_matrix_uri,
448+         tmp_ids_uri,
449+         4 ,
450+         2 ,
451+         0 ,
452+         TemporalPolicy{TimeTravel, 5 });
453+     CHECK (num_vectors (Y) == 0 );
454+     CHECK (dimension (Y) == 0 );
455+     CHECK (Y.size () == 0 );
456+   }
457+ }
0 commit comments