ExternalFunction

Listing of External Evaluators »

ExternalFunction[sys,"f"]

represents an external function named "f" defined in the external evaluator sys.

ExternalFunction[session,"f"]

represents an external function "f" in the specified ExternalSessionObject.

ExternalFunction[sys,"code"]

represents an external function defined by the code fragment "code".

ExternalFunction[obj,"method"]

represents a method bound to the ExternalObject.

Details

Examples

open allclose all

Basic Examples  (3)

Create an external function using the absolute value function in Python:

Compute the absolute value of with the external Python function:

Start a new session:

Define a new function:

Use the function:

Close the session:

Start a new session:

Return an object for a Python module:

Run a method from the module, using ExternalFunction:

Close the session:

Scope  (6)

Define a lambda function in Python:

Use this Python function in the Wolfram Language:

Use a Python built-in function:

Use the external function to convert a string to a list:

Start a session:

Define a function using complex numbers:

Compute the argument of a complex number via the Python phase function:

Close the session:

Start a NodeJS session:

In NodeJS, it is not enough to just define a functionyou have to explicitly return the function for ExternalFunction to recognize it as a callable function:

Call the function:

Close the session:

Start a Julia session:

Define a function in Julia:

Call the function:

Close the session:

ExternalFunction supports the same command specification as ExternalEvaluate:

Properties & Relations  (5)

ExternalOperation can be used to extract the operation from an ExternalFunction:

Run the operation using ExternalEvaluate:

ExternalOperation can be used as an argument to ExternalFunction:

The executed operation is identical to the following one:

Which can be executed with ExternalEvaluate:

The result is equivalent to running the following Python code:

Start a Python session:

Create an ExternalFunction and an ExternalObject:

ExternalObject can be used as an argument to ExternalFunction:

The result is equivalent to running the following Python code:

Close the session:

Start a Python session:

Create an ExternalObject:

Use ExternalFunction to run methods on the object:

Close the session:

Start a Python session:

Create an ExternalObject for the datetime module:

Create an ExternalObject with the current date and another one with a timedelta:

Send back the objects using an ExternalFunction:

The same can be done with an ExternalEvaluate call:

Use "ReturnType" to return a String:

Close the session:

Applications  (3)

Start a new session:

Define a function in the session:

Create an ExternalFunction from this Python function:

Use the function within normal Wolfram Language code:

Start a new session:

Import the Python NumPy package to load additional functionality:

Call the external function:

It partitioned the list into a 3×4 matrix:

The equivalent Wolfram Language command:

Start a new session:

Define a Python function that imports an image from a URL and rotates it:

The result is a ByteArray:

Import the ByteArray to display the rotated image:

Wolfram Research (2019), ExternalFunction, Wolfram Language function, https://reference.wolfram.com/language/ref/ExternalFunction.html (updated 2024).

Text

Wolfram Research (2019), ExternalFunction, Wolfram Language function, https://reference.wolfram.com/language/ref/ExternalFunction.html (updated 2024).

CMS

Wolfram Language. 2019. "ExternalFunction." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2024. https://reference.wolfram.com/language/ref/ExternalFunction.html.

APA

Wolfram Language. (2019). ExternalFunction. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/ExternalFunction.html

BibTeX

@misc{reference.wolfram_2024_externalfunction, author="Wolfram Research", title="{ExternalFunction}", year="2024", howpublished="\url{https://reference.wolfram.com/language/ref/ExternalFunction.html}", note=[Accessed: 21-November-2024 ]}

BibLaTeX

@online{reference.wolfram_2024_externalfunction, organization={Wolfram Research}, title={ExternalFunction}, year={2024}, url={https://reference.wolfram.com/language/ref/ExternalFunction.html}, note=[Accessed: 21-November-2024 ]}