當前位置: 首頁>>代碼示例>>Java>>正文


Java FloatWritable類代碼示例

本文整理匯總了Java中org.apache.hadoop.io.FloatWritable的典型用法代碼示例。如果您正苦於以下問題:Java FloatWritable類的具體用法?Java FloatWritable怎麽用?Java FloatWritable使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


FloatWritable類屬於org.apache.hadoop.io包,在下文中一共展示了FloatWritable類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: main

import org.apache.hadoop.io.FloatWritable; //導入依賴的package包/類
public static void main(String[] args) throws Exception {
	Configuration conf = new Configuration();
	Job job = Job.getInstance(conf, "maxtemp");
	
	job.setMapperClass(MaxTempMapper.class);
	job.setReducerClass(MaxTempReducer.class);

	job.setOutputKeyClass(Text.class);
	job.setOutputValueClass(FloatWritable.class);

	FileInputFormat.setInputPaths(job, new Path(args[0]));
	FileOutputFormat.setOutputPath(job, new Path(args[1]));

	if (!job.waitForCompletion(true))
		return;
}
 
開發者ID:aadishgoel2013,項目名稱:Hadoop-Codes,代碼行數:17,代碼來源:MaxTempDriver.java

示例2: makeRandomWritables

import org.apache.hadoop.io.FloatWritable; //導入依賴的package包/類
private Writable[] makeRandomWritables() {
  Random r = new Random();
  Writable[] writs = {
    new BooleanWritable(r.nextBoolean()),
    new FloatWritable(r.nextFloat()),
    new FloatWritable(r.nextFloat()),
    new IntWritable(r.nextInt()),
    new LongWritable(r.nextLong()),
    new BytesWritable("dingo".getBytes()),
    new LongWritable(r.nextLong()),
    new IntWritable(r.nextInt()),
    new BytesWritable("yak".getBytes()),
    new IntWritable(r.nextInt())
  };
  return writs;
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:17,代碼來源:TestTupleWritable.java

示例3: testIterable

import org.apache.hadoop.io.FloatWritable; //導入依賴的package包/類
public void testIterable() throws Exception {
  Random r = new Random();
  Writable[] writs = {
    new BooleanWritable(r.nextBoolean()),
    new FloatWritable(r.nextFloat()),
    new FloatWritable(r.nextFloat()),
    new IntWritable(r.nextInt()),
    new LongWritable(r.nextLong()),
    new BytesWritable("dingo".getBytes()),
    new LongWritable(r.nextLong()),
    new IntWritable(r.nextInt()),
    new BytesWritable("yak".getBytes()),
    new IntWritable(r.nextInt())
  };
  TupleWritable t = new TupleWritable(writs);
  for (int i = 0; i < 6; ++i) {
    t.setWritten(i);
  }
  verifIter(writs, t, 0);
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:21,代碼來源:TestTupleWritable.java

示例4: testNestedIterable

import org.apache.hadoop.io.FloatWritable; //導入依賴的package包/類
public void testNestedIterable() throws Exception {
  Random r = new Random();
  Writable[] writs = {
    new BooleanWritable(r.nextBoolean()),
    new FloatWritable(r.nextFloat()),
    new FloatWritable(r.nextFloat()),
    new IntWritable(r.nextInt()),
    new LongWritable(r.nextLong()),
    new BytesWritable("dingo".getBytes()),
    new LongWritable(r.nextLong()),
    new IntWritable(r.nextInt()),
    new BytesWritable("yak".getBytes()),
    new IntWritable(r.nextInt())
  };
  TupleWritable sTuple = makeTuple(writs);
  assertTrue("Bad count", writs.length == verifIter(writs, sTuple, 0));
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:18,代碼來源:TestTupleWritable.java

示例5: testWritable

import org.apache.hadoop.io.FloatWritable; //導入依賴的package包/類
public void testWritable() throws Exception {
  Random r = new Random();
  Writable[] writs = {
    new BooleanWritable(r.nextBoolean()),
    new FloatWritable(r.nextFloat()),
    new FloatWritable(r.nextFloat()),
    new IntWritable(r.nextInt()),
    new LongWritable(r.nextLong()),
    new BytesWritable("dingo".getBytes()),
    new LongWritable(r.nextLong()),
    new IntWritable(r.nextInt()),
    new BytesWritable("yak".getBytes()),
    new IntWritable(r.nextInt())
  };
  TupleWritable sTuple = makeTuple(writs);
  ByteArrayOutputStream out = new ByteArrayOutputStream();
  sTuple.write(new DataOutputStream(out));
  ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
  TupleWritable dTuple = new TupleWritable();
  dTuple.readFields(new DataInputStream(in));
  assertTrue("Failed to write/read tuple", sTuple.equals(dTuple));
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:23,代碼來源:TestTupleWritable.java

示例6: terminate

import org.apache.hadoop.io.FloatWritable; //導入依賴的package包/類
@Override
public Object terminate(@SuppressWarnings("deprecation") AggregationBuffer agg)
        throws HiveException {
    PLSAPredictAggregationBuffer myAggr = (PLSAPredictAggregationBuffer) agg;
    float[] topicDistr = myAggr.get();

    SortedMap<Float, Integer> sortedDistr = new TreeMap<Float, Integer>(
        Collections.reverseOrder());
    for (int i = 0; i < topicDistr.length; i++) {
        sortedDistr.put(topicDistr[i], i);
    }

    List<Object[]> result = new ArrayList<Object[]>();
    for (Map.Entry<Float, Integer> e : sortedDistr.entrySet()) {
        Object[] struct = new Object[2];
        struct[0] = new IntWritable(e.getValue().intValue()); // label
        struct[1] = new FloatWritable(e.getKey().floatValue()); // probability
        result.add(struct);
    }
    return result;
}
 
開發者ID:apache,項目名稱:incubator-hivemall,代碼行數:22,代碼來源:PLSAPredictUDAF.java

示例7: testWriteFloat

import org.apache.hadoop.io.FloatWritable; //導入依賴的package包/類
@Test
public void testWriteFloat() throws Exception {
    if (!canTest()) {
        return;
    }
    float aFloat = 12.34f;
    template.sendBody("direct:write_float", aFloat);

    Configuration conf = new Configuration();
    Path file1 = new Path("file:///" + TEMP_DIR.toUri() + "/test-camel-float");
    FileSystem fs1 = FileSystem.get(file1.toUri(), conf);
    SequenceFile.Reader reader = new SequenceFile.Reader(fs1, file1, conf);
    Writable key = (Writable) ReflectionUtils.newInstance(reader.getKeyClass(), conf);
    Writable value = (Writable) ReflectionUtils.newInstance(reader.getValueClass(), conf);
    reader.next(key, value);
    float rFloat = ((FloatWritable) value).get();
    assertEquals(rFloat, aFloat, 0.0F);

    IOHelper.close(reader);
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:21,代碼來源:HdfsProducerTest.java

示例8: init

import org.apache.hadoop.io.FloatWritable; //導入依賴的package包/類
@Override
public void init() throws IOException {
  registerKey(NullWritable.class.getName(), NullWritableSerializer.class);
  registerKey(Text.class.getName(), TextSerializer.class);
  registerKey(LongWritable.class.getName(), LongWritableSerializer.class);
  registerKey(IntWritable.class.getName(), IntWritableSerializer.class);
  registerKey(Writable.class.getName(), DefaultSerializer.class);
  registerKey(BytesWritable.class.getName(), BytesWritableSerializer.class);
  registerKey(BooleanWritable.class.getName(), BoolWritableSerializer.class);
  registerKey(ByteWritable.class.getName(), ByteWritableSerializer.class);
  registerKey(FloatWritable.class.getName(), FloatWritableSerializer.class);
  registerKey(DoubleWritable.class.getName(), DoubleWritableSerializer.class);
  registerKey(VIntWritable.class.getName(), VIntWritableSerializer.class);
  registerKey(VLongWritable.class.getName(), VLongWritableSerializer.class);

  LOG.info("Hadoop platform inited");
}
 
開發者ID:aliyun-beta,項目名稱:aliyun-oss-hadoop-fs,代碼行數:18,代碼來源:HadoopPlatform.java

示例9: terminate

import org.apache.hadoop.io.FloatWritable; //導入依賴的package包/類
@Override
public Object terminate(@SuppressWarnings("deprecation") AggregationBuffer agg)
        throws HiveException {
    OnlineLDAPredictAggregationBuffer myAggr = (OnlineLDAPredictAggregationBuffer) agg;
    float[] topicDistr = myAggr.get();

    SortedMap<Float, Integer> sortedDistr = new TreeMap<Float, Integer>(
        Collections.reverseOrder());
    for (int i = 0; i < topicDistr.length; i++) {
        sortedDistr.put(topicDistr[i], i);
    }

    List<Object[]> result = new ArrayList<Object[]>();
    for (Map.Entry<Float, Integer> e : sortedDistr.entrySet()) {
        Object[] struct = new Object[2];
        struct[0] = new IntWritable(e.getValue()); // label
        struct[1] = new FloatWritable(e.getKey()); // probability
        result.add(struct);
    }
    return result;
}
 
開發者ID:apache,項目名稱:incubator-hivemall,代碼行數:22,代碼來源:LDAPredictUDAF.java

示例10: map

import org.apache.hadoop.io.FloatWritable; //導入依賴的package包/類
/**
 * Outputs the url with the appropriate number of inlinks, outlinks, or for
 * score.
 */
public void map(Text key, Node node,
    OutputCollector<FloatWritable, Text> output, Reporter reporter)
    throws IOException {

  float number = 0;
  if (inlinks) {
    number = node.getNumInlinks();
  } else if (outlinks) {
    number = node.getNumOutlinks();
  } else {
    number = node.getInlinkScore();
  }

  // number collected with negative to be descending
  output.collect(new FloatWritable(-number), key);
}
 
開發者ID:jorcox,項目名稱:GeoCrawler,代碼行數:21,代碼來源:NodeDumper.java

示例11: createPrimitive

import org.apache.hadoop.io.FloatWritable; //導入依賴的package包/類
private static Writable createPrimitive(Object obj, PrimitiveObjectInspector inspector)
        throws SerDeException {
    if (obj == null) {
        return null;
    }
    switch (inspector.getPrimitiveCategory()) {
        case DOUBLE:
            return new DoubleWritable(((DoubleObjectInspector) inspector).get(obj));
        case FLOAT:
            return new FloatWritable(((FloatObjectInspector) inspector).get(obj));
        case INT:
            return new IntWritable(((IntObjectInspector) inspector).get(obj));
        case LONG:
            return new LongWritable(((LongObjectInspector) inspector).get(obj));
        case STRING:
            return new Text(((StringObjectInspector) inspector).getPrimitiveJavaObject(obj));
        case DATE:
            return ((DateObjectInspector) inspector).getPrimitiveWritableObject(obj);
        case TIMESTAMP:
            return ((TimestampObjectInspector) inspector).getPrimitiveWritableObject(obj);
        default:
            throw new SerDeException("Can't serialize primitive : " + inspector.getPrimitiveCategory());
    }
}
 
開發者ID:shunfei,項目名稱:indexr,代碼行數:25,代碼來源:IndexRSerde.java

示例12: reduce

import org.apache.hadoop.io.FloatWritable; //導入依賴的package包/類
/**
 * Outputs either the sum or the top value for this record.
 */
public void reduce(Text key, Iterator<FloatWritable> values,
    OutputCollector<Text, FloatWritable> output, Reporter reporter)
    throws IOException {

  long numCollected = 0;
  float sumOrMax = 0;
  float val = 0;

  // collect all values, this time with the url as key
  while (values.hasNext() && (numCollected < topn)) {
    val = values.next().get();

    if (sum) {
      sumOrMax += val;
    } else {
      if (sumOrMax < val) {
        sumOrMax = val;
      }
    }

    numCollected++;
  }

  output.collect(key, new FloatWritable(sumOrMax));
}
 
開發者ID:jorcox,項目名稱:GeoCrawler,代碼行數:29,代碼來源:NodeDumper.java

示例13: merge

import org.apache.hadoop.io.FloatWritable; //導入依賴的package包/類
public boolean merge(List<FloatWritable> other) {
    if (other == null) {
        return true;
    }
    if (partial == null) {
        this.partial = new ArrayList<FloatWritable>(other);
        return true;
    }
    final int nDims = other.size();
    for (int i = 0; i < nDims; i++) {
        FloatWritable x = other.set(i, null);
        if (x != null) {
            partial.set(i, x);
        }
    }
    return true;
}
 
開發者ID:apache,項目名稱:incubator-hivemall,代碼行數:18,代碼來源:ConvertToDenseModelUDAF.java

示例14: map

import org.apache.hadoop.io.FloatWritable; //導入依賴的package包/類
public void map(Object key, Text value, Context context)
		throws IOException, InterruptedException {
	
	String line = value.toString();
	String [] a = line.split(" ");
	System.out.println(line);
	int sum=0;
	for(String i:a){
		sum += Integer.parseInt(i);
	}
	float avg = sum/a.length;
	System.out.println(avg);
	context.write(new Text("maxavg"),new FloatWritable(avg) );
	
}
 
開發者ID:aadishgoel2013,項目名稱:Hadoop-Codes,代碼行數:16,代碼來源:MaximumAverageMapper.java

示例15: reduce

import org.apache.hadoop.io.FloatWritable; //導入依賴的package包/類
public void reduce(Text key, Iterable<FloatWritable> values, Context context)
		throws IOException, InterruptedException {

	float max=0;
	for (FloatWritable val : values) {
		if(val.get()>max){
			max=val.get();
		}
		
	}
	context.write(key, new FloatWritable(max));
}
 
開發者ID:aadishgoel2013,項目名稱:Hadoop-Codes,代碼行數:13,代碼來源:MaximumAverageReducer.java


注:本文中的org.apache.hadoop.io.FloatWritable類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。