http://git-wip-us.apache.org/repos/asf/incubator-hivemall/blob/c4036695/core/src/main/java/hivemall/ftvec/pairing/FeaturePairsUDTF.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/hivemall/ftvec/pairing/FeaturePairsUDTF.java b/core/src/main/java/hivemall/ftvec/pairing/FeaturePairsUDTF.java index 3ec6ad7..3f959e5 100644 --- a/core/src/main/java/hivemall/ftvec/pairing/FeaturePairsUDTF.java +++ b/core/src/main/java/hivemall/ftvec/pairing/FeaturePairsUDTF.java @@ -101,8 +101,8 @@ public final class FeaturePairsUDTF extends UDTFWithOptions { this._numFields = Primitives.parseInt(cl.getOptionValue("num_fields"), Feature.DEFAULT_NUM_FIELDS); if (_numFields <= 1) { - throw new UDFArgumentException("-num_fields MUST be greater than 1: " - + _numFields); + throw new UDFArgumentException( + "-num_fields MUST be greater than 1: " + _numFields); } } else { throw new UDFArgumentException("Unsupported option: " + cl.getArgList().get(0)); @@ -282,8 +282,8 @@ public final class FeaturePairsUDTF extends UDTFWithOptions { return; } - this._features = Feature.parseFFMFeatures(arg, fvOI, _features, _numFeatures, - _numFields); + this._features = + Feature.parseFFMFeatures(arg, fvOI, _features, _numFeatures, _numFields); // W0 f0.set(0);
http://git-wip-us.apache.org/repos/asf/incubator-hivemall/blob/c4036695/core/src/main/java/hivemall/ftvec/ranking/BprSamplingUDTF.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/hivemall/ftvec/ranking/BprSamplingUDTF.java b/core/src/main/java/hivemall/ftvec/ranking/BprSamplingUDTF.java index 3967c82..821c734 100644 --- a/core/src/main/java/hivemall/ftvec/ranking/BprSamplingUDTF.java +++ b/core/src/main/java/hivemall/ftvec/ranking/BprSamplingUDTF.java @@ -210,7 +210,8 @@ public final class BprSamplingUDTF extends UDTFWithOptions { } } - private void forward(final int user, final int posItem, final int negItem) throws HiveException { + private void forward(final int user, final int posItem, final int negItem) + throws HiveException { assert (user >= 0) : user; assert (posItem >= 0) : posItem; assert (negItem >= 0) : negItem; @@ -268,9 +269,8 @@ public final class BprSamplingUDTF extends UDTFWithOptions { * Caution: This is not a perfect 'without sampling' but it does 'without sampling' for positive * feedbacks. */ - private void uniformUserSamplingWithoutReplacement( - @Nonnull final PositiveOnlyFeedback feedback, final int numSamples) - throws HiveException { + private void uniformUserSamplingWithoutReplacement(@Nonnull final PositiveOnlyFeedback feedback, + final int numSamples) throws HiveException { int numUsers = feedback.getNumUsers(); if (numUsers == 0) { return; @@ -288,8 +288,8 @@ public final class BprSamplingUDTF extends UDTFWithOptions { int nthUser = rand.nextInt(numUsers); int user = BitUtils.indexOfSetBit(userBits, nthUser); if (user == -1) { - throw new HiveException("Cannot find " + nthUser + "-th user among " + numUsers - + " users"); + throw new HiveException( + "Cannot find " + nthUser + "-th user among " + numUsers + " users"); } IntArrayList posItems = feedback.getItems(user, true); http://git-wip-us.apache.org/repos/asf/incubator-hivemall/blob/c4036695/core/src/main/java/hivemall/ftvec/ranking/ItemPairsSamplingUDTF.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/hivemall/ftvec/ranking/ItemPairsSamplingUDTF.java b/core/src/main/java/hivemall/ftvec/ranking/ItemPairsSamplingUDTF.java index 64ef4ba..87e5858 100644 --- a/core/src/main/java/hivemall/ftvec/ranking/ItemPairsSamplingUDTF.java +++ b/core/src/main/java/hivemall/ftvec/ranking/ItemPairsSamplingUDTF.java @@ -110,7 +110,8 @@ public final class ItemPairsSamplingUDTF extends UDTFWithOptions { + " takes at least two arguments"); } this.listOI = HiveUtils.asListOI(argOIs[0]); - this.listElemOI = HiveUtils.asPrimitiveObjectInspector(listOI.getListElementObjectInspector()); + this.listElemOI = + HiveUtils.asPrimitiveObjectInspector(listOI.getListElementObjectInspector()); processOptions(argOIs); this.maxItemId = HiveUtils.getAsConstInt(argOIs[1]); @@ -181,9 +182,9 @@ public final class ItemPairsSamplingUDTF extends UDTFWithOptions { int i = BitUtils.indexOfSetBit(bitset, nth); if (i == -1) { - throw new UDFArgumentException("Cannot find a value for " + nth - + "-th element in bitset " + bitset.toString() + " where numPosItems = " - + numPosItems); + throw new UDFArgumentException( + "Cannot find a value for " + nth + "-th element in bitset " + bitset.toString() + + " where numPosItems = " + numPosItems); } nth = _rand.nextInt(numNegItems); @@ -208,9 +209,9 @@ public final class ItemPairsSamplingUDTF extends UDTFWithOptions { int nth = _rand.nextInt(numPosItems); int i = BitUtils.indexOfSetBit(bitsetForPosSampling, nth); if (i == -1) { - throw new UDFArgumentException("Cannot find a value for " + nth - + "-th element in bitset " + bitset.toString() + " where numPosItems = " - + numPosItems); + throw new UDFArgumentException( + "Cannot find a value for " + nth + "-th element in bitset " + bitset.toString() + + " where numPosItems = " + numPosItems); } bitsetForPosSampling.set(i, false); --numPosItems; http://git-wip-us.apache.org/repos/asf/incubator-hivemall/blob/c4036695/core/src/main/java/hivemall/ftvec/ranking/PopulateNotInUDTF.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/hivemall/ftvec/ranking/PopulateNotInUDTF.java b/core/src/main/java/hivemall/ftvec/ranking/PopulateNotInUDTF.java index 29529e1..1b25af9 100644 --- a/core/src/main/java/hivemall/ftvec/ranking/PopulateNotInUDTF.java +++ b/core/src/main/java/hivemall/ftvec/ranking/PopulateNotInUDTF.java @@ -39,8 +39,7 @@ import org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector; import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory; import org.apache.hadoop.io.IntWritable; -@Description( - name = "populate_not_in", +@Description(name = "populate_not_in", value = "_FUNC_(list items, const int max_item_id [, const string options])" + "- Returns a relation consists of <int item> that item does not exist in the given items") public final class PopulateNotInUDTF extends UDTFWithOptions { @@ -89,7 +88,8 @@ public final class PopulateNotInUDTF extends UDTFWithOptions { + " takes at least two arguments"); } this.listOI = HiveUtils.asListOI(argOIs[0]); - this.listElemOI = HiveUtils.asPrimitiveObjectInspector(listOI.getListElementObjectInspector()); + this.listElemOI = + HiveUtils.asPrimitiveObjectInspector(listOI.getListElementObjectInspector()); processOptions(argOIs); this.maxItemId = HiveUtils.getAsConstInt(argOIs[1]); http://git-wip-us.apache.org/repos/asf/incubator-hivemall/blob/c4036695/core/src/main/java/hivemall/ftvec/scaling/RescaleUDF.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/hivemall/ftvec/scaling/RescaleUDF.java b/core/src/main/java/hivemall/ftvec/scaling/RescaleUDF.java index a73150c..af14791 100644 --- a/core/src/main/java/hivemall/ftvec/scaling/RescaleUDF.java +++ b/core/src/main/java/hivemall/ftvec/scaling/RescaleUDF.java @@ -81,15 +81,16 @@ public final class RescaleUDF extends UDF { final String[] fv = s.split(":"); if (fv.length != 2) { - throw new HiveException(String.format("Invalid feature value " + "representation: %s", - s)); + throw new HiveException( + String.format("Invalid feature value " + "representation: %s", s)); } float v; try { v = Float.parseFloat(fv[1]); } catch (NumberFormatException e) { - throw new HiveException(String.format("Invalid feature value " - + "representation: %s, %s can't parse to float.", s, fv[1])); + throw new HiveException(String.format( + "Invalid feature value " + "representation: %s, %s can't parse to float.", s, + fv[1])); } float scaled_v = min_max_normalization(v, min.floatValue(), max.floatValue()); @@ -100,8 +101,8 @@ public final class RescaleUDF extends UDF { private static float min_max_normalization(final float value, final float min, final float max) throws HiveException { if (min > max) { - throw new HiveException("min value `" + min + "` SHOULD be less than max value `" + max - + '`'); + throw new HiveException( + "min value `" + min + "` SHOULD be less than max value `" + max + '`'); } if (min == max) { return 0.5f; http://git-wip-us.apache.org/repos/asf/incubator-hivemall/blob/c4036695/core/src/main/java/hivemall/ftvec/selection/ChiSquareUDF.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/hivemall/ftvec/selection/ChiSquareUDF.java b/core/src/main/java/hivemall/ftvec/selection/ChiSquareUDF.java index ca622bc..a18b803 100644 --- a/core/src/main/java/hivemall/ftvec/selection/ChiSquareUDF.java +++ b/core/src/main/java/hivemall/ftvec/selection/ChiSquareUDF.java @@ -83,15 +83,19 @@ public final class ChiSquareUDF extends GenericUDF { this.observedOI = HiveUtils.asListOI(OIs[1]); this.observedRowOI = HiveUtils.asListOI(observedOI.getListElementObjectInspector()); - this.observedElOI = HiveUtils.asDoubleCompatibleOI(observedRowOI.getListElementObjectInspector()); + this.observedElOI = + HiveUtils.asDoubleCompatibleOI(observedRowOI.getListElementObjectInspector()); this.expectedOI = HiveUtils.asListOI(OIs[0]); this.expectedRowOI = HiveUtils.asListOI(expectedOI.getListElementObjectInspector()); - this.expectedElOI = HiveUtils.asDoubleCompatibleOI(expectedRowOI.getListElementObjectInspector()); + this.expectedElOI = + HiveUtils.asDoubleCompatibleOI(expectedRowOI.getListElementObjectInspector()); this.result = new List[2]; List<ObjectInspector> fieldOIs = new ArrayList<ObjectInspector>(); - fieldOIs.add(ObjectInspectorFactory.getStandardListObjectInspector(PrimitiveObjectInspectorFactory.writableDoubleObjectInspector)); - fieldOIs.add(ObjectInspectorFactory.getStandardListObjectInspector(PrimitiveObjectInspectorFactory.writableDoubleObjectInspector)); + fieldOIs.add(ObjectInspectorFactory.getStandardListObjectInspector( + PrimitiveObjectInspectorFactory.writableDoubleObjectInspector)); + fieldOIs.add(ObjectInspectorFactory.getStandardListObjectInspector( + PrimitiveObjectInspectorFactory.writableDoubleObjectInspector)); return ObjectInspectorFactory.getStandardStructObjectInspector( Arrays.asList("chi2", "pvalue"), fieldOIs); @@ -118,10 +122,10 @@ public final class ChiSquareUDF extends GenericUDF { Preconditions.checkNotNull(expectedObjRow, UDFArgumentException.class); if (observedRow == null) { - observedRow = HiveUtils.asDoubleArray(observedObjRow, observedRowOI, observedElOI, - false); - expectedRow = HiveUtils.asDoubleArray(expectedObjRow, expectedRowOI, expectedElOI, - false); + observedRow = + HiveUtils.asDoubleArray(observedObjRow, observedRowOI, observedElOI, false); + expectedRow = + HiveUtils.asDoubleArray(expectedObjRow, expectedRowOI, expectedElOI, false); nFeatures = observedRow.length; observed = new double[nFeatures][nClasses]; expected = new double[nFeatures][nClasses]; http://git-wip-us.apache.org/repos/asf/incubator-hivemall/blob/c4036695/core/src/main/java/hivemall/ftvec/selection/SignalNoiseRatioUDAF.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/hivemall/ftvec/selection/SignalNoiseRatioUDAF.java b/core/src/main/java/hivemall/ftvec/selection/SignalNoiseRatioUDAF.java index da0de59..171f8e6 100644 --- a/core/src/main/java/hivemall/ftvec/selection/SignalNoiseRatioUDAF.java +++ b/core/src/main/java/hivemall/ftvec/selection/SignalNoiseRatioUDAF.java @@ -67,11 +67,10 @@ public class SignalNoiseRatioUDAF extends AbstractGenericUDAFResolver { "Only array<number> type argument is acceptable but " + OIs[0].getTypeName() + " was passed as `features`"); } - if (!HiveUtils.isListOI(OIs[1]) - || !HiveUtils.isIntegerOI(((ListObjectInspector) OIs[1]).getListElementObjectInspector())) { - throw new UDFArgumentTypeException(1, - "Only array<int> type argument is acceptable but " + OIs[1].getTypeName() - + " was passed as `labels`"); + if (!HiveUtils.isListOI(OIs[1]) || !HiveUtils.isIntegerOI( + ((ListObjectInspector) OIs[1]).getListElementObjectInspector())) { + throw new UDFArgumentTypeException(1, "Only array<int> type argument is acceptable but " + + OIs[1].getTypeName() + " was passed as `labels`"); } return new SignalNoiseRatioUDAFEvaluator(); @@ -104,9 +103,10 @@ public class SignalNoiseRatioUDAF extends AbstractGenericUDAFResolver { @Override public int estimate() { - return counts == null ? 0 : SizeOf.LONG * counts.length + SizeOf.DOUBLE - * means.length * means[0].length + SizeOf.DOUBLE * variances.length - * variances[0].length; + return counts == null ? 0 + : SizeOf.LONG * counts.length + + SizeOf.DOUBLE * means.length * means[0].length + + SizeOf.DOUBLE * variances.length * variances[0].length; } public void init(int nClasses, int nFeatures) { @@ -135,7 +135,8 @@ public class SignalNoiseRatioUDAF extends AbstractGenericUDAFResolver { // initialize input if (mode == Mode.PARTIAL1 || mode == Mode.COMPLETE) {// from original data this.featuresOI = HiveUtils.asListOI(OIs[0]); - this.featureOI = HiveUtils.asDoubleCompatibleOI(featuresOI.getListElementObjectInspector()); + this.featureOI = + HiveUtils.asDoubleCompatibleOI(featuresOI.getListElementObjectInspector()); this.labelsOI = HiveUtils.asListOI(OIs[1]); this.labelOI = HiveUtils.asIntegerOI(labelsOI.getListElementObjectInspector()); } else {// from partial aggregation @@ -149,20 +150,28 @@ public class SignalNoiseRatioUDAF extends AbstractGenericUDAFResolver { this.meanElemOI = HiveUtils.asDoubleOI(meanListOI.getListElementObjectInspector()); this.variancesField = structOI.getStructFieldRef("variances"); this.variancesOI = HiveUtils.asListOI(variancesField.getFieldObjectInspector()); - this.varianceListOI = HiveUtils.asListOI(variancesOI.getListElementObjectInspector()); - this.varianceElemOI = HiveUtils.asDoubleOI(varianceListOI.getListElementObjectInspector()); + this.varianceListOI = + HiveUtils.asListOI(variancesOI.getListElementObjectInspector()); + this.varianceElemOI = + HiveUtils.asDoubleOI(varianceListOI.getListElementObjectInspector()); } // initialize output if (mode == Mode.PARTIAL1 || mode == Mode.PARTIAL2) {// terminatePartial List<ObjectInspector> fieldOIs = new ArrayList<ObjectInspector>(); - fieldOIs.add(ObjectInspectorFactory.getStandardListObjectInspector(PrimitiveObjectInspectorFactory.writableLongObjectInspector)); - fieldOIs.add(ObjectInspectorFactory.getStandardListObjectInspector(ObjectInspectorFactory.getStandardListObjectInspector(PrimitiveObjectInspectorFactory.writableDoubleObjectInspector))); - fieldOIs.add(ObjectInspectorFactory.getStandardListObjectInspector(ObjectInspectorFactory.getStandardListObjectInspector(PrimitiveObjectInspectorFactory.writableDoubleObjectInspector))); + fieldOIs.add(ObjectInspectorFactory.getStandardListObjectInspector( + PrimitiveObjectInspectorFactory.writableLongObjectInspector)); + fieldOIs.add(ObjectInspectorFactory.getStandardListObjectInspector( + ObjectInspectorFactory.getStandardListObjectInspector( + PrimitiveObjectInspectorFactory.writableDoubleObjectInspector))); + fieldOIs.add(ObjectInspectorFactory.getStandardListObjectInspector( + ObjectInspectorFactory.getStandardListObjectInspector( + PrimitiveObjectInspectorFactory.writableDoubleObjectInspector))); return ObjectInspectorFactory.getStandardStructObjectInspector( Arrays.asList("counts", "means", "variances"), fieldOIs); } else {// terminate - return ObjectInspectorFactory.getStandardListObjectInspector(PrimitiveObjectInspectorFactory.writableDoubleObjectInspector); + return ObjectInspectorFactory.getStandardListObjectInspector( + PrimitiveObjectInspectorFactory.writableDoubleObjectInspector); } } @@ -214,13 +223,13 @@ public class SignalNoiseRatioUDAF extends AbstractGenericUDAFResolver { final long n = myAgg.counts[clazz]; myAgg.counts[clazz]++; for (int i = 0; i < nFeatures; i++) { - final double x = PrimitiveObjectInspectorUtils.getDouble(features.get(i), featureOI); + final double x = + PrimitiveObjectInspectorUtils.getDouble(features.get(i), featureOI); final double meanN = myAgg.means[clazz][i]; final double varianceN = myAgg.variances[clazz][i]; myAgg.means[clazz][i] = (n * meanN + x) / (n + 1.d); - myAgg.variances[clazz][i] = (n * varianceN + (x - meanN) - * (x - myAgg.means[clazz][i])) - / (n + 1.d); + myAgg.variances[clazz][i] = + (n * varianceN + (x - meanN) * (x - myAgg.means[clazz][i])) / (n + 1.d); } } @@ -260,10 +269,11 @@ public class SignalNoiseRatioUDAF extends AbstractGenericUDAFResolver { final SignalNoiseRatioAggregationBuffer myAgg = (SignalNoiseRatioAggregationBuffer) agg; - final List<?> counts = countsOI.getList(structOI.getStructFieldData(other, countsField)); + final List<?> counts = + countsOI.getList(structOI.getStructFieldData(other, countsField)); final List<?> means = meansOI.getList(structOI.getStructFieldData(other, meansField)); - final List<?> variances = variancesOI.getList(structOI.getStructFieldData(other, - variancesField)); + final List<?> variances = + variancesOI.getList(structOI.getStructFieldData(other, variancesField)); final int nClasses = counts.size(); final int nFeatures = meanListOI.getListLength(means.get(0)); @@ -286,8 +296,8 @@ public class SignalNoiseRatioUDAF extends AbstractGenericUDAFResolver { myAgg.counts[i] += cnt; for (int j = 0; j < nFeatures; j++) { final double meanN = myAgg.means[i][j]; - final double meanM = PrimitiveObjectInspectorUtils.getDouble(mean.get(j), - meanElemOI); + final double meanM = + PrimitiveObjectInspectorUtils.getDouble(mean.get(j), meanElemOI); final double varianceN = myAgg.variances[i][j]; final double varianceM = PrimitiveObjectInspectorUtils.getDouble( variance.get(j), varianceElemOI); @@ -299,9 +309,8 @@ public class SignalNoiseRatioUDAF extends AbstractGenericUDAFResolver { // merge by Chan's method // http://i.stanford.edu/pub/cstr/reports/cs/tr/79/773/CS-TR-79-773.pdf myAgg.means[i][j] = (n * meanN + cnt * meanM) / (double) (n + cnt); - myAgg.variances[i][j] = (varianceN * (n - 1) + varianceM * (cnt - 1) + Math.pow( - meanN - meanM, 2) * n * cnt / (n + cnt)) - / (n + cnt - 1); + myAgg.variances[i][j] = (varianceN * (n - 1) + varianceM * (cnt - 1) + + Math.pow(meanN - meanM, 2) * n * cnt / (n + cnt)) / (n + cnt - 1); } } } @@ -348,13 +357,14 @@ public class SignalNoiseRatioUDAF extends AbstractGenericUDAFResolver { } for (int k = 0; k < j; k++) { // avoid comparing between classes having only single entry - if (myAgg.counts[k] == 0 || (myAgg.counts[j] == 1 && myAgg.counts[k] == 1)) { + if (myAgg.counts[k] == 0 + || (myAgg.counts[j] == 1 && myAgg.counts[k] == 1)) { continue; } // SUM(snr) GROUP BY feature - final double snr = Math.abs(myAgg.means[j][i] - myAgg.means[k][i]) - / (sds[j] + sds[k]); + final double snr = + Math.abs(myAgg.means[j][i] - myAgg.means[k][i]) / (sds[j] + sds[k]); // if `NaN`(when diff between means and both sds are zero, IOW, all related values are equal), // regard feature `i` as meaningless between class `j` and `k`. So, skip the entry. if (!Double.isNaN(snr)) { http://git-wip-us.apache.org/repos/asf/incubator-hivemall/blob/c4036695/core/src/main/java/hivemall/ftvec/trans/AddFieldIndicesUDF.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/hivemall/ftvec/trans/AddFieldIndicesUDF.java b/core/src/main/java/hivemall/ftvec/trans/AddFieldIndicesUDF.java index 3713cb3..b8d0403 100644 --- a/core/src/main/java/hivemall/ftvec/trans/AddFieldIndicesUDF.java +++ b/core/src/main/java/hivemall/ftvec/trans/AddFieldIndicesUDF.java @@ -56,7 +56,8 @@ public final class AddFieldIndicesUDF extends GenericUDF { throw new UDFArgumentException("Expected array<string> but got " + argOIs[0]); } - return ObjectInspectorFactory.getStandardListObjectInspector(PrimitiveObjectInspectorFactory.javaStringObjectInspector); + return ObjectInspectorFactory.getStandardListObjectInspector( + PrimitiveObjectInspectorFactory.javaStringObjectInspector); } @Override http://git-wip-us.apache.org/repos/asf/incubator-hivemall/blob/c4036695/core/src/main/java/hivemall/ftvec/trans/BinarizeLabelUDTF.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/hivemall/ftvec/trans/BinarizeLabelUDTF.java b/core/src/main/java/hivemall/ftvec/trans/BinarizeLabelUDTF.java index c10095d..9b194e7 100644 --- a/core/src/main/java/hivemall/ftvec/trans/BinarizeLabelUDTF.java +++ b/core/src/main/java/hivemall/ftvec/trans/BinarizeLabelUDTF.java @@ -34,9 +34,10 @@ import org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector; import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory; import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorUtils; -@Description(name = "binarize_label", value = "_FUNC_(int/long positive, int/long negative, ...) " - + "- Returns positive/negative records that are represented " - + "as (..., int label) where label is 0 or 1") +@Description(name = "binarize_label", + value = "_FUNC_(int/long positive, int/long negative, ...) " + + "- Returns positive/negative records that are represented " + + "as (..., int label) where label is 0 or 1") @UDFType(deterministic = true, stateful = false) public final class BinarizeLabelUDTF extends GenericUDTF { http://git-wip-us.apache.org/repos/asf/incubator-hivemall/blob/c4036695/core/src/main/java/hivemall/ftvec/trans/CategoricalFeaturesUDF.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/hivemall/ftvec/trans/CategoricalFeaturesUDF.java b/core/src/main/java/hivemall/ftvec/trans/CategoricalFeaturesUDF.java index cb1ab18..2f0b79b 100644 --- a/core/src/main/java/hivemall/ftvec/trans/CategoricalFeaturesUDF.java +++ b/core/src/main/java/hivemall/ftvec/trans/CategoricalFeaturesUDF.java @@ -40,8 +40,7 @@ import org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector; import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory; import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorUtils; -@Description( - name = "categorical_features", +@Description(name = "categorical_features", value = "_FUNC_(array<string> featureNames, feature1, feature2, .. [, const string options])" + " - Returns a feature vector array<string>") @UDFType(deterministic = true, stateful = false) @@ -82,8 +81,8 @@ public final class CategoricalFeaturesUDF extends UDFWithOptions { throws UDFArgumentException { final int numArgOIs = argOIs.length; if (numArgOIs < 2) { - throw new UDFArgumentException("argOIs.length must be greater that or equals to 2: " - + numArgOIs); + throw new UDFArgumentException( + "argOIs.length must be greater that or equals to 2: " + numArgOIs); } this._featureNames = HiveUtils.getConstStringArray(argOIs[0]); @@ -92,16 +91,16 @@ public final class CategoricalFeaturesUDF extends UDFWithOptions { } int numFeatureNames = _featureNames.length; if (numFeatureNames < 1) { - throw new UDFArgumentException("#featureNames must be greater than or equals to 1: " - + numFeatureNames); + throw new UDFArgumentException( + "#featureNames must be greater than or equals to 1: " + numFeatureNames); } for (String featureName : _featureNames) { if (featureName == null) { - throw new UDFArgumentException("featureName should not be null: " - + Arrays.toString(_featureNames)); + throw new UDFArgumentException( + "featureName should not be null: " + Arrays.toString(_featureNames)); } else if (featureName.indexOf(':') != -1) { - throw new UDFArgumentException("featureName should not include colon: " - + featureName); + throw new UDFArgumentException( + "featureName should not include colon: " + featureName); } } @@ -114,16 +113,15 @@ public final class CategoricalFeaturesUDF extends UDFWithOptions { processOptions(optionValue); numFeatures = numArgOIs - 2; } else { - throw new UDFArgumentException( - "Unexpected arguments for _FUNC_" - + "(const array<string> featureNames, feature1, feature2, .. [, const string options])"); + throw new UDFArgumentException("Unexpected arguments for _FUNC_" + + "(const array<string> featureNames, feature1, feature2, .. [, const string options])"); } } else { numFeatures = lastArgIndex; } if (numFeatureNames != numFeatures) { - throw new UDFArgumentLengthException("#featureNames '" + numFeatureNames - + "' != #features '" + numFeatures + "'"); + throw new UDFArgumentLengthException( + "#featureNames '" + numFeatureNames + "' != #features '" + numFeatures + "'"); } this._inputOIs = new PrimitiveObjectInspector[numFeatures]; @@ -133,7 +131,8 @@ public final class CategoricalFeaturesUDF extends UDFWithOptions { } this._result = new ArrayList<String>(numFeatures); - return ObjectInspectorFactory.getStandardListObjectInspector(PrimitiveObjectInspectorFactory.javaStringObjectInspector); + return ObjectInspectorFactory.getStandardListObjectInspector( + PrimitiveObjectInspectorFactory.javaStringObjectInspector); } @Override http://git-wip-us.apache.org/repos/asf/incubator-hivemall/blob/c4036695/core/src/main/java/hivemall/ftvec/trans/FFMFeaturesUDF.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/hivemall/ftvec/trans/FFMFeaturesUDF.java b/core/src/main/java/hivemall/ftvec/trans/FFMFeaturesUDF.java index 33539af..0ed1d92 100644 --- a/core/src/main/java/hivemall/ftvec/trans/FFMFeaturesUDF.java +++ b/core/src/main/java/hivemall/ftvec/trans/FFMFeaturesUDF.java @@ -45,8 +45,7 @@ import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectIn import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorUtils; import org.apache.hadoop.io.Text; -@Description( - name = "ffm_features", +@Description(name = "ffm_features", value = "_FUNC_(const array<string> featureNames, feature1, feature2, .. [, const string options])" + " - Takes categorical variables and returns a feature vector array<string>" + " in a libffm format <field>:<index>:<value>") @@ -86,15 +85,15 @@ public final class FFMFeaturesUDF extends UDFWithOptions { int hashbits = Primitives.parseInt(cl.getOptionValue("feature_hashing"), Feature.DEFAULT_FEATURE_BITS); if (hashbits < 18 || hashbits > 31) { - throw new UDFArgumentException("-feature_hashing MUST be in range [18,31]: " - + hashbits); + throw new UDFArgumentException( + "-feature_hashing MUST be in range [18,31]: " + hashbits); } numFeatures = 1 << hashbits; } this._numFeatures = numFeatures; - int numFields = Primitives.parseInt(cl.getOptionValue("num_fields"), - Feature.DEFAULT_NUM_FIELDS); + int numFields = + Primitives.parseInt(cl.getOptionValue("num_fields"), Feature.DEFAULT_NUM_FIELDS); if (numFields <= 1) { throw new UDFArgumentException("-num_fields MUST be greater than 1: " + numFields); } @@ -119,16 +118,16 @@ public final class FFMFeaturesUDF extends UDFWithOptions { } int numFeatureNames = _featureNames.length; if (numFeatureNames < 1) { - throw new UDFArgumentException("#featureNames must be greater than or equals to 1: " - + numFeatureNames); + throw new UDFArgumentException( + "#featureNames must be greater than or equals to 1: " + numFeatureNames); } for (String featureName : _featureNames) { if (featureName == null) { - throw new UDFArgumentException("featureName should not be null: " - + Arrays.toString(_featureNames)); + throw new UDFArgumentException( + "featureName should not be null: " + Arrays.toString(_featureNames)); } else if (featureName.indexOf(':') != -1) { - throw new UDFArgumentException("featureName should not include colon: " - + featureName); + throw new UDFArgumentException( + "featureName should not include colon: " + featureName); } } @@ -141,16 +140,15 @@ public final class FFMFeaturesUDF extends UDFWithOptions { processOptions(optionValue); numFeatures = numArgOIs - 2; } else { - throw new UDFArgumentException( - "Unexpected arguments for _FUNC_" - + "(const array<string> featureNames, feature1, feature2, .. [, const string options])"); + throw new UDFArgumentException("Unexpected arguments for _FUNC_" + + "(const array<string> featureNames, feature1, feature2, .. [, const string options])"); } } else { numFeatures = lastArgIndex; } if (numFeatureNames != numFeatures) { - throw new UDFArgumentLengthException("#featureNames '" + numFeatureNames - + "' != #features '" + numFeatures + "'"); + throw new UDFArgumentLengthException( + "#featureNames '" + numFeatureNames + "' != #features '" + numFeatures + "'"); } this._inputOIs = new PrimitiveObjectInspector[numFeatures]; @@ -160,7 +158,8 @@ public final class FFMFeaturesUDF extends UDFWithOptions { } this._result = new ArrayList<Text>(numFeatures); - return ObjectInspectorFactory.getStandardListObjectInspector(PrimitiveObjectInspectorFactory.writableStringObjectInspector); + return ObjectInspectorFactory.getStandardListObjectInspector( + PrimitiveObjectInspectorFactory.writableStringObjectInspector); } @Override @@ -189,8 +188,8 @@ public final class FFMFeaturesUDF extends UDFWithOptions { // categorical feature representation final String fv; if (_mhash) { - int field = _emitIndices ? i - : MurmurHash3.murmurhash3(_featureNames[i], _numFields); + int field = + _emitIndices ? i : MurmurHash3.murmurhash3(_featureNames[i], _numFields); // +NUM_FIELD to avoid conflict to quantitative features int index = MurmurHash3.murmurhash3(feature, _numFeatures) + _numFields; fv = builder.append(field).append(':').append(index).append(":1").toString(); http://git-wip-us.apache.org/repos/asf/incubator-hivemall/blob/c4036695/core/src/main/java/hivemall/ftvec/trans/IndexedFeatures.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/hivemall/ftvec/trans/IndexedFeatures.java b/core/src/main/java/hivemall/ftvec/trans/IndexedFeatures.java index eb61006..ededf44 100644 --- a/core/src/main/java/hivemall/ftvec/trans/IndexedFeatures.java +++ b/core/src/main/java/hivemall/ftvec/trans/IndexedFeatures.java @@ -34,8 +34,7 @@ import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector; import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory; import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory; -@Description( - name = "indexed_features", +@Description(name = "indexed_features", value = "_FUNC_(double v1, double v2, ...) - Returns a list of features as array<string>: [1:v1, 2:v2, ..]") @UDFType(deterministic = true, stateful = false) public final class IndexedFeatures extends GenericUDF { @@ -53,7 +52,8 @@ public final class IndexedFeatures extends GenericUDF { } this.list = null; - return ObjectInspectorFactory.getStandardListObjectInspector(PrimitiveObjectInspectorFactory.javaStringObjectInspector); + return ObjectInspectorFactory.getStandardListObjectInspector( + PrimitiveObjectInspectorFactory.javaStringObjectInspector); } @Override http://git-wip-us.apache.org/repos/asf/incubator-hivemall/blob/c4036695/core/src/main/java/hivemall/ftvec/trans/OnehotEncodingUDAF.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/hivemall/ftvec/trans/OnehotEncodingUDAF.java b/core/src/main/java/hivemall/ftvec/trans/OnehotEncodingUDAF.java index 704a4c7..ca76fab 100644 --- a/core/src/main/java/hivemall/ftvec/trans/OnehotEncodingUDAF.java +++ b/core/src/main/java/hivemall/ftvec/trans/OnehotEncodingUDAF.java @@ -64,7 +64,8 @@ public final class OnehotEncodingUDAF extends AbstractGenericUDAFResolver { } @Override - public GenericUDAFEvaluator getEvaluator(@Nonnull TypeInfo[] argTypes) throws SemanticException { + public GenericUDAFEvaluator getEvaluator(@Nonnull TypeInfo[] argTypes) + throws SemanticException { final int numFeatures = argTypes.length; if (numFeatures == 0) { throw new UDFArgumentException("_FUNC_ requires at least 1 argument"); @@ -115,9 +116,11 @@ public final class OnehotEncodingUDAF extends AbstractGenericUDAFResolver { for (int i = 0; i < numFields; i++) { StructField field = mergeOI.getStructFieldRef("f" + String.valueOf(i)); fields[i] = field; - ListObjectInspector fieldOI = HiveUtils.asListOI(field.getFieldObjectInspector()); + ListObjectInspector fieldOI = + HiveUtils.asListOI(field.getFieldObjectInspector()); fieldOIs[i] = fieldOI; - inputElemOIs[i] = HiveUtils.asPrimitiveObjectInspector(fieldOI.getListElementObjectInspector()); + inputElemOIs[i] = HiveUtils.asPrimitiveObjectInspector( + fieldOI.getListElementObjectInspector()); } } @@ -154,7 +157,8 @@ public final class OnehotEncodingUDAF extends AbstractGenericUDAFResolver { fieldNames.add("f" + String.valueOf(i)); ObjectInspector elemOI = ObjectInspectorUtils.getStandardObjectInspector( inputOIs[i], ObjectInspectorCopyOption.WRITABLE); - ListObjectInspector listOI = ObjectInspectorFactory.getStandardListObjectInspector(elemOI); + ListObjectInspector listOI = + ObjectInspectorFactory.getStandardListObjectInspector(elemOI); fieldOIs.add(listOI); } return ObjectInspectorFactory.getStandardStructObjectInspector(fieldNames, fieldOIs); @@ -170,8 +174,8 @@ public final class OnehotEncodingUDAF extends AbstractGenericUDAFResolver { final List<ObjectInspector> fieldOIs = new ArrayList<>(inputOIs.length); for (int i = 0; i < inputOIs.length; i++) { fieldNames.add("f" + String.valueOf(i + 1)); - ObjectInspector keyOI = ObjectInspectorUtils.getStandardObjectInspector( - inputOIs[i], ObjectInspectorCopyOption.WRITABLE); + ObjectInspector keyOI = ObjectInspectorUtils.getStandardObjectInspector(inputOIs[i], + ObjectInspectorCopyOption.WRITABLE); MapObjectInspector mapOI = ObjectInspectorFactory.getStandardMapObjectInspector( keyOI, PrimitiveObjectInspectorFactory.javaIntObjectInspector); fieldOIs.add(mapOI); @@ -213,7 +217,8 @@ public final class OnehotEncodingUDAF extends AbstractGenericUDAFResolver { @SuppressWarnings("deprecation") @Override - public void merge(AggregationBuffer aggregationBuffer, Object partial) throws HiveException { + public void merge(AggregationBuffer aggregationBuffer, Object partial) + throws HiveException { if (partial == null) { return; } @@ -286,7 +291,8 @@ public final class OnehotEncodingUDAF extends AbstractGenericUDAFResolver { @SuppressWarnings("unchecked") void merge(@Nonnull final Object partial, @Nonnull final StructObjectInspector mergeOI, - @Nonnull final StructField[] fields, @Nonnull final ListObjectInspector[] fieldOIs) { + @Nonnull final StructField[] fields, + @Nonnull final ListObjectInspector[] fieldOIs) { Preconditions.checkArgument(fields.length == fieldOIs.length); final int numFields = fieldOIs.length; http://git-wip-us.apache.org/repos/asf/incubator-hivemall/blob/c4036695/core/src/main/java/hivemall/ftvec/trans/QuantifiedFeaturesUDTF.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/hivemall/ftvec/trans/QuantifiedFeaturesUDTF.java b/core/src/main/java/hivemall/ftvec/trans/QuantifiedFeaturesUDTF.java index c036855..0e4572b 100644 --- a/core/src/main/java/hivemall/ftvec/trans/QuantifiedFeaturesUDTF.java +++ b/core/src/main/java/hivemall/ftvec/trans/QuantifiedFeaturesUDTF.java @@ -38,8 +38,7 @@ import org.apache.hadoop.hive.serde2.objectinspector.primitive.BooleanObjectInsp import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory; import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorUtils; -@Description( - name = "quantified_features", +@Description(name = "quantified_features", value = "_FUNC_(boolean output, col1, col2, ...) - Returns an identified features in a dense array<double>") public final class QuantifiedFeaturesUDTF extends GenericUDTF { @@ -56,8 +55,8 @@ public final class QuantifiedFeaturesUDTF extends GenericUDTF { public StructObjectInspector initialize(ObjectInspector[] argOIs) throws UDFArgumentException { int size = argOIs.length; if (size < 2) { - throw new UDFArgumentException("quantified_features takes at least two arguments: " - + size); + throw new UDFArgumentException( + "quantified_features takes at least two arguments: " + size); } this.boolOI = HiveUtils.asBooleanOI(argOIs[0]); @@ -81,7 +80,8 @@ public final class QuantifiedFeaturesUDTF extends GenericUDTF { List<String> fieldNames = new ArrayList<String>(outputSize); List<ObjectInspector> fieldOIs = new ArrayList<ObjectInspector>(outputSize); fieldNames.add("features"); - fieldOIs.add(ObjectInspectorFactory.getStandardListObjectInspector(PrimitiveObjectInspectorFactory.writableDoubleObjectInspector)); + fieldOIs.add(ObjectInspectorFactory.getStandardListObjectInspector( + PrimitiveObjectInspectorFactory.writableDoubleObjectInspector)); return ObjectInspectorFactory.getStandardStructObjectInspector(fieldNames, fieldOIs); } @@ -103,7 +103,8 @@ public final class QuantifiedFeaturesUDTF extends GenericUDTF { values[i].set(v); } else { if (arg == null) { - throw new HiveException("Found Null in the input: " + Arrays.toString(args)); + throw new HiveException( + "Found Null in the input: " + Arrays.toString(args)); } else { String k = arg.toString(); int id = identifier.valueOf(k); http://git-wip-us.apache.org/repos/asf/incubator-hivemall/blob/c4036695/core/src/main/java/hivemall/ftvec/trans/QuantitativeFeaturesUDF.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/hivemall/ftvec/trans/QuantitativeFeaturesUDF.java b/core/src/main/java/hivemall/ftvec/trans/QuantitativeFeaturesUDF.java index 00514cf..002e2cb 100644 --- a/core/src/main/java/hivemall/ftvec/trans/QuantitativeFeaturesUDF.java +++ b/core/src/main/java/hivemall/ftvec/trans/QuantitativeFeaturesUDF.java @@ -42,8 +42,7 @@ import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectIn import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorUtils; import org.apache.hadoop.io.Text; -@Description( - name = "quantitative_features", +@Description(name = "quantitative_features", value = "_FUNC_(array<string> featureNames, feature1, feature2, .. [, const string options])" + " - Returns a feature vector array<string>") @UDFType(deterministic = true, stateful = false) @@ -74,8 +73,8 @@ public final class QuantitativeFeaturesUDF extends UDFWithOptions { throws UDFArgumentException { final int numArgOIs = argOIs.length; if (numArgOIs < 2) { - throw new UDFArgumentException("argOIs.length must be greater that or equals to 2: " - + numArgOIs); + throw new UDFArgumentException( + "argOIs.length must be greater that or equals to 2: " + numArgOIs); } this._featureNames = HiveUtils.getConstStringArray(argOIs[0]); @@ -84,16 +83,16 @@ public final class QuantitativeFeaturesUDF extends UDFWithOptions { } int numFeatureNames = _featureNames.length; if (numFeatureNames < 1) { - throw new UDFArgumentException("#featureNames must be greater than or equals to 1: " - + numFeatureNames); + throw new UDFArgumentException( + "#featureNames must be greater than or equals to 1: " + numFeatureNames); } for (String featureName : _featureNames) { if (featureName == null) { - throw new UDFArgumentException("featureName should not be null: " - + Arrays.toString(_featureNames)); + throw new UDFArgumentException( + "featureName should not be null: " + Arrays.toString(_featureNames)); } else if (featureName.indexOf(':') != -1) { - throw new UDFArgumentException("featureName should not include colon: " - + featureName); + throw new UDFArgumentException( + "featureName should not include colon: " + featureName); } } @@ -106,16 +105,15 @@ public final class QuantitativeFeaturesUDF extends UDFWithOptions { processOptions(optionValue); numFeatures = numArgOIs - 2; } else { - throw new UDFArgumentException( - "Unexpected arguments for _FUNC_" - + "(const array<string> featureNames, feature1, feature2, .. [, const string options])"); + throw new UDFArgumentException("Unexpected arguments for _FUNC_" + + "(const array<string> featureNames, feature1, feature2, .. [, const string options])"); } } else { numFeatures = lastArgIndex; } if (numFeatureNames != numFeatures) { - throw new UDFArgumentLengthException("#featureNames '" + numFeatureNames - + "' != #features '" + numFeatures + "'"); + throw new UDFArgumentLengthException( + "#featureNames '" + numFeatureNames + "' != #features '" + numFeatures + "'"); } this._inputOIs = new PrimitiveObjectInspector[numFeatures]; @@ -125,7 +123,8 @@ public final class QuantitativeFeaturesUDF extends UDFWithOptions { } this._result = new ArrayList<Text>(numFeatures); - return ObjectInspectorFactory.getStandardListObjectInspector(PrimitiveObjectInspectorFactory.writableStringObjectInspector); + return ObjectInspectorFactory.getStandardListObjectInspector( + PrimitiveObjectInspectorFactory.writableStringObjectInspector); } @Override http://git-wip-us.apache.org/repos/asf/incubator-hivemall/blob/c4036695/core/src/main/java/hivemall/ftvec/trans/VectorizeFeaturesUDF.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/hivemall/ftvec/trans/VectorizeFeaturesUDF.java b/core/src/main/java/hivemall/ftvec/trans/VectorizeFeaturesUDF.java index 4a37f94..b846235 100644 --- a/core/src/main/java/hivemall/ftvec/trans/VectorizeFeaturesUDF.java +++ b/core/src/main/java/hivemall/ftvec/trans/VectorizeFeaturesUDF.java @@ -43,8 +43,7 @@ import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectIn import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorUtils; import org.apache.hadoop.io.Text; -@Description( - name = "vectorize_features", +@Description(name = "vectorize_features", value = "_FUNC_(array<string> featureNames, feature1, feature2, .. [, const string options])" + " - Returns a feature vector array<string>") @UDFType(deterministic = true, stateful = false) @@ -75,8 +74,8 @@ public final class VectorizeFeaturesUDF extends UDFWithOptions { throws UDFArgumentException { final int numArgOIs = argOIs.length; if (numArgOIs < 2) { - throw new UDFArgumentException("argOIs.length must be greater that or equals to 2: " - + numArgOIs); + throw new UDFArgumentException( + "argOIs.length must be greater that or equals to 2: " + numArgOIs); } this._featureNames = HiveUtils.getConstStringArray(argOIs[0]); @@ -85,16 +84,16 @@ public final class VectorizeFeaturesUDF extends UDFWithOptions { } int numFeatureNames = _featureNames.length; if (numFeatureNames < 1) { - throw new UDFArgumentException("#featureNames must be greater than or equals to 1: " - + numFeatureNames); + throw new UDFArgumentException( + "#featureNames must be greater than or equals to 1: " + numFeatureNames); } for (String featureName : _featureNames) { if (featureName == null) { - throw new UDFArgumentException("featureName should not be null: " - + Arrays.toString(_featureNames)); + throw new UDFArgumentException( + "featureName should not be null: " + Arrays.toString(_featureNames)); } else if (featureName.indexOf(':') != -1) { - throw new UDFArgumentException("featureName should not include colon: " - + featureName); + throw new UDFArgumentException( + "featureName should not include colon: " + featureName); } } @@ -107,16 +106,15 @@ public final class VectorizeFeaturesUDF extends UDFWithOptions { processOptions(optionValue); numFeatures = numArgOIs - 2; } else { - throw new UDFArgumentException( - "Unexpected arguments for _FUNC_" - + "(const array<string> featureNames, feature1, feature2, .. [, const string options])"); + throw new UDFArgumentException("Unexpected arguments for _FUNC_" + + "(const array<string> featureNames, feature1, feature2, .. [, const string options])"); } } else { numFeatures = lastArgIndex; } if (numFeatureNames != numFeatures) { - throw new UDFArgumentLengthException("#featureNames '" + numFeatureNames - + "' != #features '" + numFeatures + "'"); + throw new UDFArgumentLengthException( + "#featureNames '" + numFeatureNames + "' != #features '" + numFeatures + "'"); } this._inputOIs = new PrimitiveObjectInspector[numFeatures]; @@ -126,7 +124,8 @@ public final class VectorizeFeaturesUDF extends UDFWithOptions { } this._result = new ArrayList<Text>(numFeatures); - return ObjectInspectorFactory.getStandardListObjectInspector(PrimitiveObjectInspectorFactory.writableStringObjectInspector); + return ObjectInspectorFactory.getStandardListObjectInspector( + PrimitiveObjectInspectorFactory.writableStringObjectInspector); } @Override http://git-wip-us.apache.org/repos/asf/incubator-hivemall/blob/c4036695/core/src/main/java/hivemall/geospatial/HaversineDistanceUDF.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/hivemall/geospatial/HaversineDistanceUDF.java b/core/src/main/java/hivemall/geospatial/HaversineDistanceUDF.java index b01d974..3cce1cf 100644 --- a/core/src/main/java/hivemall/geospatial/HaversineDistanceUDF.java +++ b/core/src/main/java/hivemall/geospatial/HaversineDistanceUDF.java @@ -41,8 +41,7 @@ import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectIn * @link https://en.wikipedia.org/wiki/Haversine_formula * @link https://rosettacode.org/wiki/Haversine_formula */ -@Description( - name = "haversine_distance", +@Description(name = "haversine_distance", value = "_FUNC_(double lat1, double lon1, double lat2, double lon2, [const boolean mile=false])::double" + " - return distance between two locations in km [or miles] using `haversine` formula", extended = "Usage: select latlon_distance(lat1, lon1, lat2, lon2) from ...") http://git-wip-us.apache.org/repos/asf/incubator-hivemall/blob/c4036695/core/src/main/java/hivemall/geospatial/Lat2TileYUDF.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/hivemall/geospatial/Lat2TileYUDF.java b/core/src/main/java/hivemall/geospatial/Lat2TileYUDF.java index 3a16293..2116a75 100644 --- a/core/src/main/java/hivemall/geospatial/Lat2TileYUDF.java +++ b/core/src/main/java/hivemall/geospatial/Lat2TileYUDF.java @@ -38,8 +38,7 @@ import org.apache.hadoop.io.IntWritable; /** * @link http://wiki.openstreetmap.org/wiki/Slippy_map_tilenames */ -@Description( - name = "lat2tiley", +@Description(name = "lat2tiley", value = "_FUNC_(double lat, int zoom)::int - Returns the tile number of the given latitude and zoom level") @UDFType(deterministic = true, stateful = false) public final class Lat2TileYUDF extends GenericUDF { http://git-wip-us.apache.org/repos/asf/incubator-hivemall/blob/c4036695/core/src/main/java/hivemall/geospatial/Lon2TileXUDF.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/hivemall/geospatial/Lon2TileXUDF.java b/core/src/main/java/hivemall/geospatial/Lon2TileXUDF.java index 36103ec..877e8cd 100644 --- a/core/src/main/java/hivemall/geospatial/Lon2TileXUDF.java +++ b/core/src/main/java/hivemall/geospatial/Lon2TileXUDF.java @@ -38,8 +38,7 @@ import org.apache.hadoop.io.IntWritable; /** * @link http://wiki.openstreetmap.org/wiki/Slippy_map_tilenames */ -@Description( - name = "lon2tilex", +@Description(name = "lon2tilex", value = "_FUNC_(double lon, int zoom)::int - Returns the tile number of the given longitude and zoom level") @UDFType(deterministic = true, stateful = false) public final class Lon2TileXUDF extends GenericUDF { http://git-wip-us.apache.org/repos/asf/incubator-hivemall/blob/c4036695/core/src/main/java/hivemall/geospatial/MapURLUDF.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/hivemall/geospatial/MapURLUDF.java b/core/src/main/java/hivemall/geospatial/MapURLUDF.java index ed06604..58a94ef 100644 --- a/core/src/main/java/hivemall/geospatial/MapURLUDF.java +++ b/core/src/main/java/hivemall/geospatial/MapURLUDF.java @@ -38,8 +38,7 @@ import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectIn import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorUtils; import org.apache.hadoop.io.Text; -@Description( - name = "map_url", +@Description(name = "map_url", value = "_FUNC_(double lat, double lon, int zoom [, const string option]) - Returns a URL string", extended = "OpenStreetMap: http://tile.openstreetmap.org/${zoom}/${xtile}/${ytile}.png\n" + "Google Maps: https://www.google.com/maps/@${lat},${lon},${zoom}z") @@ -129,7 +128,8 @@ public final class MapURLUDF extends UDFWithOptions { if (type == MapType.openstreetmap) {// http://tile.openstreetmap.org/${zoom}/${xtile}/${ytile}.png if (zoom < 0 || zoom > 19) { throw new UDFArgumentException( - "Illegal zoom level. Supported zoom level for openstreetmap is [0,19]: " + zoom); + "Illegal zoom level. Supported zoom level for openstreetmap is [0,19]: " + + zoom); } final int xtile, ytile; try { http://git-wip-us.apache.org/repos/asf/incubator-hivemall/blob/c4036695/core/src/main/java/hivemall/geospatial/TileUDF.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/hivemall/geospatial/TileUDF.java b/core/src/main/java/hivemall/geospatial/TileUDF.java index 164aa56..0e7b800 100644 --- a/core/src/main/java/hivemall/geospatial/TileUDF.java +++ b/core/src/main/java/hivemall/geospatial/TileUDF.java @@ -38,8 +38,7 @@ import org.apache.hadoop.io.LongWritable; /** * @link http://wiki.openstreetmap.org/wiki/Slippy_map_tilenames */ -@Description( - name = "tile", +@Description(name = "tile", value = "_FUNC_(double lat, double lon, int zoom)::bigint - Returns a tile number 2^2n where n is zoom level.\n" + "_FUNC_(lat,lon,zoom) = xtile(lon,zoom) + ytile(lat,zoom) * 2^zoom", extended = "refer http://wiki.openstreetmap.org/wiki/Slippy_map_tilenames for detail") http://git-wip-us.apache.org/repos/asf/incubator-hivemall/blob/c4036695/core/src/main/java/hivemall/geospatial/TileX2LonUDF.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/hivemall/geospatial/TileX2LonUDF.java b/core/src/main/java/hivemall/geospatial/TileX2LonUDF.java index 5979227..bf06a7d 100644 --- a/core/src/main/java/hivemall/geospatial/TileX2LonUDF.java +++ b/core/src/main/java/hivemall/geospatial/TileX2LonUDF.java @@ -38,8 +38,7 @@ import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectIn /** * @link http://wiki.openstreetmap.org/wiki/Slippy_map_tilenames */ -@Description( - name = "tilex2lon", +@Description(name = "tilex2lon", value = "_FUNC_(int x, int zoom)::double - Returns longitude of the given tile x and zoom level") @UDFType(deterministic = true, stateful = false) public final class TileX2LonUDF extends GenericUDF { http://git-wip-us.apache.org/repos/asf/incubator-hivemall/blob/c4036695/core/src/main/java/hivemall/geospatial/TileY2LatUDF.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/hivemall/geospatial/TileY2LatUDF.java b/core/src/main/java/hivemall/geospatial/TileY2LatUDF.java index f2e6da0..5d2a6da 100644 --- a/core/src/main/java/hivemall/geospatial/TileY2LatUDF.java +++ b/core/src/main/java/hivemall/geospatial/TileY2LatUDF.java @@ -38,8 +38,7 @@ import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectIn /** * @link http://wiki.openstreetmap.org/wiki/Slippy_map_tilenames */ -@Description( - name = "tiley2lat", +@Description(name = "tiley2lat", value = "_FUNC_(int y, int zoom)::double - Returns latitude of the given tile y and zoom level") @UDFType(deterministic = true, stateful = false) public final class TileY2LatUDF extends GenericUDF { http://git-wip-us.apache.org/repos/asf/incubator-hivemall/blob/c4036695/core/src/main/java/hivemall/knn/distance/EuclidDistanceUDF.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/hivemall/knn/distance/EuclidDistanceUDF.java b/core/src/main/java/hivemall/knn/distance/EuclidDistanceUDF.java index 26401f6..ca06fcb 100644 --- a/core/src/main/java/hivemall/knn/distance/EuclidDistanceUDF.java +++ b/core/src/main/java/hivemall/knn/distance/EuclidDistanceUDF.java @@ -36,8 +36,7 @@ import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector; import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory; import org.apache.hadoop.io.FloatWritable; -@Description( - name = "euclid_distance", +@Description(name = "euclid_distance", value = "_FUNC_(ftvec1, ftvec2) - Returns the square root of the sum of the squared differences" + ": sqrt(sum((x - y)^2))") @UDFType(deterministic = true, stateful = false) http://git-wip-us.apache.org/repos/asf/incubator-hivemall/blob/c4036695/core/src/main/java/hivemall/knn/distance/KLDivergenceUDF.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/hivemall/knn/distance/KLDivergenceUDF.java b/core/src/main/java/hivemall/knn/distance/KLDivergenceUDF.java index 9ba682a..5b68be3 100644 --- a/core/src/main/java/hivemall/knn/distance/KLDivergenceUDF.java +++ b/core/src/main/java/hivemall/knn/distance/KLDivergenceUDF.java @@ -41,7 +41,8 @@ public final class KLDivergenceUDF extends UDF { public static double kld(final double mu1, final double sigma1, final double mu2, final double sigma2) { - return (Math.log(sigma2 / sigma1) + sigma2 / sigma1 + Math.pow(mu1 - mu2, 2) / sigma2 - 1.d) * 0.5d; + return (Math.log(sigma2 / sigma1) + sigma2 / sigma1 + Math.pow(mu1 - mu2, 2) / sigma2 - 1.d) + * 0.5d; } } http://git-wip-us.apache.org/repos/asf/incubator-hivemall/blob/c4036695/core/src/main/java/hivemall/knn/lsh/MinHashUDTF.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/hivemall/knn/lsh/MinHashUDTF.java b/core/src/main/java/hivemall/knn/lsh/MinHashUDTF.java index 2d86337..e2b921c 100644 --- a/core/src/main/java/hivemall/knn/lsh/MinHashUDTF.java +++ b/core/src/main/java/hivemall/knn/lsh/MinHashUDTF.java @@ -47,8 +47,7 @@ import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectIn /** * A Minhash implementation that outputs n different k-depth Signatures. */ -@Description( - name = "minhash", +@Description(name = "minhash", value = "_FUNC_(ANY item, array<int|bigint|string> features [, constant string options])" + " - Returns n different k-depth signatures (i.e., clusterid) for each item <clusterid, item>") @UDFType(deterministic = true, stateful = false) http://git-wip-us.apache.org/repos/asf/incubator-hivemall/blob/c4036695/core/src/main/java/hivemall/knn/lsh/MinHashesUDF.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/hivemall/knn/lsh/MinHashesUDF.java b/core/src/main/java/hivemall/knn/lsh/MinHashesUDF.java index 6fc12c9..bf248e9 100644 --- a/core/src/main/java/hivemall/knn/lsh/MinHashesUDF.java +++ b/core/src/main/java/hivemall/knn/lsh/MinHashesUDF.java @@ -66,7 +66,8 @@ public final class MinHashesUDF extends UDF { return computeSignatures(featureList, numHashes, keyGroups, seeds); } - public List<IntWritable> evaluate(List<String> features, boolean noWeight) throws HiveException { + public List<IntWritable> evaluate(List<String> features, boolean noWeight) + throws HiveException { return evaluate(features, 5, 2, noWeight); } http://git-wip-us.apache.org/repos/asf/incubator-hivemall/blob/c4036695/core/src/main/java/hivemall/knn/lsh/bBitMinHashUDF.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/hivemall/knn/lsh/bBitMinHashUDF.java b/core/src/main/java/hivemall/knn/lsh/bBitMinHashUDF.java index 71f4fbe..9687931 100644 --- a/core/src/main/java/hivemall/knn/lsh/bBitMinHashUDF.java +++ b/core/src/main/java/hivemall/knn/lsh/bBitMinHashUDF.java @@ -33,8 +33,8 @@ import org.apache.hadoop.hive.ql.metadata.HiveException; import org.apache.hadoop.hive.ql.udf.UDFType; import org.apache.hadoop.io.Text; -@Description(name = "bbit_minhash", value = "_FUNC_(array<> features [, int numHashes])" - + " - Returns a b-bits minhash value") +@Description(name = "bbit_minhash", + value = "_FUNC_(array<> features [, int numHashes])" + " - Returns a b-bits minhash value") @UDFType(deterministic = true, stateful = false) public final class bBitMinHashUDF extends UDF { @@ -106,8 +106,8 @@ public final class bBitMinHashUDF extends UDF { private static String computeSignatures(final List<FeatureValue> features, final int numHashes, final int[] seeds) throws HiveException { if (numHashes <= 0 || numHashes > 512) { - throw new HiveException("The number of hash function must be in range (0,512]: " - + numHashes); + throw new HiveException( + "The number of hash function must be in range (0,512]: " + numHashes); } final int[] hashes = new int[numHashes]; // Compute N sets K minhash values http://git-wip-us.apache.org/repos/asf/incubator-hivemall/blob/c4036695/core/src/main/java/hivemall/knn/similarity/DIMSUMMapperUDTF.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/hivemall/knn/similarity/DIMSUMMapperUDTF.java b/core/src/main/java/hivemall/knn/similarity/DIMSUMMapperUDTF.java index 58c0e9a..1a91121 100644 --- a/core/src/main/java/hivemall/knn/similarity/DIMSUMMapperUDTF.java +++ b/core/src/main/java/hivemall/knn/similarity/DIMSUMMapperUDTF.java @@ -50,8 +50,7 @@ import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectIn import org.apache.hadoop.io.IntWritable; import org.apache.hadoop.io.Text; -@Description( - name = "dimsum_mapper", +@Description(name = "dimsum_mapper", value = "_FUNC_(array<string> row, map<int col_id, double norm> colNorms [, const string options]) " + "- Returns column-wise partial similarities") public final class DIMSUMMapperUDTF extends UDTFWithOptions { http://git-wip-us.apache.org/repos/asf/incubator-hivemall/blob/c4036695/core/src/main/java/hivemall/math/matrix/AbstractMatrix.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/hivemall/math/matrix/AbstractMatrix.java b/core/src/main/java/hivemall/math/matrix/AbstractMatrix.java index fe3c543..627ef9c 100644 --- a/core/src/main/java/hivemall/math/matrix/AbstractMatrix.java +++ b/core/src/main/java/hivemall/math/matrix/AbstractMatrix.java @@ -53,7 +53,8 @@ public abstract class AbstractMatrix implements Matrix { protected static final void checkColIndex(final int col, final int numColumns) { if (col < 0 || col >= numColumns) { - throw new IndexOutOfBoundsException("Col index " + col + " out of bounds " + numColumns); + throw new IndexOutOfBoundsException( + "Col index " + col + " out of bounds " + numColumns); } } @@ -78,7 +79,8 @@ public abstract class AbstractMatrix implements Matrix { throw new IndexOutOfBoundsException("Row index " + row + " out of bounds " + numRows); } if (col < 0 || col >= numColumns) { - throw new IndexOutOfBoundsException("Col index " + col + " out of bounds " + numColumns); + throw new IndexOutOfBoundsException( + "Col index " + col + " out of bounds " + numColumns); } } http://git-wip-us.apache.org/repos/asf/incubator-hivemall/blob/c4036695/core/src/main/java/hivemall/math/matrix/FloatMatrix.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/hivemall/math/matrix/FloatMatrix.java b/core/src/main/java/hivemall/math/matrix/FloatMatrix.java index fe26175..afc54a0 100644 --- a/core/src/main/java/hivemall/math/matrix/FloatMatrix.java +++ b/core/src/main/java/hivemall/math/matrix/FloatMatrix.java @@ -39,7 +39,8 @@ public interface FloatMatrix extends Matrix { * @throws IndexOutOfBoundsException * @throws UnsupportedOperationException */ - public float getAndSet(@Nonnegative final int row, @Nonnegative final int col, final float value); + public float getAndSet(@Nonnegative final int row, @Nonnegative final int col, + final float value); /** * @return returns dst http://git-wip-us.apache.org/repos/asf/incubator-hivemall/blob/c4036695/core/src/main/java/hivemall/math/matrix/builders/ColumnMajorDenseMatrixBuilder.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/hivemall/math/matrix/builders/ColumnMajorDenseMatrixBuilder.java b/core/src/main/java/hivemall/math/matrix/builders/ColumnMajorDenseMatrixBuilder.java index d212271..b830219 100644 --- a/core/src/main/java/hivemall/math/matrix/builders/ColumnMajorDenseMatrixBuilder.java +++ b/core/src/main/java/hivemall/math/matrix/builders/ColumnMajorDenseMatrixBuilder.java @@ -49,7 +49,8 @@ public final class ColumnMajorDenseMatrixBuilder extends MatrixBuilder { } @Override - public ColumnMajorDenseMatrixBuilder nextColumn(@Nonnegative final int col, final double value) { + public ColumnMajorDenseMatrixBuilder nextColumn(@Nonnegative final int col, + final double value) { if (value == 0.d) { return this; } http://git-wip-us.apache.org/repos/asf/incubator-hivemall/blob/c4036695/core/src/main/java/hivemall/math/matrix/builders/MatrixBuilder.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/hivemall/math/matrix/builders/MatrixBuilder.java b/core/src/main/java/hivemall/math/matrix/builders/MatrixBuilder.java index 6f8c46a..7688086 100644 --- a/core/src/main/java/hivemall/math/matrix/builders/MatrixBuilder.java +++ b/core/src/main/java/hivemall/math/matrix/builders/MatrixBuilder.java @@ -78,8 +78,8 @@ public abstract class MatrixBuilder { int colIndex = Integer.parseInt(feature); if (colIndex < 0) { - throw new IllegalArgumentException("Col index MUST be greater than or equals to 0: " - + colIndex); + throw new IllegalArgumentException( + "Col index MUST be greater than or equals to 0: " + colIndex); } return nextColumn(colIndex, value); http://git-wip-us.apache.org/repos/asf/incubator-hivemall/blob/c4036695/core/src/main/java/hivemall/math/matrix/ints/AbstractIntMatrix.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/hivemall/math/matrix/ints/AbstractIntMatrix.java b/core/src/main/java/hivemall/math/matrix/ints/AbstractIntMatrix.java index 0431310..1c5fb6e 100644 --- a/core/src/main/java/hivemall/math/matrix/ints/AbstractIntMatrix.java +++ b/core/src/main/java/hivemall/math/matrix/ints/AbstractIntMatrix.java @@ -60,7 +60,8 @@ public abstract class AbstractIntMatrix implements IntMatrix { protected static final void checkColIndex(final int col, final int numColumns) { if (col < 0 || col >= numColumns) { - throw new IndexOutOfBoundsException("Col index " + col + " out of bounds " + numColumns); + throw new IndexOutOfBoundsException( + "Col index " + col + " out of bounds " + numColumns); } } @@ -85,7 +86,8 @@ public abstract class AbstractIntMatrix implements IntMatrix { throw new IndexOutOfBoundsException("Row index " + row + " out of bounds " + numRows); } if (col < 0 || col >= numColumns) { - throw new IndexOutOfBoundsException("Col index " + col + " out of bounds " + numColumns); + throw new IndexOutOfBoundsException( + "Col index " + col + " out of bounds " + numColumns); } } http://git-wip-us.apache.org/repos/asf/incubator-hivemall/blob/c4036695/core/src/main/java/hivemall/math/matrix/ints/DoKIntMatrix.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/hivemall/math/matrix/ints/DoKIntMatrix.java b/core/src/main/java/hivemall/math/matrix/ints/DoKIntMatrix.java index 2bbd3b4..5feb423 100644 --- a/core/src/main/java/hivemall/math/matrix/ints/DoKIntMatrix.java +++ b/core/src/main/java/hivemall/math/matrix/ints/DoKIntMatrix.java @@ -48,8 +48,8 @@ public final class DoKIntMatrix extends AbstractIntMatrix { public DoKIntMatrix(@Nonnegative int numRows, @Nonnegative int numCols, @Nonnegative float sparsity) { - Preconditions.checkArgument(sparsity >= 0.f && sparsity <= 1.f, "Invalid Sparsity value: " - + sparsity); + Preconditions.checkArgument(sparsity >= 0.f && sparsity <= 1.f, + "Invalid Sparsity value: " + sparsity); int initialCapacity = Math.max(16384, Math.round(numRows * numCols * sparsity)); this.elements = new Long2IntOpenHashTable(initialCapacity); this.numRows = numRows; @@ -249,10 +249,10 @@ public final class DoKIntMatrix extends AbstractIntMatrix { } @Nonnull - private static DoKIntMatrix buildFromColumnMajorMatrix( - @Nonnull final int[][] columnMajorMatrix, boolean nonZeroOnly) { - final Long2IntOpenHashTable elements = new Long2IntOpenHashTable( - columnMajorMatrix.length * 3); + private static DoKIntMatrix buildFromColumnMajorMatrix(@Nonnull final int[][] columnMajorMatrix, + boolean nonZeroOnly) { + final Long2IntOpenHashTable elements = + new Long2IntOpenHashTable(columnMajorMatrix.length * 3); int numRows = 0, numColumns = columnMajorMatrix.length; for (int j = 0; j < columnMajorMatrix.length; j++) { http://git-wip-us.apache.org/repos/asf/incubator-hivemall/blob/c4036695/core/src/main/java/hivemall/math/matrix/sparse/CSCMatrix.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/hivemall/math/matrix/sparse/CSCMatrix.java b/core/src/main/java/hivemall/math/matrix/sparse/CSCMatrix.java index 3fe2202..317a0f1 100644 --- a/core/src/main/java/hivemall/math/matrix/sparse/CSCMatrix.java +++ b/core/src/main/java/hivemall/math/matrix/sparse/CSCMatrix.java @@ -171,8 +171,8 @@ public final class CSCMatrix extends ColumnMajorMatrix { final int index = getIndex(row, col); if (index < 0) { - throw new UnsupportedOperationException("Cannot update value in row " + row + ", col " - + col); + throw new UnsupportedOperationException( + "Cannot update value in row " + row + ", col " + col); } double old = values[index]; @@ -186,8 +186,8 @@ public final class CSCMatrix extends ColumnMajorMatrix { final int index = getIndex(row, col); if (index < 0) { - throw new UnsupportedOperationException("Cannot update value in row " + row + ", col " - + col); + throw new UnsupportedOperationException( + "Cannot update value in row " + row + ", col " + col); } values[index] = value; } @@ -197,8 +197,8 @@ public final class CSCMatrix extends ColumnMajorMatrix { int rightEx = columnPointers[col + 1]; final int index = Arrays.binarySearch(rowIndices, leftIn, rightEx, row); if (index >= 0 && index >= values.length) { - throw new IndexOutOfBoundsException("Value index " + index + " out of range " - + values.length); + throw new IndexOutOfBoundsException( + "Value index " + index + " out of range " + values.length); } return index; } http://git-wip-us.apache.org/repos/asf/incubator-hivemall/blob/c4036695/core/src/main/java/hivemall/math/matrix/sparse/CSRMatrix.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/hivemall/math/matrix/sparse/CSRMatrix.java b/core/src/main/java/hivemall/math/matrix/sparse/CSRMatrix.java index 9ce3054..8a63c9c 100644 --- a/core/src/main/java/hivemall/math/matrix/sparse/CSRMatrix.java +++ b/core/src/main/java/hivemall/math/matrix/sparse/CSRMatrix.java @@ -53,8 +53,8 @@ public final class CSRMatrix extends RowMajorMatrix { public CSRMatrix(@Nonnull int[] rowPointers, @Nonnull int[] columnIndices, @Nonnull double[] values, @Nonnegative int numColumns) { super(); - Preconditions.checkArgument(rowPointers.length >= 1, "rowPointers must be greater than 0: " - + rowPointers.length); + Preconditions.checkArgument(rowPointers.length >= 1, + "rowPointers must be greater than 0: " + rowPointers.length); Preconditions.checkArgument(columnIndices.length == values.length, "#columnIndices (" + columnIndices.length + ") must be equals to #values (" + values.length + ")"); this.rowPointers = rowPointers; @@ -145,8 +145,8 @@ public final class CSRMatrix extends RowMajorMatrix { final int index = getIndex(row, col); if (index < 0) { - throw new UnsupportedOperationException("Cannot update value in row " + row + ", col " - + col); + throw new UnsupportedOperationException( + "Cannot update value in row " + row + ", col " + col); } double old = values[index]; @@ -160,8 +160,8 @@ public final class CSRMatrix extends RowMajorMatrix { final int index = getIndex(row, col); if (index < 0) { - throw new UnsupportedOperationException("Cannot update value in row " + row + ", col " - + col); + throw new UnsupportedOperationException( + "Cannot update value in row " + row + ", col " + col); } values[index] = value; } @@ -171,8 +171,8 @@ public final class CSRMatrix extends RowMajorMatrix { int rightEx = rowPointers[row + 1]; final int index = Arrays.binarySearch(columnIndices, leftIn, rightEx, col); if (index >= 0 && index >= values.length) { - throw new IndexOutOfBoundsException("Value index " + index + " out of range " - + values.length); + throw new IndexOutOfBoundsException( + "Value index " + index + " out of range " + values.length); } return index; } http://git-wip-us.apache.org/repos/asf/incubator-hivemall/blob/c4036695/core/src/main/java/hivemall/math/matrix/sparse/DoKMatrix.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/hivemall/math/matrix/sparse/DoKMatrix.java b/core/src/main/java/hivemall/math/matrix/sparse/DoKMatrix.java index 6dc0502..8ac0cf9 100644 --- a/core/src/main/java/hivemall/math/matrix/sparse/DoKMatrix.java +++ b/core/src/main/java/hivemall/math/matrix/sparse/DoKMatrix.java @@ -59,10 +59,11 @@ public final class DoKMatrix extends AbstractMatrix { this(numRows, numCols, 0.05f); } - public DoKMatrix(@Nonnegative int numRows, @Nonnegative int numCols, @Nonnegative float sparsity) { + public DoKMatrix(@Nonnegative int numRows, @Nonnegative int numCols, + @Nonnegative float sparsity) { super(); - Preconditions.checkArgument(sparsity >= 0.f && sparsity <= 1.f, "Invalid Sparsity value: " - + sparsity); + Preconditions.checkArgument(sparsity >= 0.f && sparsity <= 1.f, + "Invalid Sparsity value: " + sparsity); int initialCapacity = Math.max(16384, Math.round(numRows * numCols * sparsity)); this.elements = new Long2DoubleOpenHashTable(initialCapacity); elements.defaultReturnValue(0.d); http://git-wip-us.apache.org/repos/asf/incubator-hivemall/blob/c4036695/core/src/main/java/hivemall/math/matrix/sparse/floats/CSCFloatMatrix.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/hivemall/math/matrix/sparse/floats/CSCFloatMatrix.java b/core/src/main/java/hivemall/math/matrix/sparse/floats/CSCFloatMatrix.java index 9421f1c..14b5240 100644 --- a/core/src/main/java/hivemall/math/matrix/sparse/floats/CSCFloatMatrix.java +++ b/core/src/main/java/hivemall/math/matrix/sparse/floats/CSCFloatMatrix.java @@ -192,8 +192,8 @@ public final class CSCFloatMatrix extends ColumnMajorFloatMatrix { final int index = getIndex(row, col); if (index < 0) { - throw new UnsupportedOperationException("Cannot update value in row " + row + ", col " - + col); + throw new UnsupportedOperationException( + "Cannot update value in row " + row + ", col " + col); } float old = values[index]; @@ -207,8 +207,8 @@ public final class CSCFloatMatrix extends ColumnMajorFloatMatrix { final int index = getIndex(row, col); if (index < 0) { - throw new UnsupportedOperationException("Cannot update value in row " + row + ", col " - + col); + throw new UnsupportedOperationException( + "Cannot update value in row " + row + ", col " + col); } values[index] = value; } @@ -218,8 +218,8 @@ public final class CSCFloatMatrix extends ColumnMajorFloatMatrix { int rightEx = columnPointers[col + 1]; final int index = Arrays.binarySearch(rowIndices, leftIn, rightEx, row); if (index >= 0 && index >= values.length) { - throw new IndexOutOfBoundsException("Value index " + index + " out of range " - + values.length); + throw new IndexOutOfBoundsException( + "Value index " + index + " out of range " + values.length); } return index; } http://git-wip-us.apache.org/repos/asf/incubator-hivemall/blob/c4036695/core/src/main/java/hivemall/math/matrix/sparse/floats/CSRFloatMatrix.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/hivemall/math/matrix/sparse/floats/CSRFloatMatrix.java b/core/src/main/java/hivemall/math/matrix/sparse/floats/CSRFloatMatrix.java index 38e28a9..d20ed14 100644 --- a/core/src/main/java/hivemall/math/matrix/sparse/floats/CSRFloatMatrix.java +++ b/core/src/main/java/hivemall/math/matrix/sparse/floats/CSRFloatMatrix.java @@ -53,8 +53,8 @@ public final class CSRFloatMatrix extends RowMajorFloatMatrix { public CSRFloatMatrix(@Nonnull int[] rowPointers, @Nonnull int[] columnIndices, @Nonnull float[] values, @Nonnegative int numColumns) { super(); - Preconditions.checkArgument(rowPointers.length >= 1, "rowPointers must be greater than 0: " - + rowPointers.length); + Preconditions.checkArgument(rowPointers.length >= 1, + "rowPointers must be greater than 0: " + rowPointers.length); Preconditions.checkArgument(columnIndices.length == values.length, "#columnIndices (" + columnIndices.length + ") must be equals to #values (" + values.length + ")"); this.rowPointers = rowPointers; @@ -151,13 +151,14 @@ public final class CSRFloatMatrix extends RowMajorFloatMatrix { } @Override - public float getAndSet(@Nonnegative final int row, @Nonnegative final int col, final float value) { + public float getAndSet(@Nonnegative final int row, @Nonnegative final int col, + final float value) { checkIndex(row, col, numRows, numColumns); final int index = getIndex(row, col); if (index < 0) { - throw new UnsupportedOperationException("Cannot update value in row " + row + ", col " - + col); + throw new UnsupportedOperationException( + "Cannot update value in row " + row + ", col " + col); } float old = values[index]; @@ -171,8 +172,8 @@ public final class CSRFloatMatrix extends RowMajorFloatMatrix { final int index = getIndex(row, col); if (index < 0) { - throw new UnsupportedOperationException("Cannot update value in row " + row + ", col " - + col); + throw new UnsupportedOperationException( + "Cannot update value in row " + row + ", col " + col); } values[index] = value; } @@ -182,8 +183,8 @@ public final class CSRFloatMatrix extends RowMajorFloatMatrix { int rightEx = rowPointers[row + 1]; final int index = Arrays.binarySearch(columnIndices, leftIn, rightEx, col); if (index >= 0 && index >= values.length) { - throw new IndexOutOfBoundsException("Value index " + index + " out of range " - + values.length); + throw new IndexOutOfBoundsException( + "Value index " + index + " out of range " + values.length); } return index; } http://git-wip-us.apache.org/repos/asf/incubator-hivemall/blob/c4036695/core/src/main/java/hivemall/math/matrix/sparse/floats/DoKFloatMatrix.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/hivemall/math/matrix/sparse/floats/DoKFloatMatrix.java b/core/src/main/java/hivemall/math/matrix/sparse/floats/DoKFloatMatrix.java index 110e391..36b8d7a 100644 --- a/core/src/main/java/hivemall/math/matrix/sparse/floats/DoKFloatMatrix.java +++ b/core/src/main/java/hivemall/math/matrix/sparse/floats/DoKFloatMatrix.java @@ -61,8 +61,8 @@ public final class DoKFloatMatrix extends AbstractMatrix implements FloatMatrix public DoKFloatMatrix(@Nonnegative int numRows, @Nonnegative int numCols, @Nonnegative float sparsity) { super(); - Preconditions.checkArgument(sparsity >= 0.f && sparsity <= 1.f, "Invalid Sparsity value: " - + sparsity); + Preconditions.checkArgument(sparsity >= 0.f && sparsity <= 1.f, + "Invalid Sparsity value: " + sparsity); int initialCapacity = Math.max(16384, Math.round(numRows * numCols * sparsity)); this.elements = new Long2FloatOpenHashTable(initialCapacity); elements.defaultReturnValue(0.f); @@ -205,7 +205,8 @@ public final class DoKFloatMatrix extends AbstractMatrix implements FloatMatrix } @Override - public float getAndSet(@Nonnegative final int row, @Nonnegative final int col, final float value) { + public float getAndSet(@Nonnegative final int row, @Nonnegative final int col, + final float value) { checkIndex(row, col); final long index = index(row, col);
