-
Notifications
You must be signed in to change notification settings - Fork 5.4k
fix bug 'vector iterator + offset out of range' in nnet-common #2594
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 bug 'vector iterator + offset out of range' in nnet-common #2594
Conversation
src/nnet3/nnet-common.cc
Outdated
| // check 'n2 > index_vector.size()' first, | ||
| // otherwise, 'end - n2' will be less than 'index_vector.begin()' and | ||
| // cause error "vector iterator + offset out of range" in STL vector. | ||
| if (n2 > index_vector.size() || iter >= end - n2) |
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.
make 'size' a variable (declare it next to 'ans') as it's inefficient to keep using size() in a loop.
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.
updated! Define 'len' as 'index_vector.size()'. Pls review again. Thanks!
b1ff84f to
1df9cc1
Compare
src/nnet3/nnet-common.cc
Outdated
| ans += iter->x * 89809; | ||
| // check 'n2 > index_vector.size()' first, | ||
| // otherwise, 'end - n2' will be less than 'index_vector.begin()' and | ||
| // cause error "vector iterator + offset out of range" in STL vector. |
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.
Please make sure this code is correctly indented (and make sure you use spaces not tabs).
Also, you can change the comment to the following:
// The following if-statement was introduced in order to fix an
// out-of-range iterator problem on Windows.
src/nnet3/nnet-common.cc
Outdated
| std::vector<Index>::const_iterator iter = index_vector.begin(), | ||
| end = index_vector.end(), med = end; | ||
| if (med > iter + n1) | ||
| if (n1 <= len) |
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.
.. also I believe this should be if n1 < len, not <=.
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.
updated again. Also checked indentation and spaces. With another question:
why when med == end == iter + n1, we would like to do for (; iter != med; ++iter) instead of skip this? This will make the hash better?
bf2f017 to
43eeb9a
Compare
43eeb9a to
68d847d
Compare
…ng/limit_arpa_unk_history.py [src] Correct usage message of acc-lda (kaldi-asr#2598) [scripts] RNNLM script fix: to accept successive spaces in configs (etc.) kaldi-asr#2595 (kaldi-asr#2597) [scripts] Slight cleanup in lmrescore_rnnlm_lat.sh (kaldi-asr#2554) [src] Fix Windows out-of-range iterator issue for nnet3 (kaldi-asr#2594) [src] Update Windows installation instructions (kaldi-asr#2607) [egs] Fix to LibriSpeech download script [affects 2nd run] (kaldi-asr#2611) [src] Change RNNLM test program to clean up temporary file (kaldi-asr#2610) added a script to scale arcs which output <unk> in HCLG.fst fix fix updating results and cleaning up scripts, and fixed a bug in utils/lang/limit_arpa_unk_history.py [scripts] Fix to script usage message (kaldi-asr#2601) [src] Correct usage message of acc-lda (kaldi-asr#2598) [scripts] RNNLM script fix: to accept successive spaces in configs (etc.) kaldi-asr#2595 (kaldi-asr#2597) [scripts] Slight cleanup in lmrescore_rnnlm_lat.sh (kaldi-asr#2554) [src] Fix Windows out-of-range iterator issue for nnet3 (kaldi-asr#2594) [src] Update Windows installation instructions (kaldi-asr#2607) [egs] Fix to LibriSpeech download script [affects 2nd run] (kaldi-asr#2611) [src] Change RNNLM test program to clean up temporary file (kaldi-asr#2610)
No description provided.