Wolfram Language

Use Plotting Operations in Compiled Code

The Wolfram Compiler is not limited to only use functions that are directly supported. It can use KernelFunction to call on all parts of the Wolfram Language. The following example plots the state of the data at regular intervals, giving insight into the execution of the code.

The helper function printPlot prints a plot of its input as a side effect and returns the value True for purposes of compilation.

The function plottingSort provides a naive implementation of the bubble sort, a simple but inefficient sorting algorithm. At the end of the While loop, KernelFunction invokes printPlot on the data variable work.

Generate some data to be sorted using plottingSort.

Use printPlot to visualize the initial state of the data.

Sort the data using plottingSort. The last two plots are identical, as the While loop terminates when a pass has made no changes.

Related Examples

de es fr ja ko pt-br zh