コード例 #1
0
  public Dimensions calcDim(Dimensions[] dims) throws ParseException {
    int len = dims.length;
    if (len == 0) throw new ParseException("ElementMultiply called with 0 arguments");
    if (len == 1) return dims[0];

    Dimensions firstDim = dims[0];
    for (int i = 1; i < len; ++i)
      if (!firstDim.equals(dims[i]))
        throw new ParseException("ElementMultiply: dimensions of each argument should be the same");

    return firstDim;
  }
コード例 #2
0
ファイル: JepMatrix.java プロジェクト: liuhb86/ppmc
  public static MatrixNodeI multiply(MatrixNodeI m1, MatrixNodeI m2) {
    assert (m1.getDim().is2D());
    assert (m2.getDim().is2D());
    assert (m1.getDim().getLastDim() == m2.getDim().getFirstDim());
    int m = m1.getDim().getFirstDim();
    int n = m1.getDim().getLastDim();
    int p = m2.getDim().getLastDim();
    Node[] entry = new Node[m * p];
    int index = 0;
    try {
      for (int i = 0; i < m; ++i) {
        for (int j = 0; j < p; ++j) {
          Node node = zero;

          for (int k = 0; k < n; ++k) {
            Node item = factory.buildOperatorNode(op.getMultiply(), get(m1, i, k), get(m2, k, j));
            node = factory.buildOperatorNode(op.getAdd(), node, item);
          }
          entry[index] = simplifier.simplify(node);
          ++index;
        }
      }
    } catch (ParseException e) {
    }
    return (MatrixNodeI) factory.buildOperatorNode(op.getMList(), entry, Dimensions.valueOf(m, p));
  }