當前位置: 首頁>>代碼示例>>Java>>正文


Java PySequence類代碼示例

本文整理匯總了Java中org.python.core.PySequence的典型用法代碼示例。如果您正苦於以下問題:Java PySequence類的具體用法?Java PySequence怎麽用?Java PySequence使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


PySequence類屬於org.python.core包,在下文中一共展示了PySequence類的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: setSlice

import org.python.core.PySequence; //導入依賴的package包/類
/**
 * Jython method to set slice within a dataset
 *
 * @param a
 *            dataset
 * @param object
 *            can an item or a dataset
 * @param indexes
 *            can be a mixed array of integers or slices
 */
public static void setSlice(Dataset a, Object object, final PyObject indexes) {
	if (a.isComplex() || a.getElementsPerItem() == 1) {
		if (object instanceof PySequence) {
			object = DatasetFactory.createFromObject(a.getDType(), object);
		}
	}

	int[] shape = a.getShape();
	SliceData slice = convertPySlicesToSlice(indexes, shape);
	a.setSlice(object, slice.slice);
}
 
開發者ID:eclipse,項目名稱:scanning,代碼行數:22,代碼來源:PythonUtils.java

示例2: getValue

import org.python.core.PySequence; //導入依賴的package包/類
private PySequence getValue() throws SyntaxException {
    try {
        return (PySequence) pythonInterpreter.eval(value);
    } catch (Exception e) {
        throw new SyntaxException("Value '" + value + "' can not be used for iteration in for loop.");
    }
}
 
開發者ID:antivo,項目名稱:Parallel-Machine-Simulator,代碼行數:8,代碼來源:Parallel.java

示例3: executeBlock

import org.python.core.PySequence; //導入依賴的package包/類
@Override
protected void executeBlock() throws SyntaxException, MemoryViolation {
    active = false;
    PySequence iterableObject = getValue();
    for (PyObject pyObject : iterableObject.asIterable()) {
        expressionReceiver.receiveIgnoreLocation(var);
        verboseComponent.info("---------------------Node with " + var + " = " + pyObject);
        setVar(pyObject);
        executeSubBlocks();
        expressionReceiver.nextNode();
    }
    jointMemory.restart();
}
 
開發者ID:antivo,項目名稱:Parallel-Machine-Simulator,代碼行數:14,代碼來源:Parallel.java

示例4: executeBlock

import org.python.core.PySequence; //導入依賴的package包/類
@Override
protected void executeBlock() throws SyntaxException, MemoryViolation {
    PySequence iterableObject = getValue();
    for (PyObject pyObject : iterableObject.asIterable()) {
        setVar(pyObject);
        executeSubBlocks();
    }
}
 
開發者ID:antivo,項目名稱:Parallel-Machine-Simulator,代碼行數:9,代碼來源:For.java

示例5: perform

import org.python.core.PySequence; //導入依賴的package包/類
/**
 * Perform the operation by calling a function in the Python script. This method adapts each of
 * the inputs into Python objects, calls the Python function, and then converts the outputs of the
 * function back into Java objects and assigns them to the outputs array. The Python function
 * should return a tuple, list, or other sequence containing the outputs.  If there is only one
 * output, it can just return a value.  Either way, the number of inputs and outputs should match
 * up with the number of parameters and return values of the function.
 */
@Override
public void perform() {
  PyObject[] pyInputs = new PyObject[inputSockets.size()];
  for (int i = 0; i < inputSockets.size(); i++) {
    pyInputs[i] = Py.java2py(inputSockets.get(i).getValue().get());
  }

  try {
    PyObject pyOutput = this.scriptFile.performFunction().__call__(pyInputs);

    if (pyOutput.isSequenceType()) {
      /*
       * If the Python function returned a sequence type, there must be multiple outputs for
       * this step.
       * Each element in the sequence is assigned to one output socket.
       */
      PySequence pySequence = (PySequence) pyOutput;
      Object[] javaOutputs = Py.tojava(pySequence, Object[].class);

      if (outputSockets.size() != javaOutputs.length) {
        throw new IllegalArgumentException(wrongNumberOfArgumentsMsg(outputSockets.size(),
            javaOutputs.length));
      }

      for (int i = 0; i < javaOutputs.length; i++) {
        outputSockets.get(i).setValue(javaOutputs[i]);
      }
    } else {
      /* If the Python script did not return a sequence, there should only be one
      output socket. */
      if (outputSockets.size() != 1) {
        throw new IllegalArgumentException(wrongNumberOfArgumentsMsg(outputSockets.size(), 1));
      }

      Object javaOutput = Py.tojava(pyOutput, outputSockets.get(0).getSocketHint().getType());
      outputSockets.get(0).setValue(javaOutput);
    }
  } catch (RuntimeException e) {
    /* Exceptions can happen if there's a mistake in a Python script, so just print a
    stack trace and leave the
     * current state of the output sockets alone.
     *
     * TODO: communicate the error to the GUI.
     */
    logger.log(Level.WARNING, e.getMessage(), e);
  }
}
 
開發者ID:WPIRoboticsProjects,項目名稱:GRIP,代碼行數:56,代碼來源:PythonScriptOperation.java


注:本文中的org.python.core.PySequence類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。