Package com.wolfram.jlink

Examples of com.wolfram.jlink.Expr


      link.waitForAnswer();
      mapper = link.getExpr();

      link.evaluate(conf.get(MathematicaJob.MAPPER));
      link.waitForAnswer();
      Expr mapFn = link.getExpr();

      link.putFunction("Set", 2);
        link.put(mapper);
        link.put(mapFn);
      link.endPacket();
View Full Code Here


      link.waitForAnswer();
      reducer = link.getExpr();

      link.evaluate(conf.get(MathematicaJob.REDUCER));
      link.waitForAnswer();
      Expr reduceFn = link.getExpr();

      link.putFunction("Set", 2);
        link.put(reducer);
        link.put(reduceFn);
      link.endPacket();
View Full Code Here

    }
    return null;
  }

  public Expr next() throws Exception {
    Expr record;
    if (reader.next(key, value)) {
      record = new Expr(
          ExprUtil.toSymbol("List"),
          new Expr[] {
            writableToExpr(key),
            writableToExpr(value)
          });
View Full Code Here

  }

  public Object[] next(int maxRecords) throws Exception {
    ArrayList<Expr> records = new ArrayList<Expr>(maxRecords);
    for (int i = 0; i < maxRecords; i++) {
      Expr record = next();
      if (record == null) {
        if (i == 0) { return null; }
        break;
      }
      records.add(record);
View Full Code Here

   * Constructs a Symbol Expr from a string.
   * @param symbol The string to turn into a symbol.
   * @return
   */
  public static Expr toSymbol(String symbol) {
    return new Expr(Expr.SYMBOL, symbol);
  }
View Full Code Here

    return new Expr(Expr.SYMBOL, symbol);
  }

  @SuppressWarnings("unchecked")
  public static Expr toExpr(Object obj) {
    Expr expr = null;
    if (obj instanceof Buffer) {
    } else if (obj instanceof Byte) {
      expr = byteToExpr((Byte) obj);
    } else if (obj instanceof Boolean) {
      expr = booleanToExpr((Boolean) obj);
    } else if (obj instanceof Integer) {
      expr = new Expr((Integer) obj);
    } else if (obj instanceof Long) {
      expr = new Expr((Long) obj);
    } else if (obj instanceof Float) {
      expr = new Expr((Float) obj);
    } else if (obj instanceof Double) {
      expr = new Expr((Double) obj);
    } else if (obj instanceof String) {
      expr = new Expr((String) obj);
    } else if (obj instanceof ArrayList) {
      expr = listToExpr((List<Object>) obj);
    } else if (obj instanceof List) {
      expr = listToExpr((List<Object>) obj);
    } else if (obj instanceof Map) {
View Full Code Here

    }
    return expr;
  }
 
  private static Expr byteToExpr(Byte b) {
    return new Expr(b);
  }
View Full Code Here

    int length = list.size();
    Expr[] expressions = new Expr[length];
    for (int i = 0; i < length; i++) {
      expressions[i] = toExpr(list.get(i));
    }
    return new Expr(toSymbol("List"), expressions);
  }
View Full Code Here

  private static Expr mapToExpr(Map<Object, Object> map) {
    int length = map.size();
    Expr[] rules = new Expr[length];
    int i = 0;
    for (Object key : map.keySet()) {
      Expr lhs = toExpr(key);
      Expr rhs = toExpr(map.get(key));
      Expr rule = new Expr(toSymbol("Rule"),
                           new Expr[] {lhs, rhs});
      rules[i] = rule;
      i++;
    }
    return new Expr(toSymbol("List"), rules);
  }
View Full Code Here

    int[] dimensions = expr.dimensions();
    int length = dimensions[0];
    /* If every element is a Rule, it's
     * a rule list */
    for (int i = 1; i <= length; i++) {
      Expr e = expr.part(i);
      if (!e.head().equals(RULE)) {
        return false;
      }
    }
    return true;
  }
View Full Code Here

TOP

Related Classes of com.wolfram.jlink.Expr

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.