当前位置: 首页>>代码示例>>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;未经允许,请勿转载。