예제 #1
0
    @Override
    protected void setup(Context ctx) throws IOException, InterruptedException {
      try {
        Configuration conf = ctx.getConfiguration();
        Path[] localFiles = DistributedCache.getLocalCacheFiles(conf);
        Preconditions.checkArgument(
            localFiles != null && localFiles.length >= 1,
            "missing paths from the DistributedCache");

        Path inputVectorPath = HadoopUtil.getSingleCachedFile(conf);

        SequenceFileValueIterator<VectorWritable> iterator =
            new SequenceFileValueIterator<VectorWritable>(inputVectorPath, true, conf);
        try {
          inputVector = iterator.next().get();
        } finally {
          Closeables.close(iterator, true);
        }

        int outDim = conf.getInt(OUTPUT_VECTOR_DIMENSION, Integer.MAX_VALUE);
        outputVector =
            conf.getBoolean(IS_SPARSE_OUTPUT, false)
                ? new RandomAccessSparseVector(outDim, 10)
                : new DenseVector(outDim);
      } catch (IOException ioe) {
        throw new IllegalStateException(ioe);
      }
    }
예제 #2
0
 public static Vector retrieveTimesSquaredOutputVector(
     Path outputVectorTmpPath, Configuration conf) throws IOException {
   Path outputFile = new Path(outputVectorTmpPath, OUTPUT_VECTOR_FILENAME + "/part-r-00000");
   SequenceFileValueIterator<VectorWritable> iterator =
       new SequenceFileValueIterator<VectorWritable>(outputFile, true, conf);
   try {
     return iterator.next().get();
   } finally {
     Closeables.close(iterator, true);
   }
 }