Skip to content

Commit

Permalink
support vstat -o 7 -d
Browse files Browse the repository at this point in the history
  • Loading branch information
takenori-y committed Nov 9, 2023
1 parent f9ab80e commit 058615f
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 17 deletions.
42 changes: 33 additions & 9 deletions src/main/vstat.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<double> 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;
}
}
}

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -541,6 +552,7 @@ int main(int argc, char* argv[]) {

double num_data;
std::vector<double> first(vector_length);
std::vector<double> 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)) {
Expand All @@ -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<int>(num_data), first, second,
Expand Down
3 changes: 1 addition & 2 deletions test/test_mgc2sp.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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 ]
Expand Down
13 changes: 7 additions & 6 deletions test/test_vstat.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 058615f

Please sign in to comment.