Skip to content
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

Correct conversions errors from u64 to size_t(u32 on msvc32) #104

Merged
merged 2 commits into from
Dec 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ VERSION
__pycache__/

# Mac OS
.DS_Store
.DS_Store

build/
4 changes: 2 additions & 2 deletions src/core/analysis/rnn_scorer_gbeam.cc
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,9 @@ Status RnnScorerGbeamFactory::make(StringPiece rnnModelPath,
state_->resolver.build(dic, state_->config, state_->rnnReader.words()));
auto& h = state_->rnnReader.header();
state_->embeddings = {state_->rnnReader.embeddings(), h.layerSize,
h.vocabSize};
static_cast<jumanpp::size_t>(h.vocabSize)};
state_->nceEmbeddings = {state_->rnnReader.nceEmbeddings(), h.layerSize,
h.vocabSize};
static_cast<jumanpp::size_t>(h.vocabSize)};
if (h.layerSize > 64 * 1024) {
return JPPS_NOT_IMPLEMENTED << "we don't support embed sizes > 64k";
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/analysis/score_processor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ util::ArraySlice<BeamCandidate> processBeamCandidates(
candidates = util::MutableArraySlice<BeamCandidate>{candidates, 0, sz};
}
std::sort(candidates.begin(), candidates.end(), comp);
auto size = std::min<u64>(maxBeam, candidates.size());
auto size = std::min<jumanpp::size_t>(maxBeam, candidates.size());
return util::ArraySlice<BeamCandidate>{candidates, 0, size};
}

Expand Down
24 changes: 14 additions & 10 deletions src/rnn/mikolov_rnn.cc
Original file line number Diff line number Diff line change
Expand Up @@ -177,29 +177,33 @@ Status MikolovModelReader::parse() {
auto maxBlock = std::max<u64>({hdr.layerSize * hdr.vocabSize, hdr.maxentSize,
hdr.layerSize * hdr.layerSize});
// 3 comes from rounding to next value + sizeof(float)
auto pageSize = 1ULL << (static_cast<u32>(std::log2(maxBlock)) + 3);
auto pageSize = static_cast<size_t>(1) << (static_cast<u32>(std::log2(maxBlock)) + 3);
data_->memmgr.initialize(pageSize);
data_->alloc = data_->memmgr.value().core();
auto& alloc = data_->alloc;

const auto embedding_matrix_size = static_cast<size_t>(hdr.layerSize) * static_cast<size_t>(hdr.vocabSize);
const auto transition_matrix_size = static_cast<size_t>(hdr.layerSize) * static_cast<size_t>(hdr.layerSize);

data_->embeddingData =
alloc->allocateBuf<float>(hdr.layerSize * hdr.vocabSize, 64);
alloc->allocateBuf<float>(embedding_matrix_size, 64);
data_->nceEmbeddingData =
alloc->allocateBuf<float>(hdr.layerSize * hdr.vocabSize, 64);
alloc->allocateBuf<float>(embedding_matrix_size, 64);
data_->matrixData =
alloc->allocateBuf<float>(hdr.layerSize * hdr.layerSize, 64);
data_->maxentWeightData = alloc->allocateBuf<float>(hdr.maxentSize, 64);
alloc->allocateBuf<float>(transition_matrix_size, 64);
data_->maxentWeightData = alloc->allocateBuf<float>(static_cast<size_t>(hdr.maxentSize), 64);

JPP_RIE_MSG(copyArray(contents, data_->embeddingData,
hdr.layerSize * hdr.vocabSize, &start),
embedding_matrix_size, &start),
"embeds");
JPP_RIE_MSG(copyArray(contents, data_->nceEmbeddingData,
hdr.layerSize * hdr.vocabSize, &start),
embedding_matrix_size, &start),
"nce embeds");
JPP_RIE_MSG(copyArray(contents, data_->matrixData,
hdr.layerSize * hdr.layerSize, &start),
transition_matrix_size, &start),
"matrix");
JPP_RIE_MSG(
copyArray(contents, data_->maxentWeightData, hdr.maxentSize, &start),
copyArray(contents, data_->maxentWeightData, static_cast<size_t>(hdr.maxentSize), &start),
"maxent weights");
if (start != contents.size()) {
return Status::InvalidState() << "did not read rnn model file fully";
Expand Down Expand Up @@ -245,4 +249,4 @@ StringPiece MikolovRnn::maxentWeightsAsStringpiece() const {

} // namespace mikolov
} // namespace rnn
} // namespace jumanpp
} // namespace jumanpp