当前位置: 首页>>代码示例>>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;未经允许,请勿转载。