@@ -525,6 +525,58 @@ test_that("time from read_cmdstan_csv matches time from fit$time()", {
525525 )
526526})
527527
528+ test_that(" returning time works for gq read_cmdstan_csv from static CSV" , {
529+ csv_files <- test_path(" resources" , " csv" , " bernoulli_ppc-1-gq-with-timing.csv" )
530+ csv_data <- read_cmdstan_csv(csv_files )
531+ expect_equal(csv_data $ time $ total , NA_integer_ )
532+ expect_equal(csv_data $ time $ chains , data.frame (
533+ chain_id = 1 ,
534+ total = 0.123
535+ ))
536+
537+ csv_files <- c(
538+ test_path(" resources" , " csv" , " bernoulli_ppc-1-gq-with-timing.csv" ),
539+ test_path(" resources" , " csv" , " bernoulli_ppc-2-gq-with-timing.csv" )
540+ )
541+ csv_data <- read_cmdstan_csv(csv_files )
542+ expect_equal(csv_data $ time $ total , NA_integer_ )
543+ expect_equal(csv_data $ time $ chains , data.frame (
544+ chain_id = c(1 , 2 ),
545+ total = c(0.123 , 0.456 )
546+ ))
547+ })
548+
549+ test_that(" returning time works for gq read_cmdstan_csv from fit object" , {
550+ gq_csv <- read_cmdstan_csv(fit_gq $ output_files())
551+ expect_equal(gq_csv $ time $ total , NA_integer_ )
552+ checkmate :: expect_data_frame(
553+ gq_csv $ time $ chains ,
554+ any.missing = FALSE ,
555+ types = c(" numeric" , " numeric" ),
556+ nrows = fit_gq $ num_chains(),
557+ ncols = 2
558+ )
559+ expect_named(gq_csv $ time $ chains , c(" chain_id" , " total" ))
560+ expect_true(all(gq_csv $ time $ chains $ total > 0 ))
561+ })
562+
563+ test_that(" gq time from read_cmdstan_csv matches time from fit_gq$time()" , {
564+ expect_equivalent(
565+ read_cmdstan_csv(fit_gq $ output_files())$ time $ chains ,
566+ fit_gq $ time()$ chains
567+ )
568+ })
569+
570+ test_that(" returning time is NULL for gq CSV without timing" , {
571+ csv_files <- test_path(" resources" , " csv" , " bernoulli_ppc-1-gq.csv" )
572+ csv_data <- read_cmdstan_csv(csv_files )
573+ expect_equal(csv_data $ time $ total , NA_integer_ )
574+ expect_equal(csv_data $ time $ chains , data.frame (
575+ chain_id = 1 ,
576+ total = 0
577+ ))
578+ })
579+
528580test_that(" read_cmdstan_csv reads seed correctly" , {
529581 opt <- read_cmdstan_csv(fit_bernoulli_optimize $ output_files())
530582 vi <- read_cmdstan_csv(fit_bernoulli_variational $ output_files())
0 commit comments