Change casts to C++ style casts, and delete unnecessary casts.

This commit is contained in:
Tetsuo Kiso 2012-02-01 17:17:58 +09:00
parent 3c04b7e826
commit 142342f8be
7 changed files with 11 additions and 11 deletions

View File

@ -142,7 +142,7 @@ void BleuScorer::prepareStats(size_t sid, const string& text, ScoreStats& entry)
for (size_t i = 0; i < _reflengths[sid].size(); ++i) {
total += _reflengths[sid][i];
}
float mean = (float)total/_reflengths[sid].size();
float mean = static_cast<float>(total) /_reflengths[sid].size();
stats.push_back(mean);
} else if (_refLengthStrategy == BLEU_CLOSEST) {
int min_diff = INT_MAX;
@ -196,7 +196,7 @@ float BleuScorer::calculateScore(const vector<int>& comps) const
}
logbleu /= kLENGTH;
float brevity = 1.0 - (float)comps[kLENGTH*2]/comps[1];//reflength divided by test length
const float brevity = 1.0 - static_cast<float>(comps[kLENGTH*2]) / comps[1];//reflength divided by test length
if (brevity < 0.0) {
logbleu += brevity;
}

View File

@ -50,7 +50,7 @@ float CderScorer::calculateScore(const vector<int>& comps) const
throw runtime_error("Size of stat vector for CDER is not 2");
}
return 1 - (comps[0] / (float) comps[1]);
return 1 - (comps[0] / static_cast<float>(comps[1]));
}
vector<int> CderScorer::computeCD(const sent_t& cand, const sent_t& ref) const

View File

@ -255,8 +255,8 @@ void Data::createShards(size_t shard_count, float shard_size, const string& scor
vector<size_t> shard_contents;
if (shard_size == 0) {
//split into roughly equal size shards
size_t shard_start = floor(0.5 + shard_id * (float)data_size / shard_count);
size_t shard_end = floor(0.5 + (shard_id+1) * (float)data_size / shard_count);
const size_t shard_start = floor(0.5 + shard_id * static_cast<float>(data_size) / shard_count);
const size_t shard_end = floor(0.5 + (shard_id + 1) * static_cast<float>(data_size) / shard_count);
for (size_t i = shard_start; i < shard_end; ++i) {
shard_contents.push_back(i);
}

View File

@ -46,7 +46,7 @@ void SparseVector::set(const string& name, FeatureStatsType value) {
void SparseVector::write(ostream& out, const string& sep) const {
for (fvector_t::const_iterator i = fvector_.begin(); i != fvector_.end(); ++i) {
if (abs((float)(i->second)) < 0.00001) continue;
if (abs(i->second) < 0.00001) continue;
string name = id2name_[i->first];
out << name << sep << i->second << " ";
}

View File

@ -54,7 +54,7 @@ void Point::Randomize()
CHECK(m_max.size()==Point::dim);
for (unsigned int i=0; i<size(); i++) {
operator[](i) = m_min[i] +
(float)random()/(float)RAND_MAX * (float)(m_max[i]-m_min[i]);
static_cast<float>(random()) / static_cast<float>(RAND_MAX) * (m_max[i] - m_min[i]);
}
}

View File

@ -459,8 +459,8 @@ int main(int argc, char **argv)
}
}
mean /= (float)option.ntry;
var /= (float)option.ntry;
mean /= static_cast<float>(option.ntry);
var /= static_cast<float>(option.ntry);
var = sqrt(abs(var - mean * mean));
if (verboselevel() > 1) {
@ -481,7 +481,7 @@ int main(int argc, char **argv)
cerr << "bestP: " << finalP << endl;
// L1-Normalization of the best Point
if ((int)to_optimize.size() == option.pdim) {
if (static_cast<int>(to_optimize.size()) == option.pdim) {
finalP.NormalizeL1();
}

View File

@ -76,7 +76,7 @@ static float sentenceLevelBleuPlusOne(const vector<float>& stats) {
logbleu += log(stats[2*j]+1) - log(stats[2*j+1]+1);
}
logbleu /= bleu_order;
float brevity = 1.0 - (float)stats[(bleu_order*2)]/stats[1];
const float brevity = 1.0 - static_cast<float>(stats[(bleu_order*2)]) / stats[1];
if (brevity < 0.0) {
logbleu += brevity;
}