From 058615fe784f3520713cdff1aca7092339d341f4 Mon Sep 17 00:00:00 2001 From: takenori-y Date: Thu, 9 Nov 2023 16:51:51 +0900 Subject: [PATCH] support vstat -o 7 -d --- src/main/vstat.cc | 42 +++++++++++++++++++++++++++++++++--------- test/test_mgc2sp.bats | 3 +-- test/test_vstat.bats | 13 +++++++------ 3 files changed, 41 insertions(+), 17 deletions(-) diff --git a/src/main/vstat.cc b/src/main/vstat.cc index c7b1dc74..ac7dbb6d 100644 --- a/src/main/vstat.cc +++ b/src/main/vstat.cc @@ -80,7 +80,7 @@ void PrintUsage(std::ostream* stream) { *stream << " stdout:" << std::endl; *stream << " statistics (double)" << std::endl; *stream << " notice:" << std::endl; - *stream << " -d is valid only if o = 0 or o = 2" << std::endl; + *stream << " -d is valid only if o = 0, 2 or 7" << std::endl; *stream << " -s can be specified multiple times" << std::endl; *stream << std::endl; *stream << " SPTK: version " << sptk::kVersion << std::endl; @@ -212,8 +212,18 @@ bool OutputStatistics(const sptk::StatisticsAccumulation& accumulation, if (!accumulation.GetSecond(buffer, &second)) { return false; } - if (!sptk::WriteStream(second, &std::cout)) { - return false; + if (outputs_only_diagonal_elements) { + std::vector tmp(vector_length); + if (!second.GetDiagonal(&tmp)) { + return false; + } + if (!sptk::WriteStream(0, vector_length, tmp, &std::cout, NULL)) { + return false; + } + } else { + if (!sptk::WriteStream(second, &std::cout)) { + return false; + } } } @@ -509,7 +519,8 @@ int main(int argc, char* argv[]) { std::istream& input_stream(ifs.is_open() ? ifs : std::cin); bool diagonal(false); - if (kMeanAndCovariance == output_format || kCovariance == output_format) { + if (kMeanAndCovariance == output_format || kCovariance == output_format || + kSufficientStatistics == output_format) { if (outputs_only_diagonal_elements) { diagonal = true; } @@ -541,6 +552,7 @@ int main(int argc, char* argv[]) { double num_data; std::vector first(vector_length); + std::vector tmp(vector_length); sptk::SymmetricMatrix second(vector_length); while (sptk::ReadStream(&num_data, &ifs2)) { if (!sptk::ReadStream(false, 0, 0, vector_length, &first, &ifs2, NULL)) { @@ -550,11 +562,23 @@ int main(int argc, char* argv[]) { return 1; } - if (!sptk::ReadStream(&second, &ifs2)) { - std::ostringstream error_message; - error_message << "Failed to read statistics (second order) in " << file; - sptk::PrintErrorMessage("vstat", error_message); - return 1; + if (diagonal) { + if (!sptk::ReadStream(false, 0, 0, vector_length, &tmp, &ifs2, NULL) || + !second.SetDiagonal(tmp)) { + std::ostringstream error_message; + error_message << "Failed to read statistics (second order) in " + << file; + sptk::PrintErrorMessage("vstat", error_message); + return 1; + } + } else { + if (!sptk::ReadStream(&second, &ifs2)) { + std::ostringstream error_message; + error_message << "Failed to read statistics (second order) in " + << file; + sptk::PrintErrorMessage("vstat", error_message); + return 1; + } } if (!accumulation.Merge(static_cast(num_data), first, second, diff --git a/test/test_mgc2sp.bats b/test/test_mgc2sp.bats index f2cea3bd..e97502f8 100755 --- a/test/test_mgc2sp.bats +++ b/test/test_mgc2sp.bats @@ -31,10 +31,9 @@ teardown() { $sptk3/step -v 0.1 -l 16 > $tmp/0 ary=("-o 0" "-o 1" "-o 2" "-o 3" "-p -o 0" "-p -o 1" "-p -o 2") for nu in "" "-n" "-u" "-n -u"; do + # shellcheck disable=SC2086 for o in $(seq 0 6); do - # shellcheck disable=SC2086 $sptk3/mgc2sp -m 15 -l 32 -a 0.1 -c 2 ${ary[$o]} $nu $tmp/0 > $tmp/1 - # shellcheck disable=SC2086 $sptk4/mgc2sp -m 15 -l 32 -a 0.1 -c 2 -o "$o" $nu $tmp/0 > $tmp/2 run $sptk4/aeq $tmp/1 $tmp/2 [ "$status" -eq 0 ] diff --git a/test/test_vstat.bats b/test/test_vstat.bats index 89913784..139b8399 100755 --- a/test/test_vstat.bats +++ b/test/test_vstat.bats @@ -64,16 +64,17 @@ teardown() { [ "$status" -eq 0 ] # Merge: - for opt in "" "-e" "-d" "-d -e"; do - $sptk3/bcut +d -l 2 -e 29 $tmp/0 | $sptk4/vstat -l 2 -o 7 $opt > $tmp/1 - $sptk3/bcut +d -l 2 -s 30 $tmp/0 | $sptk4/vstat -l 2 -o 7 $opt > $tmp/2 - echo | $sptk4/vstat -l 2 -s $tmp/1 -s $tmp/2 -o 0 $opt > $tmp/3 - $sptk4/vstat -l 2 $tmp/0 -o 0 $opt > $tmp/4 + # shellcheck disable=SC2086 + for de in "" "-d" "-e" "-d -e"; do + $sptk3/bcut +d -l 2 -e 29 $tmp/0 | $sptk4/vstat -l 2 -o 7 $de > $tmp/1 + $sptk3/bcut +d -l 2 -s 30 $tmp/0 | $sptk4/vstat -l 2 -o 7 $de > $tmp/2 + echo | $sptk4/vstat -l 2 -s $tmp/1 -s $tmp/2 -o 0 $de > $tmp/3 + $sptk4/vstat -l 2 $tmp/0 -o 0 $de > $tmp/4 run $sptk4/aeq $tmp/3 $tmp/4 [ "$status" -eq 0 ] cat $tmp/1 $tmp/2 > $tmp/5 - echo | $sptk4/vstat -l 2 -s $tmp/5 -o 0 $opt > $tmp/6 + echo | $sptk4/vstat -l 2 -s $tmp/5 -o 0 $de > $tmp/6 run $sptk4/aeq $tmp/3 $tmp/6 [ "$status" -eq 0 ] done