@@ -86,6 +86,9 @@ pub struct StanModel {
8686
8787/// Return meta information about the constrained parameters of the model
8888fn params ( var_string : & str ) -> anyhow:: Result < Vec < Parameter > > {
89+ if var_string. is_empty ( ) {
90+ return Ok ( vec ! [ ] ) ;
91+ }
8992 // Parse each variable string into (name, is_complex, indices)
9093 let parsed_variables: anyhow:: Result < Vec < ( String , bool , Vec < usize > ) > > = var_string
9194 . split ( ',' )
@@ -540,6 +543,7 @@ pub struct StanTrace<'model> {
540543 trace : Vec < Vec < f64 > > ,
541544 expanded_buffer : Box < [ f64 ] > ,
542545 rng : bridgestan:: Rng < & ' model bridgestan:: StanLibrary > ,
546+ count : usize ,
543547}
544548
545549impl < ' model > Clone for StanTrace < ' model > {
@@ -559,6 +563,7 @@ impl<'model> Clone for StanTrace<'model> {
559563 trace : self . trace . clone ( ) ,
560564 expanded_buffer : self . expanded_buffer . clone ( ) ,
561565 rng,
566+ count : self . count ,
562567 }
563568 }
564569}
@@ -591,6 +596,7 @@ impl<'model> DrawStorage for StanTrace<'model> {
591596 // We need to transpose
592597 fortran_to_c_order ( slice, & var. shape , trace) ;
593598 }
599+ self . count += 1 ;
594600 Ok ( ( ) )
595601 }
596602
@@ -613,7 +619,7 @@ impl<'model> DrawStorage for StanTrace<'model> {
613619 . unzip ( ) ;
614620
615621 Ok ( Arc :: new (
616- StructArray :: try_new ( fields. into ( ) , arrays, None )
622+ StructArray :: try_new_with_length ( fields. into ( ) , arrays, None , self . count )
617623 . context ( "Could not create arrow StructArray" ) ?,
618624 ) )
619625 }
@@ -649,6 +655,7 @@ impl Model for StanModel {
649655 trace,
650656 rng,
651657 expanded_buffer : buffer. into ( ) ,
658+ count : 0 ,
652659 } )
653660 }
654661
@@ -734,6 +741,10 @@ mod tests {
734741
735742 #[ test]
736743 fn parse_vars ( ) {
744+ let vars = "" ;
745+ let parsed = super :: params ( vars) . unwrap ( ) ;
746+ assert ! ( parsed. len( ) == 0 ) ;
747+
737748 let vars = "x.1.1,x.2.1,x.3.1,x.1.2,x.2.2,x.3.2" ;
738749 let parsed = super :: params ( vars) . unwrap ( ) ;
739750 assert ! ( parsed. len( ) == 1 ) ;
0 commit comments