am 0028ed36: Use "float" instead of "double"

* commit '0028ed3627ff4f37a62a80f3b2c857e373cd5090':
  Use "float" instead of "double"
This commit is contained in:
satok 2012-05-16 05:04:46 -07:00 committed by Android Git Automerger
commit ac067f2db7
12 changed files with 49 additions and 48 deletions

View file

@ -18,6 +18,7 @@ package com.android.inputmethod.keyboard;
import android.graphics.Rect;
import android.text.TextUtils;
import android.util.FloatMath;
import com.android.inputmethod.keyboard.Keyboard.Params.TouchPositionCorrection;
import com.android.inputmethod.latin.JniUtils;
@ -147,7 +148,7 @@ public class ProximityInfo {
final float radius = touchPositionCorrection.mRadii[row];
sweetSpotCenterXs[i] = hitBoxCenterX + x * hitBoxWidth;
sweetSpotCenterYs[i] = hitBoxCenterY + y * hitBoxHeight;
sweetSpotRadii[i] = radius * (float) Math.sqrt(
sweetSpotRadii[i] = radius * FloatMath.sqrt(
hitBoxWidth * hitBoxWidth + hitBoxHeight * hitBoxHeight);
}
}

View file

@ -35,7 +35,7 @@ public class AutoCorrection {
public static CharSequence computeAutoCorrectionWord(
HashMap<String, Dictionary> dictionaries,
WordComposer wordComposer, ArrayList<SuggestedWordInfo> suggestions,
CharSequence consideredWord, double autoCorrectionThreshold,
CharSequence consideredWord, float autoCorrectionThreshold,
CharSequence whitelistedWord) {
if (hasAutoCorrectionForWhitelistedWord(whitelistedWord)) {
return whitelistedWord;
@ -100,14 +100,14 @@ public class AutoCorrection {
private static boolean hasAutoCorrectionForBinaryDictionary(WordComposer wordComposer,
ArrayList<SuggestedWordInfo> suggestions,
CharSequence consideredWord, double autoCorrectionThreshold) {
CharSequence consideredWord, float autoCorrectionThreshold) {
if (wordComposer.size() > 1 && suggestions.size() > 0) {
final SuggestedWordInfo autoCorrectionSuggestion = suggestions.get(0);
//final int autoCorrectionSuggestionScore = sortedScores[0];
final int autoCorrectionSuggestionScore = autoCorrectionSuggestion.mScore;
// TODO: when the normalized score of the first suggestion is nearly equals to
// the normalized score of the second suggestion, behave less aggressive.
final double normalizedScore = BinaryDictionary.calcNormalizedScore(
final float normalizedScore = BinaryDictionary.calcNormalizedScore(
consideredWord.toString(), autoCorrectionSuggestion.mWord.toString(),
autoCorrectionSuggestionScore);
if (DBG) {

View file

@ -92,7 +92,7 @@ public class BinaryDictionary extends Dictionary {
private native int getBigramsNative(long dict, int[] prevWord, int prevWordLength,
int[] inputCodes, int inputCodesLength, char[] outputChars, int[] scores,
int maxWordLength, int maxBigrams);
private static native double calcNormalizedScoreNative(
private static native float calcNormalizedScoreNative(
char[] before, int beforeLength, char[] after, int afterLength, int score);
private static native int editDistanceNative(
char[] before, int beforeLength, char[] after, int afterLength);
@ -189,7 +189,7 @@ public class BinaryDictionary extends Dictionary {
prevWordCodePointArray, mUseFullEditDistance, outputChars, scores);
}
public static double calcNormalizedScore(String before, String after, int score) {
public static float calcNormalizedScore(String before, String after, int score) {
return calcNormalizedScoreNative(before.toCharArray(), before.length(),
after.toCharArray(), after.length(), score);
}

View file

@ -77,7 +77,7 @@ public class SettingsValues {
public final float mFxVolume;
public final int mKeyPreviewPopupDismissDelay;
public final boolean mAutoCorrectEnabled;
public final double mAutoCorrectionThreshold;
public final float mAutoCorrectionThreshold;
private final boolean mVoiceKeyEnabled;
private final boolean mVoiceKeyOnMain;
@ -255,21 +255,21 @@ public class SettingsValues {
R.bool.config_default_next_word_prediction));
}
private static double getAutoCorrectionThreshold(final Resources resources,
private static float getAutoCorrectionThreshold(final Resources resources,
final String currentAutoCorrectionSetting) {
final String[] autoCorrectionThresholdValues = resources.getStringArray(
R.array.auto_correction_threshold_values);
// When autoCorrectionThreshold is greater than 1.0, it's like auto correction is off.
double autoCorrectionThreshold = Double.MAX_VALUE;
float autoCorrectionThreshold = Float.MAX_VALUE;
try {
final int arrayIndex = Integer.valueOf(currentAutoCorrectionSetting);
if (arrayIndex >= 0 && arrayIndex < autoCorrectionThresholdValues.length) {
autoCorrectionThreshold = Double.parseDouble(
autoCorrectionThreshold = Float.parseFloat(
autoCorrectionThresholdValues[arrayIndex]);
}
} catch (NumberFormatException e) {
// Whenever the threshold settings are correct, never come here.
autoCorrectionThreshold = Double.MAX_VALUE;
autoCorrectionThreshold = Float.MAX_VALUE;
Log.w(TAG, "Cannot load auto correction threshold setting."
+ " currentAutoCorrectionSetting: " + currentAutoCorrectionSetting
+ ", autoCorrectionThresholdValues: "

View file

@ -77,7 +77,7 @@ public class Suggest implements Dictionary.WordCallback {
private static final int PREF_MAX_BIGRAMS = 60;
private double mAutoCorrectionThreshold;
private float mAutoCorrectionThreshold;
private ArrayList<SuggestedWordInfo> mSuggestions = new ArrayList<SuggestedWordInfo>();
private ArrayList<SuggestedWordInfo> mBigramSuggestions = new ArrayList<SuggestedWordInfo>();
@ -185,7 +185,7 @@ public class Suggest implements Dictionary.WordCallback {
userHistoryDictionary);
}
public void setAutoCorrectionThreshold(double threshold) {
public void setAutoCorrectionThreshold(float threshold) {
mAutoCorrectionThreshold = threshold;
}
@ -416,7 +416,7 @@ public class Suggest implements Dictionary.WordCallback {
// than i because we added the typed word to mSuggestions without touching mScores.
for (int i = 0; i < suggestionsSize - 1; ++i) {
final SuggestedWordInfo cur = suggestions.get(i + 1);
final double normalizedScore = BinaryDictionary.calcNormalizedScore(
final float normalizedScore = BinaryDictionary.calcNormalizedScore(
typedWord, cur.toString(), cur.mScore);
final String scoreInfoString;
if (normalizedScore > 0) {

View file

@ -79,9 +79,9 @@ public class AndroidSpellCheckerService extends SpellCheckerService
private Dictionary mContactsDictionary;
// The threshold for a candidate to be offered as a suggestion.
private double mSuggestionThreshold;
private float mSuggestionThreshold;
// The threshold for a suggestion to be considered "recommended".
private double mRecommendedThreshold;
private float mRecommendedThreshold;
// Whether to use the contacts dictionary
private boolean mUseContactsDictionary;
private final Object mUseContactsLock = new Object();
@ -113,9 +113,9 @@ public class AndroidSpellCheckerService extends SpellCheckerService
@Override public void onCreate() {
super.onCreate();
mSuggestionThreshold =
Double.parseDouble(getString(R.string.spellchecker_suggestion_threshold_value));
Float.parseFloat(getString(R.string.spellchecker_suggestion_threshold_value));
mRecommendedThreshold =
Double.parseDouble(getString(R.string.spellchecker_recommended_threshold_value));
Float.parseFloat(getString(R.string.spellchecker_recommended_threshold_value));
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
prefs.registerOnSharedPreferenceChangeListener(this);
onSharedPreferenceChanged(prefs, PREF_USE_CONTACTS_KEY);
@ -207,8 +207,8 @@ public class AndroidSpellCheckerService extends SpellCheckerService
private final ArrayList<CharSequence> mSuggestions;
private final int[] mScores;
private final String mOriginalText;
private final double mSuggestionThreshold;
private final double mRecommendedThreshold;
private final float mSuggestionThreshold;
private final float mRecommendedThreshold;
private final int mMaxLength;
private int mLength = 0;
@ -217,8 +217,8 @@ public class AndroidSpellCheckerService extends SpellCheckerService
private String mBestSuggestion = null;
private int mBestScore = Integer.MIN_VALUE; // As small as possible
SuggestionsGatherer(final String originalText, final double suggestionThreshold,
final double recommendedThreshold, final int maxLength) {
SuggestionsGatherer(final String originalText, final float suggestionThreshold,
final float recommendedThreshold, final int maxLength) {
mOriginalText = originalText;
mSuggestionThreshold = suggestionThreshold;
mRecommendedThreshold = recommendedThreshold;
@ -261,7 +261,7 @@ public class AndroidSpellCheckerService extends SpellCheckerService
// Compute the normalized score and skip this word if it's normalized score does not
// make the threshold.
final String wordString = new String(word, wordOffset, wordLength);
final double normalizedScore =
final float normalizedScore =
BinaryDictionary.calcNormalizedScore(mOriginalText, wordString, score);
if (normalizedScore < mSuggestionThreshold) {
if (DBG) Log.i(TAG, wordString + " does not make the score threshold");
@ -295,7 +295,7 @@ public class AndroidSpellCheckerService extends SpellCheckerService
hasRecommendedSuggestions = false;
} else {
gatheredSuggestions = EMPTY_STRING_ARRAY;
final double normalizedScore = BinaryDictionary.calcNormalizedScore(
final float normalizedScore = BinaryDictionary.calcNormalizedScore(
mOriginalText, mBestSuggestion, mBestScore);
hasRecommendedSuggestions = (normalizedScore > mRecommendedThreshold);
}
@ -329,7 +329,7 @@ public class AndroidSpellCheckerService extends SpellCheckerService
final int bestScore = mScores[mLength - 1];
final CharSequence bestSuggestion = mSuggestions.get(0);
final double normalizedScore =
final float normalizedScore =
BinaryDictionary.calcNormalizedScore(
mOriginalText, bestSuggestion.toString(), bestScore);
hasRecommendedSuggestions = (normalizedScore > mRecommendedThreshold);

View file

@ -196,11 +196,11 @@ static jboolean latinime_BinaryDictionary_isValidBigram(JNIEnv *env, jobject obj
return result;
}
static jdouble latinime_BinaryDictionary_calcNormalizedScore(JNIEnv *env, jobject object,
static jfloat latinime_BinaryDictionary_calcNormalizedScore(JNIEnv *env, jobject object,
jcharArray before, jint beforeLength, jcharArray after, jint afterLength, jint score) {
jchar *beforeChars = env->GetCharArrayElements(before, 0);
jchar *afterChars = env->GetCharArrayElements(after, 0);
jdouble result = Correction::RankingAlgorithm::calcNormalizedScore((unsigned short*)beforeChars,
jfloat result = Correction::RankingAlgorithm::calcNormalizedScore((unsigned short*)beforeChars,
beforeLength, (unsigned short*)afterChars, afterLength, score);
env->ReleaseCharArrayElements(after, afterChars, JNI_ABORT);
env->ReleaseCharArrayElements(before, beforeChars, JNI_ABORT);
@ -255,7 +255,7 @@ static JNINativeMethod sMethods[] = {
{"isValidWordNative", "(J[II)Z", (void*)latinime_BinaryDictionary_isValidWord},
{"isValidBigramNative", "(J[I[I)Z", (void*)latinime_BinaryDictionary_isValidBigram},
{"getBigramsNative", "(J[II[II[C[III)I", (void*)latinime_BinaryDictionary_getBigrams},
{"calcNormalizedScoreNative", "([CI[CII)D",
{"calcNormalizedScoreNative", "([CI[CII)F",
(void*)latinime_BinaryDictionary_calcNormalizedScore},
{"editDistanceNative", "([CI[CI)I", (void*)latinime_BinaryDictionary_editDistance}
};

View file

@ -1113,7 +1113,7 @@ int Correction::RankingAlgorithm::editDistance(const unsigned short* before,
// So, we can normalize original score by dividing pow(2, min(b.l(),a.l())) * 255 * 2.
/* static */
double Correction::RankingAlgorithm::calcNormalizedScore(const unsigned short* before,
float Correction::RankingAlgorithm::calcNormalizedScore(const unsigned short* before,
const int beforeLength, const unsigned short* after, const int afterLength,
const int score) {
if (0 == beforeLength || 0 == afterLength) {
@ -1131,14 +1131,14 @@ double Correction::RankingAlgorithm::calcNormalizedScore(const unsigned short* b
return 0;
}
const double maxScore = score >= S_INT_MAX ? S_INT_MAX : MAX_INITIAL_SCORE
* pow((double)TYPED_LETTER_MULTIPLIER,
(double)min(beforeLength, afterLength - spaceCount)) * FULL_WORD_MULTIPLIER;
const float maxScore = score >= S_INT_MAX ? S_INT_MAX : MAX_INITIAL_SCORE
* pow((float)TYPED_LETTER_MULTIPLIER,
(float)min(beforeLength, afterLength - spaceCount)) * FULL_WORD_MULTIPLIER;
// add a weight based on edit distance.
// distance <= max(afterLength, beforeLength) == afterLength,
// so, 0 <= distance / afterLength <= 1
const double weight = 1.0 - (double) distance / afterLength;
const float weight = 1.0 - (float) distance / afterLength;
return (score / maxScore) * weight;
}

View file

@ -162,7 +162,7 @@ class Correction {
static int calcFreqForSplitMultipleWords(const int *freqArray, const int *wordLengthArray,
const int wordCount, const Correction* correction, const bool isSpaceProximity,
const unsigned short *word);
static double calcNormalizedScore(const unsigned short* before, const int beforeLength,
static float calcNormalizedScore(const unsigned short* before, const int beforeLength,
const unsigned short* after, const int afterLength, const int score);
static int editDistance(const unsigned short* before,
const int beforeLength, const unsigned short* after, const int afterLength);

View file

@ -46,8 +46,8 @@ static inline void dumpWord(const unsigned short* word, const int length) {
#include <time.h>
#define PROF_BUF_SIZE 100
static double profile_buf[PROF_BUF_SIZE];
static double profile_old[PROF_BUF_SIZE];
static float profile_buf[PROF_BUF_SIZE];
static float profile_old[PROF_BUF_SIZE];
static unsigned int profile_counter[PROF_BUF_SIZE];
#define PROF_RESET prof_reset()
@ -74,8 +74,8 @@ static inline void prof_out(void) {
AKLOGI("Error: You must call PROF_OPEN before PROF_CLOSE.");
}
AKLOGI("Total time is %6.3f ms.",
profile_buf[PROF_BUF_SIZE - 1] * 1000 / (double)CLOCKS_PER_SEC);
double all = 0;
profile_buf[PROF_BUF_SIZE - 1] * 1000 / (float)CLOCKS_PER_SEC);
float all = 0;
for (int i = 0; i < PROF_BUF_SIZE - 1; ++i) {
all += profile_buf[i];
}
@ -84,7 +84,7 @@ static inline void prof_out(void) {
if (profile_buf[i] != 0) {
AKLOGI("(%d): Used %4.2f%%, %8.4f ms. Called %d times.",
i, (profile_buf[i] * 100 / all),
profile_buf[i] * 1000 / (double)CLOCKS_PER_SEC, profile_counter[i]);
profile_buf[i] * 1000 / (float)CLOCKS_PER_SEC, profile_counter[i]);
}
}
}

View file

@ -202,7 +202,7 @@ int UnigramDictionary::getSuggestions(ProximityInfo *proximityInfo,
PROF_START(20);
if (DEBUG_DICT) {
double ns = queuePool->getMasterQueue()->getHighestNormalizedScore(
float ns = queuePool->getMasterQueue()->getHighestNormalizedScore(
proximityInfo->getPrimaryInputWord(), codesSize, 0, 0, 0);
ns += 0;
AKLOGI("Max normalized score = %f", ns);
@ -212,7 +212,7 @@ int UnigramDictionary::getSuggestions(ProximityInfo *proximityInfo,
proximityInfo->getPrimaryInputWord(), codesSize, frequencies, outWords);
if (DEBUG_DICT) {
double ns = queuePool->getMasterQueue()->getHighestNormalizedScore(
float ns = queuePool->getMasterQueue()->getHighestNormalizedScore(
proximityInfo->getPrimaryInputWord(), codesSize, 0, 0, 0);
ns += 0;
AKLOGI("Returning %d words", suggestedWordsCount);
@ -255,7 +255,7 @@ void UnigramDictionary::getWordSuggestions(ProximityInfo *proximityInfo,
bool hasAutoCorrectionCandidate = false;
WordsPriorityQueue* masterQueue = queuePool->getMasterQueue();
if (masterQueue->size() > 0) {
double nsForMaster = masterQueue->getHighestNormalizedScore(
float nsForMaster = masterQueue->getHighestNormalizedScore(
proximityInfo->getPrimaryInputWord(), inputLength, 0, 0, 0);
hasAutoCorrectionCandidate = (nsForMaster > START_TWO_WORDS_CORRECTION_THRESHOLD);
}
@ -284,7 +284,7 @@ void UnigramDictionary::getWordSuggestions(ProximityInfo *proximityInfo,
const int score = sw->mScore;
const unsigned short* word = sw->mWord;
const int wordLength = sw->mWordLength;
double ns = Correction::RankingAlgorithm::calcNormalizedScore(
float ns = Correction::RankingAlgorithm::calcNormalizedScore(
proximityInfo->getPrimaryInputWord(), i, word, wordLength, score);
ns += 0;
AKLOGI("--- TOP SUB WORDS for %d --- %d %f [%d]", i, score, ns,
@ -452,7 +452,7 @@ bool UnigramDictionary::getSubStringSuggestion(
return false;
}
int score = 0;
const double ns = queue->getHighestNormalizedScore(
const float ns = queue->getHighestNormalizedScore(
proximityInfo->getPrimaryInputWord(), inputWordLength,
&tempOutputWord, &score, &nextWordLength);
if (DEBUG_DICT) {

View file

@ -112,13 +112,13 @@ class WordsPriorityQueue {
if (size >= 2) {
SuggestedWord* nsMaxSw = 0;
unsigned int maxIndex = 0;
double maxNs = 0;
float maxNs = 0;
for (unsigned int i = 0; i < size; ++i) {
SuggestedWord* tempSw = swBuffer[i];
if (!tempSw) {
continue;
}
const double tempNs = getNormalizedScore(tempSw, before, beforeLength, 0, 0, 0);
const float tempNs = getNormalizedScore(tempSw, before, beforeLength, 0, 0, 0);
if (tempNs >= maxNs) {
maxNs = tempNs;
maxIndex = i;
@ -172,7 +172,7 @@ class WordsPriorityQueue {
DUMP_WORD(mHighestSuggestedWord->mWord, mHighestSuggestedWord->mWordLength);
}
double getHighestNormalizedScore(const unsigned short* before, const int beforeLength,
float getHighestNormalizedScore(const unsigned short* before, const int beforeLength,
unsigned short** outWord, int *outScore, int *outLength) {
if (!mHighestSuggestedWord) {
return 0.0;
@ -199,7 +199,7 @@ class WordsPriorityQueue {
return 0;
}
static double getNormalizedScore(SuggestedWord* sw, const unsigned short* before,
static float getNormalizedScore(SuggestedWord* sw, const unsigned short* before,
const int beforeLength, unsigned short** outWord, int *outScore, int *outLength) {
const int score = sw->mScore;
unsigned short* word = sw->mWord;