当前位置: 首页>>代码示例>>Java>>正文


Java DenseVector类代码示例

本文整理汇总了Java中no.uib.cipr.matrix.DenseVector的典型用法代码示例。如果您正苦于以下问题:Java DenseVector类的具体用法?Java DenseVector怎么用?Java DenseVector使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


DenseVector类属于no.uib.cipr.matrix包,在下文中一共展示了DenseVector类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: ILUT

import no.uib.cipr.matrix.DenseVector; //导入依赖的package包/类
/**
 * Sets up the preconditioner for the given matrix
 * 
 * @param LU
 *            Matrix to use internally. For best performance, its non-zero
 *            pattern should conform to that of the system matrix
 * @param tau
 *            Drop tolerance
 * @param p
 *            Number of entries to keep on each row in of the factored
 *            matrix. This is in addition to the entries of the original
 *            matrix
 */
public ILUT(FlexCompRowMatrix LU, double tau, int p) {
    if (!LU.isSquare())
        throw new IllegalArgumentException(
                "ILU only applies to square matrices");

    this.LU = LU;
    this.tau = tau;
    this.p = p;

    int n = LU.numRows();
    lower = new ArrayList<IntDoubleEntry>(n);
    upper = new ArrayList<IntDoubleEntry>(n);
    y = new DenseVector(n);
    diagind = new int[n];
}
 
开发者ID:opprop-benchmarks,项目名称:matrix-toolkits-java,代码行数:29,代码来源:ILUT.java

示例2: solve

import no.uib.cipr.matrix.DenseVector; //导入依赖的package包/类
@Override
public Vector solve(Vector b, Vector x) {
    if (!(b instanceof DenseVector) || !(x instanceof DenseVector))
        return super.solve(b, x);

    double[] bd = ((DenseVector) b).getData();
    double[] xd = ((DenseVector) x).getData();

    for (int i = 0; i < numRows; ++i) {

        // Get row i
        SparseVector row = LU.getRow(i);
        int[] index = row.getIndex();
        double[] data = row.getData();

        // xi = bi - sum[j<i] Lij * xj
        double sum = 0;
        for (int j = 0; j < diagind[i]; ++j)
            sum += data[j] * xd[index[j]];

        xd[i] = bd[i] - sum;
    }

    return x;
}
 
开发者ID:opprop-benchmarks,项目名称:matrix-toolkits-java,代码行数:26,代码来源:ILUT.java

示例3: transSolve

import no.uib.cipr.matrix.DenseVector; //导入依赖的package包/类
@Override
public Vector transSolve(Vector b, Vector x) {
    if (!(x instanceof DenseVector))
        return super.transSolve(b, x);

    x.set(b);

    double[] xd = ((DenseVector) x).getData();

    for (int i = numRows - 1; i >= 0; --i) {

        // Get row i
        SparseVector row = LU.getRow(i);
        int[] index = row.getIndex();
        double[] data = row.getData();

        // At this stage, x[i] is known, so move it over to the right
        // hand side for the remaining equations
        for (int j = 0; j < diagind[i]; ++j)
            xd[index[j]] -= data[j] * xd[i];

    }

    return x;
}
 
开发者ID:opprop-benchmarks,项目名称:matrix-toolkits-java,代码行数:26,代码来源:ILUT.java

示例4: solve

import no.uib.cipr.matrix.DenseVector; //导入依赖的package包/类
@Override
public Vector solve(Vector b, Vector x) {
    if (!(b instanceof DenseVector) || !(x instanceof DenseVector))
        return super.solve(b, x);

    double[] bd = ((DenseVector) b).getData();
    double[] xd = ((DenseVector) x).getData();

    for (int i = 0; i < numRows; ++i) {

        // xi = bi - sum[j<i] Lij * xj
        double sum = 0;
        for (int j = rowptr[i]; j < diagind[i]; ++j)
            sum += data[j] * xd[colind[j]];

        xd[i] = bd[i] - sum;
    }

    return x;
}
 
开发者ID:opprop-benchmarks,项目名称:matrix-toolkits-java,代码行数:21,代码来源:UnitLowerCompRowMatrix.java

示例5: transSolve

import no.uib.cipr.matrix.DenseVector; //导入依赖的package包/类
@Override
public Vector transSolve(Vector b, Vector x) {
    if (!(x instanceof DenseVector))
        return super.transSolve(b, x);

    x.set(b);

    double[] xd = ((DenseVector) x).getData();

    for (int i = numRows - 1; i >= 0; --i)

        // At this stage, x[i] is known, so move it over to the right hand
        // side for the remaining equations
        for (int j = rowptr[i]; j < diagind[i]; ++j)
            xd[colind[j]] -= data[j] * xd[i];

    return x;
}
 
开发者ID:opprop-benchmarks,项目名称:matrix-toolkits-java,代码行数:19,代码来源:UnitLowerCompRowMatrix.java

示例6: transMultAdd

import no.uib.cipr.matrix.DenseVector; //导入依赖的package包/类
@Override
public Vector transMultAdd(double alpha, Vector x, Vector y) {
    if (!(x instanceof DenseVector) || !(y instanceof DenseVector))
        return super.transMultAdd(alpha, x, y);

    checkTransMultAdd(x, y);

    double[] xd = ((DenseVector) x).getData(), yd = ((DenseVector) y)
            .getData();

    // y = 1/alpha * y
    y.scale(1. / alpha);

    // y = A'x + y
    for (int i = 0; i < numRows; ++i) {
        SparseVector v = rowD[i];
        int[] index = v.getIndex();
        double[] data = v.getData();
        int length = v.getUsed();
        for (int j = 0; j < length; ++j)
            yd[index[j]] += data[j] * xd[i];
    }

    // y = alpha*y = alpha * A'x + y
    return y.scale(alpha);
}
 
开发者ID:opprop-benchmarks,项目名称:matrix-toolkits-java,代码行数:27,代码来源:FlexCompRowMatrix.java

示例7: multAdd

import no.uib.cipr.matrix.DenseVector; //导入依赖的package包/类
@Override
public Vector multAdd(double alpha, Vector x, Vector y) {
    if (!(x instanceof DenseVector) || !(y instanceof DenseVector))
        return super.multAdd(alpha, x, y);

    checkMultAdd(x, y);

    double[] xd = ((DenseVector) x).getData(), yd = ((DenseVector) y)
            .getData();

    // y = 1/alpha * y
    y.scale(1 / alpha);

    // y = A*x + y
    for (int i = 0; i < numColumns; ++i)
        for (int j = columnPointer[i]; j < columnPointer[i + 1]; ++j)
            yd[rowIndex[j]] += data[j] * xd[i];

    // y = alpha*y = alpha*A*x + y
    return y.scale(alpha);
}
 
开发者ID:opprop-benchmarks,项目名称:matrix-toolkits-java,代码行数:22,代码来源:CompColMatrix.java

示例8: transMult

import no.uib.cipr.matrix.DenseVector; //导入依赖的package包/类
@Override
public Vector transMult(Vector x, Vector y) {
    if (!(x instanceof DenseVector) || !(y instanceof DenseVector))
        return super.transMult(x, y);

    checkTransMultAdd(x, y);

    double[] xd = ((DenseVector) x).getData();
    double[] yd = ((DenseVector) y).getData();

    for (int i = 0; i < numColumns; ++i) {
        double dot = 0;
        for (int j = columnPointer[i]; j < columnPointer[i + 1]; ++j)
            dot += data[j] * xd[rowIndex[j]];
        yd[i] = dot;
    }

    return y;
}
 
开发者ID:opprop-benchmarks,项目名称:matrix-toolkits-java,代码行数:20,代码来源:CompColMatrix.java

示例9: transMultAdd

import no.uib.cipr.matrix.DenseVector; //导入依赖的package包/类
@Override
public Vector transMultAdd(double alpha, Vector x, Vector y) {
    if (!(x instanceof DenseVector) || !(y instanceof DenseVector))
        return super.transMultAdd(alpha, x, y);

    checkTransMultAdd(x, y);

    double[] xd = ((DenseVector) x).getData();
    double[] yd = ((DenseVector) y).getData();

    for (int i = 0; i < numColumns; ++i) {
        double dot = 0;
        for (int j = columnPointer[i]; j < columnPointer[i + 1]; ++j)
            dot += data[j] * xd[rowIndex[j]];
        yd[i] += alpha * dot;
    }

    return y;
}
 
开发者ID:opprop-benchmarks,项目名称:matrix-toolkits-java,代码行数:20,代码来源:CompColMatrix.java

示例10: solve

import no.uib.cipr.matrix.DenseVector; //导入依赖的package包/类
@Override
public Vector solve(Vector b, Vector x) {
    if (!(b instanceof DenseVector) || !(x instanceof DenseVector))
        return super.solve(b, x);

    double[] bd = ((DenseVector) b).getData();
    double[] xd = ((DenseVector) x).getData();

    for (int i = numRows - 1; i >= 0; --i) {

        // xi = (bi - sum[j>i] Uij * xj) / Uii
        double sum = 0;
        for (int j = diagind[i] + 1; j < rowptr[i + 1]; ++j)
            sum += data[j] * xd[colind[j]];

        xd[i] = (bd[i] - sum) / data[diagind[i]];
    }

    return x;
}
 
开发者ID:opprop-benchmarks,项目名称:matrix-toolkits-java,代码行数:21,代码来源:UpperCompRowMatrix.java

示例11: transSolve

import no.uib.cipr.matrix.DenseVector; //导入依赖的package包/类
@Override
public Vector transSolve(Vector b, Vector x) {
    if (!(x instanceof DenseVector))
        return super.transSolve(b, x);

    x.set(b);

    double[] xd = ((DenseVector) x).getData();

    for (int i = 0; i < numRows; ++i) {

        // Solve for the current entry
        xd[i] /= data[diagind[i]];

        // Move this known solution over to the right hand side for the
        // remaining equations
        for (int j = diagind[i] + 1; j < rowptr[i + 1]; ++j)
            xd[colind[j]] -= data[j] * xd[i];
    }

    return x;
}
 
开发者ID:opprop-benchmarks,项目名称:matrix-toolkits-java,代码行数:23,代码来源:UpperCompRowMatrix.java

示例12: mult

import no.uib.cipr.matrix.DenseVector; //导入依赖的package包/类
@Override
public Vector mult(Vector x, Vector y) {
    if (!(x instanceof DenseVector) || !(y instanceof DenseVector))
        return super.mult(x, y);

    checkMultAdd(x, y);

    double[] xd = ((DenseVector) x).getData();
    double[] yd = ((DenseVector) y).getData();

    y.zero();

    for (int i = 0; i < ind.length; ++i) {
        int row = ind[i] < 0 ? -ind[i] : 0;
        int column = ind[i] > 0 ? ind[i] : 0;
        double[] locDiag = diag[i];
        for (int j = 0; j < locDiag.length; ++j, ++row, ++column)
            yd[row] += locDiag[j] * xd[column];
    }

    return y;
}
 
开发者ID:opprop-benchmarks,项目名称:matrix-toolkits-java,代码行数:23,代码来源:CompDiagMatrix.java

示例13: multAdd

import no.uib.cipr.matrix.DenseVector; //导入依赖的package包/类
@Override
public Vector multAdd(double alpha, Vector x, Vector y) {
    if (!(x instanceof DenseVector) || !(y instanceof DenseVector))
        return super.multAdd(alpha, x, y);

    checkMultAdd(x, y);

    double[] xd = ((DenseVector) x).getData();
    double[] yd = ((DenseVector) y).getData();

    for (int i = 0; i < ind.length; ++i) {
        int row = ind[i] < 0 ? -ind[i] : 0;
        int column = ind[i] > 0 ? ind[i] : 0;
        double[] locDiag = diag[i];
        for (int j = 0; j < locDiag.length; ++j, ++row, ++column)
            yd[row] += alpha * locDiag[j] * xd[column];
    }

    return y;
}
 
开发者ID:opprop-benchmarks,项目名称:matrix-toolkits-java,代码行数:21,代码来源:CompDiagMatrix.java

示例14: transMultAdd

import no.uib.cipr.matrix.DenseVector; //导入依赖的package包/类
@Override
public Vector transMultAdd(double alpha, Vector x, Vector y) {
    if (!(x instanceof DenseVector) || !(y instanceof DenseVector))
        return super.transMultAdd(alpha, x, y);

    checkTransMultAdd(x, y);

    double[] xd = ((DenseVector) x).getData();
    double[] yd = ((DenseVector) y).getData();

    for (int i = 0; i < ind.length; ++i) {
        int row = ind[i] < 0 ? -ind[i] : 0;
        int column = ind[i] > 0 ? ind[i] : 0;
        double[] locDiag = diag[i];
        for (int j = 0; j < locDiag.length; ++j, ++row, ++column)
            yd[column] += alpha * locDiag[j] * xd[row];
    }

    return y;
}
 
开发者ID:opprop-benchmarks,项目名称:matrix-toolkits-java,代码行数:21,代码来源:CompDiagMatrix.java

示例15: multAdd

import no.uib.cipr.matrix.DenseVector; //导入依赖的package包/类
@Override
public Vector multAdd(double alpha, Vector x, Vector y) {
    if (!(x instanceof DenseVector) || !(y instanceof DenseVector))
        return super.multAdd(alpha, x, y);

    checkMultAdd(x, y);

    double[] xd = ((DenseVector) x).getData();
    double[] yd = ((DenseVector) y).getData();

    // y = 1/alpha * y
    y.scale(1. / alpha);

    // y = A*x + y
    for (int i = 0; i < numColumns; ++i) {
        SparseVector v = colD[i];
        int[] index = v.getIndex();
        double[] data = v.getData();
        int length = v.getUsed();
        for (int j = 0; j < length; ++j)
            yd[index[j]] += data[j] * xd[i];
    }

    // y = alpha*y = alpha * A'x + y
    return y.scale(alpha);
}
 
开发者ID:opprop-benchmarks,项目名称:matrix-toolkits-java,代码行数:27,代码来源:FlexCompColMatrix.java


注:本文中的no.uib.cipr.matrix.DenseVector类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。