-
Notifications
You must be signed in to change notification settings - Fork 217
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix determinize issues #42
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -502,6 +502,53 @@ TEST(FsaAlgo, TopSort) { | |
} | ||
} | ||
|
||
class DeterminizeTest : public ::testing::Test { | ||
protected: | ||
DeterminizeTest() { | ||
std::vector<Arc> arcs = {{0, 4, 1}, {0, 1, 1}, {1, 2, 2}, {1, 3, 3}, | ||
{2, 7, 1}, {3, 7, 1}, {4, 6, 1}, {4, 6, 1}, | ||
{4, 5, 1}, {4, 8, -1}, {5, 8, -1}, {6, 8, -1}, | ||
{7, 8, -1}}; | ||
fsa_ = new Fsa(std::move(arcs), 8); | ||
num_states_ = fsa_->NumStates(); | ||
|
||
auto num_arcs = fsa_->arcs.size(); | ||
arc_weights_ = new float[num_arcs]; | ||
std::vector<float> weights = {1, 1, 2, 3, 4, 5, 2, 3, 3, 2, 4, 3, 5}; | ||
std::copy_n(weights.begin(), num_arcs, arc_weights_); | ||
|
||
max_wfsa_ = new WfsaWithFbWeights(*fsa_, arc_weights_, kMaxWeight); | ||
log_wfsa_ = new WfsaWithFbWeights(*fsa_, arc_weights_, kLogSumWeight); | ||
} | ||
|
||
~DeterminizeTest() { | ||
delete fsa_; | ||
delete[] arc_weights_; | ||
delete max_wfsa_; | ||
delete log_wfsa_; | ||
} | ||
|
||
WfsaWithFbWeights *max_wfsa_; | ||
WfsaWithFbWeights *log_wfsa_; | ||
Fsa *fsa_; | ||
int32_t num_states_; | ||
float *arc_weights_; | ||
}; | ||
|
||
TEST_F(DeterminizeTest, DeterminizePrunedMax) { | ||
Fsa b; | ||
std::vector<float> b_arc_weights; | ||
std::vector<std::vector<int32_t>> arc_derivs; | ||
DeterminizePrunedMax(*max_wfsa_, 10, 100, &b, &b_arc_weights, &arc_derivs); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just leave |
||
} | ||
|
||
TEST_F(DeterminizeTest, DeterminizePrunedLogSum) { | ||
Fsa b; | ||
std::vector<float> b_arc_weights; | ||
std::vector<std::vector<std::pair<int32_t, float>>> arc_derivs; | ||
DeterminizePrunedLogSum(*log_wfsa_, 10, 100, &b, &b_arc_weights, &arc_derivs); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd like, to have this code automatically: and if possible check that the arc_derivs make sense somehow, although that is more complex and can be left for now. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can merge this PR when you fix the other issue, though; you can work on this later. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will add all |
||
|
||
TEST(FsaAlgo, CreateFsa) { | ||
{ | ||
// clang-format off | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What was the problem with unique_ptr here? I made it unique_ptr as it's more lightweight than shared_ptr (and this is only ever owned in one place, I believed.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
priority_queue.top()
returns a const reference so we cannnot callstd::move()
on its returned value to construct anyunqiue_ptr
orshared_ptr
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see here
https://github.com/danpovey/k2/blob/75c4cd1b1fdd2a20009997c269b905b438575cdb/k2/csrc/determinize.h#L818
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see; shared_ptr is fine.