Example usage for java.lang Math ceil

List of usage examples for java.lang Math ceil

Introduction

In this page you can find the example usage for java.lang Math ceil.

Prototype

public static double ceil(double a) 

Source Link

Document

Returns the smallest (closest to negative infinity) double value that is greater than or equal to the argument and is equal to a mathematical integer.

Usage

From source file:net.sf.dsp4j.octave.packages.signal_1_2_0.Cheb2Ord.java

private void calcCheb2Ord(double[] Wp, double[] Ws, double Rp, double Rs) {
    double T = 2;

    // returned frequency is the same as the input frequency
    Wc = Arrays.copyOf(Ws, Ws.length);

    // warp the target frequencies according to the bilinear transform
    for (int i = 0; i < Wp.length; i++) {
        Ws[i] = 2.0 / T * Math.tan(Math.PI * Ws[i] / T);
        Wp[i] = 2.0 / T * Math.tan(Math.PI * Wp[i] / T);
    }/*from www.j  av a 2 s  .  c o m*/
    double Wa;

    if (Wp[0] < Ws[0]) {
        // low pass
        if (Wp.length == 1) {
            Wa = Wp[0] / Ws[0];
        } else {
            // band reject
            throw new RuntimeException("band reject is not implement yet.");
        }
    } else {
        // if high pass, reverse the sense of the test
        if (Wp.length == 1) {
            Wa = Ws[0] / Wp[0];
        } else {
            // band pass 
            Wa = Double.MAX_VALUE;
            for (int i = 0; i < Wp.length; i++) {
                Wa = Math.min(Wa, Math.abs((Math.pow(Wp[i], 2) - Ws[0] * Ws[1]) / (Wp[i] * (Ws[0] - Ws[1]))));
            }
        }
    }

    // compute minimum n which satisfies all band edge conditions
    final double stop_atten = Math.pow(10, Math.abs(Rs) / 10.0);
    final double pass_atten = Math.pow(10, Math.abs(Rp) / 10.0);
    n = (int) Math.ceil(
            FastMath.acosh(Math.sqrt((stop_atten - 1.0) / (pass_atten - 1.0))) / FastMath.acosh(1.0 / Wa));

}

From source file:com.microsoft.tfs.core.clients.workitem.internal.files.AttachmentUpDownHelper.java

private static int computeTaskSize(final long responseContentLength) {
    return (int) Math.ceil(((double) responseContentLength) / DOWNLOAD_BUFFER_SIZE);
}

From source file:com.ultrapower.eoms.common.plugin.ecside.view.html.FormBuilder.java

public void hiddenTotalField(){
    int currentRowsDisplayed = getTableModel().getLimit().getCurrentRowsDisplayed();
   int totalPages = 0;
  int totalRows = getTableModel().getLimit().getTotalRows();
  if (currentRowsDisplayed > 0) {
     totalPages =(int)Math.ceil((double)totalRows / currentRowsDisplayed);
  } else {/*from  w  ww . j  a v  a 2 s. co m*/
     totalPages = 1;
  }
   html.newline();
  html.input("hidden").name(model.getTableHandler().prefixWithTableId() +TableConstants.HIDDEN_TOTAL_PAGES).value(""+totalPages).xclose();
   html.newline();
  html.input("hidden").name(model.getTableHandler().prefixWithTableId() +TableConstants.HIDDEN_TOTAL_ROWS).value(""+totalRows).xclose();

}

From source file:edu.stanford.cfuller.imageanalysistools.filter.ConvolutionFilter.java

public static Complex[][] transform(Image im, int z) {

    FastFourierTransformer fft = new org.apache.commons.math3.transform.FastFourierTransformer(
            org.apache.commons.math3.transform.DftNormalization.STANDARD);

    int ydimPowOfTwo = im.getDimensionSizes().get(ImageCoordinate.Y);
    int xdimPowOfTwo = im.getDimensionSizes().get(ImageCoordinate.X);

    if (!org.apache.commons.math3.util.ArithmeticUtils.isPowerOfTwo(ydimPowOfTwo)
            || !org.apache.commons.math3.util.ArithmeticUtils.isPowerOfTwo(xdimPowOfTwo)) {

        xdimPowOfTwo = (int) Math.pow(2,
                Math.ceil(Math.log(im.getDimensionSizes().get(ImageCoordinate.X)) / Math.log(2)));
        ydimPowOfTwo = (int) Math.pow(2,
                Math.ceil(Math.log(im.getDimensionSizes().get(ImageCoordinate.Y)) / Math.log(2)));
    }//www  .  ja v  a  2 s .co m

    int p = z;

    im.selectPlane(p);

    double[][] rowImage = new double[ydimPowOfTwo][xdimPowOfTwo];
    for (int i = 0; i < ydimPowOfTwo; i++) {
        java.util.Arrays.fill(rowImage[i], 0); // ensures zero-padding
    }
    Complex[][] colMajorImage = new Complex[xdimPowOfTwo][ydimPowOfTwo];

    for (ImageCoordinate ic : im) {
        rowImage[ic.get(ImageCoordinate.Y)][ic.get(ImageCoordinate.X)] = im.getValue(ic);
    }

    for (int r = 0; r < rowImage.length; r++) {
        double[] row = rowImage[r];
        Complex[] transformedRow = fft.transform(row, org.apache.commons.math3.transform.TransformType.FORWARD);

        for (int c = 0; c < colMajorImage.length; c++) {
            colMajorImage[c][r] = transformedRow[c];
        }
    }

    for (int c = 0; c < colMajorImage.length; c++) {
        colMajorImage[c] = fft.transform(colMajorImage[c],
                org.apache.commons.math3.transform.TransformType.FORWARD);
    }
    return colMajorImage;

}

From source file:net.sf.dsp4j.octave.packages.signal_1_2_0.Cheb1Ord.java

private void calcCheb1Ord(double[] Wp, double[] Ws, double Rp, double Rs) {

    double T = 2;

    // returned frequency is the same as the input frequency
    Wc = Arrays.copyOf(Wp, Wp.length);

    // warp the target frequencies according to the bilinear transform
    for (int i = 0; i < Wp.length; i++) {
        Ws[i] = 2.0 / T * Math.tan(Math.PI * Ws[i] / T);
        Wp[i] = 2.0 / T * Math.tan(Math.PI * Wp[i] / T);
    }/*w w w . ja v a  2 s  . c  o  m*/
    double Wa;
    if (Wp[0] < Ws[0]) // low pass
    {
        if (Wp.length == 1) {
            Wa = Ws[0] / Wp[0];
        } else {
            // band reject
            throw new RuntimeException("band reject is not implement yet.");
        }
    } else {
        // if high pass, reverse the sense of the test
        if (Wp.length == 1) {
            Wa = Wp[0] / Ws[0];
        } else {
            // band pass
            Wa = Double.MAX_VALUE;
            for (int i = 0; i < Wp.length; i++) {
                Wa = Math.min(Wa, Math.abs((Math.pow(Ws[i], 2) - Wp[0] * Wp[1]) / (Ws[i] * (Wp[0] - Wp[1]))));
            }
        }
    }

    // compute minimum n which satisfies all band edge conditions
    final double stop_atten = Math.pow(10, Math.abs(Rs) / 10.0);
    final double pass_atten = Math.pow(10, Math.abs(Rp) / 10.0);
    n = (int) Math
            .ceil(FastMath.acosh(Math.sqrt((stop_atten - 1.0) / (pass_atten - 1.0))) / FastMath.acosh(Wa));

}

From source file:it.polimi.diceH2020.SPACE4Cloud.shared.solution.SolutionPerJob.java

public void setNumberContainers(int numberContainers) {
    if (this.numberContainers == null || this.numberContainers.intValue() != numberContainers) {
        changed = true;//  ww w.j  a  v a2s . c o  m
    }
    this.numberContainers = numberContainers;
    // update num of vm
    if (xi != null) {
        this.numberVM = (int) Math.ceil((double) this.numberContainers / xi);
    } else {
        return;
    }
    if (typeVMselected != null && typeVMselected.getEta() >= 0) {
        this.numSpotVM = (int) Math.floor(typeVMselected.getEta() * this.numberVM);
        this.numReservedVM = (int) Math.min(typeVMselected.getR(), (this.numberVM - numSpotVM));
        this.numOnDemandVM = Math.max(0, this.numberVM - numSpotVM - numReservedVM);
    }
}

From source file:com.poscoict.license.service.MorgueService.java

public Map<String, Object> getBoardList(String boardId, String chartNum, String search, String select) {
    Map<String, Object> map = new HashMap<String, Object>();

    int pageList = 14; // ? 14 
    int totalCount = 0;
    int totalPage = 0;

    int start = (Integer.parseInt(chartNum) == 1) ? 0 : (Integer.parseInt(chartNum) - 1) * pageList;
    List<Map<String, Object>> list = null;

    if ((search == null) || (search == "")) { // ?
        totalCount = morgueDao.getBoardCount(boardId);
        totalPage = (int) Math.ceil((double) totalCount / pageList); // ? ? 
        list = morgueDao.getCustomBoardList(boardId, start, pageList);
    } else {//from w  w w  . j  a v a2 s .co  m
        totalCount = morgueDao.getSearchCount(boardId, search, select);
        totalPage = (int) Math.ceil((double) totalCount / pageList); // ? ? 
        list = morgueDao.getBoardSearch(boardId, search, select, start, pageList);
    }

    map.put("list", list);
    map.put("totalPage", totalPage);
    map.put("boardName", morgueDao.getCustomBoardName(boardId));

    return map;
}

From source file:eu.larkc.RDFPig.optimizers.strategies.SamplePruneOptimizationStrategy.java

@Override
public void prune(ArrayList<Set<TupleCostPair>> searchSpace, Executor executor, CostCalculator calculator) {

    // Only sample up to MAXSAMPLINGCYCLES steps
    int maxSamplingCycles = Configuration.getInstance().getPropertyInt(Configuration.MAXSAMPLINGCYCLES);
    if (searchSpace.size() > maxSamplingCycles) {
        return;/*w w  w  . java 2 s.c o m*/
    }

    logger.info("Calling SamplePrune for cycle: " + searchSpace.size());

    // Sort last calculated expressions by cost
    Set<TupleCostPair> currentLevel = searchSpace.get(searchSpace.size() - 1);

    if (currentLevel.isEmpty()) {
        logger.warn("Empty current level, searchSpace sizes: ");
        for (Set<TupleCostPair> s : searchSpace) {
            logger.warn(Integer.toString(s.size()));
        }
        return;
    }

    List<TupleCostPair> sortedByCost = new ArrayList<TupleCostPair>(currentLevel);
    Collections.sort(sortedByCost, new Comparator<TupleCostPair>() {
        @Override
        public int compare(TupleCostPair o1, TupleCostPair o2) {
            if (o1.cost == o2.cost)
                return 0;
            else
                return o1.cost > o2.cost ? 1 : -1;
        }
    });

    // TODO adapt pruning to stddev?

    // Prune the bottom part
    double staticPruneRatio = Configuration.getInstance()
            .getPropertyDouble(Configuration.DYNAMICPROGRAMMINGSTATICPRUNEBEFORE);
    int staticPruneIndex = (int) Math.ceil(sortedByCost.size() / staticPruneRatio);
    if (staticPruneIndex == sortedByCost.size())
        staticPruneIndex--;
    sortedByCost = sortedByCost.subList(0, staticPruneIndex);

    // Sample the remaining ones
    Set<TupleExpr> candidates = new HashSet<TupleExpr>();
    for (TupleCostPair t : sortedByCost) {
        candidates.add(t.tuple);
    }
    try {
        executor.execute(candidates, Configuration.getInstance().getPropertyDouble(Configuration.SAMPLE_RATE));
    } catch (Exception e) {
        throw new RuntimeException("Could not sample", e);
    }

    // Update costs and remove the unsampled ones from the search space
    Iterator<TupleCostPair> it = currentLevel.iterator();
    while (it.hasNext()) {
        TupleCostPair c = it.next();
        if (candidates.contains(c.tuple))
            c.cost = calculator.getCost(c.tuple);
        else
            it.remove();
    }

    logger.info("Sample-Prune done for level " + (searchSpace.size() - 1) + " current level size = "
            + currentLevel.size());

}

From source file:com.microsoft.azure.management.datalake.store.uploader.UploadMetadata.java

/**
 * Constructs a new UploadMetadata from the given parameters.
 *
 * @param metadataFilePath The file path to assign to this metadata file (for saving purposes).
 * @param uploadParameters The parameters to use for constructing this metadata.
 *///w w  w.  j a  va2s .  co  m
public UploadMetadata(String metadataFilePath, UploadParameters uploadParameters) {
    this.metadataFilePath = metadataFilePath;

    this.uploadId = UUID.randomUUID().toString();
    this.inputFilePath = uploadParameters.getInputFilePath();
    this.targetStreamPath = uploadParameters.getTargetStreamPath();

    String[] streamData = splitTargetStreamPathByName();
    String streamName = streamData[0];
    String streamDirectory = streamData[1];

    if (streamDirectory == null || StringUtils.isEmpty(streamDirectory)) {
        // the scenario where the file is being uploaded at the root
        this.segmentStreamDirectory = MessageFormat.format("/{0}.segments.{1}", streamName, UUID.randomUUID());
    } else {
        // the scenario where the file is being uploaded in a sub folder
        this.segmentStreamDirectory = MessageFormat.format("{0}/{1}.segments.{2}", streamDirectory, streamName,
                UUID.randomUUID());
    }

    this.isBinary = uploadParameters.isBinary();

    File fileInfo = new File(uploadParameters.getInputFilePath());
    this.fileLength = fileInfo.length();

    this.encodingName = uploadParameters.getFileEncoding().name();

    // we are taking the smaller number of segments between segment lengths of 256 and the segment growth logic.
    // this protects us against agressive increase of thread count resulting in far more segments than
    // is reasonable for a given file size. We also ensure that each segment is at least 256mb in size.
    // This is the size that ensures we have the optimal storage creation in the store.
    int preliminarySegmentCount = (int) Math
            .ceil((double) fileInfo.length() / uploadParameters.getMaxSegementLength());
    this.segmentCount = Math.min(preliminarySegmentCount,
            UploadSegmentMetadata.calculateSegmentCount(fileInfo.length()));
    this.segmentLength = UploadSegmentMetadata.calculateSegmentLength(fileInfo.length(), this.segmentCount);

    this.segments = new UploadSegmentMetadata[this.segmentCount];
    for (int i = 0; i < this.segmentCount; i++) {
        this.segments[i] = new UploadSegmentMetadata(i, this);
    }
}

From source file:com.ibm.bi.dml.runtime.matrix.data.LibMatrixDatagen.java

/**
 * /*from   www  .  jav a  2  s .  c  o  m*/
 * @param nrow
 * @param ncol
 * @param brlen
 * @param bclen
 * @param sparsity
 * @return
 * @throws DMLRuntimeException
 */
public static long[] computeNNZperBlock(long nrow, long ncol, int brlen, int bclen, double sparsity)
        throws DMLRuntimeException {
    int numBlocks = (int) (Math.ceil((double) nrow / brlen) * Math.ceil((double) ncol / bclen));
    //System.out.println("nrow=" + nrow + ", brlen=" + brlen + ", ncol="+ncol+", bclen=" + bclen + "::: " + Math.ceil(nrow/brlen));

    // CURRENT: 
    //       Total #of NNZ is set to the expected value (nrow*ncol*sparsity).
    // TODO: 
    //      Instead of using the expected value, one should actually 
    //       treat NNZ as a random variable and accordingly generate a random value.
    long nnz = (long) Math.ceil(nrow * (ncol * sparsity));
    //System.out.println("Number of blocks = " + numBlocks + "; NNZ = " + nnz);

    if (numBlocks > Integer.MAX_VALUE) {
        throw new DMLRuntimeException(
                "A random matrix of size [" + nrow + "," + ncol + "] can not be created. Number of blocks ("
                        + numBlocks + ") exceeds the maximum integer size. Try to increase the block size.");
    }

    // Compute block-level NNZ
    long[] ret = new long[numBlocks];
    Arrays.fill(ret, 0);

    if (nnz < numBlocks) {
        // Ultra-sparse matrix

        // generate the number of blocks with at least one non-zero
        // = a random number between [1,nnz]
        Random runif = new Random(System.nanoTime());
        int numNZBlocks = 1;
        if (nnz - 1 > 0)
            numNZBlocks += runif.nextInt((int) (nnz - 1)); // To avoid exception from random.nextInt(0) 

        // distribute non-zeros across numNZBlocks

        // compute proportions for each nzblock 
        // - divide (0,1] interval into numNZBlocks portions of random size
        double[] blockNNZproportions = new double[numNZBlocks];

        runif.setSeed(System.nanoTime());
        for (int i = 0; i < numNZBlocks - 1; i++) {
            blockNNZproportions[i] = runif.nextDouble();
        }
        blockNNZproportions[numNZBlocks - 1] = 1;
        // sort the values in ascending order
        Arrays.sort(blockNNZproportions);

        // compute actual number of non zeros per block according to proportions
        long actualnnz = 0;
        int bid;
        runif.setSeed(System.nanoTime());
        for (int i = 0; i < numNZBlocks; i++) {
            bid = -1;
            do {
                bid = runif.nextInt(numBlocks);
            } while (ret[bid] != 0);

            double prop = (i == 0 ? blockNNZproportions[i]
                    : (blockNNZproportions[i] - blockNNZproportions[i - 1]));
            ret[bid] = (long) Math.floor(prop * nnz);
            actualnnz += ret[bid];
        }

        // Code to make sure exact number of non-zeros are generated
        while (actualnnz < nnz) {
            bid = runif.nextInt(numBlocks);
            ret[bid]++;
            actualnnz++;
        }
    } else {
        int bid = 0;

        //long actualnnz = 0;
        for (long r = 0; r < nrow; r += brlen) {
            long curBlockRowSize = Math.min(brlen, (nrow - r));
            for (long c = 0; c < ncol; c += bclen) {
                long curBlockColSize = Math.min(bclen, (ncol - c));
                ret[bid] = (long) (curBlockRowSize * curBlockColSize * sparsity);
                //actualnnz += ret[bid];
                bid++;
            }
        }
    }
    return ret;
}