public WorkerThread[] execute(final WorkerThread worker, final int nTasks) { final MyThreadPool p = MyThreadPool.getInstance(); final int[] partition = p.partition(nTasks); final WorkerThread[] workers = new WorkerThread[partition.length - 1]; for (int i = 0; i < partition.length - 1; i++) { final WorkerThread w = worker.clone(); w.set(partition[i], partition[i + 1] - 1); workers[i] = w; p.execute(w); } await(); return workers; }
/** * Copy all files in the source directory to the target directory. * @param srcDir The source directory. * @param dstDir The target directory. * @param files The files to be copied. NOTE THAT this list contains only names (WITHOUT PATH). */ public static void copyFiles(final String srcDir, final String dstDir, final List<String> files) { for (final String file : files) { FileUtils.copyFile(srcDir + file, dstDir + file); } }
/** * Sort an integer array using Quick Sort. * @param sortVal The integer array to be sorted. * @param asc TRUE to sort ascendingly, FALSE to sort descendingly. * @return The sorted indexes. */ public static int[] sort(int[] sortVal, boolean asc) { return qSort(sortVal, asc); } /**
@Override public void setFeatureValue(int fid, float fval) { if(fid <= 0 || fid >= fVals.length) { throw RankLibError.create("Error in DenseDataPoint::setFeatureValue(): feature (id=" + fid + ") not found."); } fVals[fid] = fval; }
/** Don't rewrap RankLibErrors in RankLibErrors */ public static RankLibError create(Exception e) { if(e instanceof RankLibError) { return (RankLibError) e; } return new RankLibError(e); }
public static void init(int poolSize) { singleton = new MyThreadPool(poolSize); } public int size()
public static int[] sortString(List<String> sortVal, boolean asc) { return qSortString(sortVal, asc); } /**
public static int[] sort(float[] list, boolean asc) { return sort(list, 0, list.length-1, asc); } public static int[] sort(float[] list, int begin, int end, boolean asc)
/** * Sort an double array using Quick Sort. * @param sortVal The double array to be sorted. * @return The sorted indexes. */ public static int[] sortDesc(final List<Double> sortVal) { return qSortDouble(sortVal, false); }
public WorkerThread[] execute(WorkerThread worker, int nTasks) { MyThreadPool p = MyThreadPool.getInstance(); int[] partition = p.partition(nTasks); WorkerThread[] workers = new WorkerThread[partition.length-1]; for(int i=0;i<partition.length-1;i++) { WorkerThread w = worker.clone(); w.set(partition[i], partition[i+1]-1); workers[i] = w; p.execute(w); } await(); return workers; }
/** * Sort an integer array using Quick Sort. * @param sortVal The integer array to be sorted. * @param asc TRUE to sort ascendingly, FALSE to sort descendingly. * @return The sorted indexes. */ public static int[] sort(List<Integer> sortVal, boolean asc) { return qSort(sortVal, asc); } public static int[] sortString(List<String> sortVal, boolean asc)
public static double mean(final double[] values) { double mean = 0.0; if (values.length == 0) { throw RankLibError.create("Error in BasicStats::mean(): Empty input array."); } for (final double value : values) { mean += value; } return mean / values.length; } }
/** Don't rewrap RankLibErrors in RankLibErrors */ public static RankLibError create(final Exception e) { if (e instanceof RankLibError) { return (RankLibError) e; } return new RankLibError(e); }
/** * Copy all files in the source directory to the target directory. * @param srcDir The source directory. * @param dstDir The target directory. * @param files The files to be copied. NOTE THAT this list contains only names (WITHOUT PATH). */ public static void copyFiles(String srcDir, String dstDir, List<String> files) { for (String file : files) FileUtils.copyFile(srcDir + file, dstDir + file); } public static final int BUF_SIZE = 51200;
/** * Sort an integer array using Quick Sort. * @param sortVal The integer array to be sorted. * @param asc TRUE to sort ascendingly, FALSE to sort descendingly. * @return The sorted indexes. */ public static int[] sort(final int[] sortVal, final boolean asc) { return qSort(sortVal, asc); }
@Override public void setFeatureValue(final int fid, final float fval) { if (fid <= 0 || fid >= fVals.length) { throw RankLibError.create("Error in DenseDataPoint::setFeatureValue(): feature (id=" + fid + ") not found."); } fVals[fid] = fval; }
/** Don't rewrap RankLibErrors in RankLibErrors */ public static RankLibError create(final String message, final Exception cause) { if (cause instanceof RankLibError) { return (RankLibError) cause; } return new RankLibError(message, cause); } }
/** * Sort an integer array using Quick Sort. * @param sortVal The integer array to be sorted. * @param asc TRUE to sort ascendingly, FALSE to sort descendingly. * @return The sorted indexes. */ public static int[] sort(final List<Integer> sortVal, final boolean asc) { return qSort(sortVal, asc); }