Multiple-Output Examples#

This file contains example usage for AutoNode functions that have more than one output. For access to the other types of examples see AutoNode Examples.

Multiple Simple Outputs#

import statistics as st

import numpy as np
import omni.graph.core as og
import omni.graph.core.types as ot

@og.create_node_type
def autonode_multi_simple(values: ot.floatarray) -> tuple[ot.float, ot.float, ot.float]:
    """Takes in a list of floating point values and returns three outputs that are the mean, median,
    and mode of the values in the list. The outputs will be named "out_0", "out_1", and "out_2".
    """
    return (values.mean(), np.median(values), st.mode(values))

Multiple Tuple Outputs#

import numpy as np
import omni.graph.core as og
import omni.graph.core.types as ot

@og.create_node_type
def autonode_multi_tuple(original: ot.matrix2d) -> tuple[ot.matrix2d, ot.matrix2d]:
    """Takes in a 2x2 matrix and returns two outputs that are the inverse and transpose of the matrix.
    Reports an error if the matrix is not invertible. Note that even though the data types themselves
    are tuples the return values will be correctly interpreted as being separate output attributes
    with each of the outputs itself being a tuple value. The outputs will be named "out_1" and "out_2".
    """
    try:
        return (original.transpose(), np.linalg.inv(original))
    except np.linalg.LinAlgError as error:
        raise og.OmniGraphError(f"Could not invert matrix {original}") from error