Skip to content

Commit 5bf7cff

Browse files
committed
Fix bugs in PolynomialPathFitter related to the number of input coordinate samples
1 parent d374608 commit 5bf7cff

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

Diff for: OpenSim/Actuators/PolynomialPathFitter.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,12 @@ void PolynomialPathFitter::run() {
170170
"Expected 'num_parallel_threads' to be between 1 and {}, but "
171171
"received {}.", std::thread::hardware_concurrency(),
172172
get_num_parallel_threads())
173+
OPENSIM_THROW_IF_FRMOBJ(
174+
static_cast<int>(values.getNumRows()) < get_num_parallel_threads(),
175+
Exception, "Expected the number of time points in the coordinate "
176+
"values table to be greater than 'num_parallel_threads', but "
177+
"received {} and {}, respectively.",
178+
values.getNumRows(), get_num_parallel_threads())
173179
log_info("Number of parallel threads = {}", get_num_parallel_threads());
174180

175181
// Number of samples per frame.
@@ -662,7 +668,8 @@ TimeSeriesTable PolynomialPathFitter::sampleCoordinateValues(
662668
int timeIdx = 0;
663669
const auto& times = values.getIndependentColumn();
664670
TimeSeriesTable valuesSampled;
665-
double dt = (times[1] - times[0]) / (get_num_samples_per_frame() + 2);
671+
double dt = (times.size() < 2) ? 0.01 :
672+
(times[1] - times[0]) / (get_num_samples_per_frame() + 2);
666673
for (int i = 0; i < get_num_parallel_threads(); ++i) {
667674
int numTimeIndexes = outputs[i].nrow() / get_num_samples_per_frame();
668675
for (int j = 0; j < numTimeIndexes; ++j) {

Diff for: OpenSim/Actuators/Test/testPolynomialPathFitter.cpp

+17-2
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,9 @@ namespace {
5757
return processor;
5858
}
5959

60-
TableProcessor createCoordinatesTable(bool correctLabel, bool addMetaData) {
61-
SimTK::Vector column = SimTK::Test::randVector(100);
60+
TableProcessor createCoordinatesTable(bool correctLabel, bool addMetaData,
61+
int numRows = 100) {
62+
SimTK::Vector column = SimTK::Test::randVector(numRows);
6263
std::vector<double> times;
6364
times.reserve(column.size());
6465
for (int i = 0; i < column.size(); ++i) {
@@ -130,3 +131,17 @@ TEST_CASE("Invalid configurations") {
130131
"Expected 'maximum_polynomial_order' to be at most 9"));
131132
}
132133
}
134+
135+
TEST_CASE("Number of rows less than the number of threads") {
136+
int numAvailableThreads = std::thread::hardware_concurrency();
137+
int numRows = (numAvailableThreads == 1) ? 1 : numAvailableThreads - 1;
138+
CAPTURE(numAvailableThreads);
139+
CAPTURE(numRows);
140+
141+
PolynomialPathFitter fitter;
142+
fitter.setModel(createHangingMuscleModel());
143+
fitter.setCoordinateValues(createCoordinatesTable(true, true, numRows));
144+
fitter.setNumParallelThreads(numAvailableThreads);
145+
REQUIRE_THROWS_WITH(fitter.run(), ContainsSubstring(
146+
"Expected the number of time points in the coordinate values table"));
147+
}

0 commit comments

Comments
 (0)