本文整理汇总了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);
}
示例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.");
}
}
示例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();
}
示例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();
}
}
示例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);
}
}