Compile a custom numerical loop
Build native CPU user functions and a checked fixed array transformation, then compare the same source through interpreted execution.
// Development native CPU subset. Build requires the matching source-build SDK.
// aner build examples/native_numeric.aner -o /tmp/aner-native-numeric
// /tmp/aner-native-numeric
import aner.math
fn transform(values: Array<Float64>, factor: Float64) -> Array<Float64> {
let output = values.copy()
for index in Range(output.len()) {
output[index] = math.sqrt(values[index] * factor)
}
return output
}
fn accumulate(values: Array<Float64>) -> Float64 {
var total = 0.0
var index = 0
while index < values.len() {
total += values[index]
index += 1
}
return total
}
let samples = Array<Float64>(size: 4, fill: 9.0)
let transformed = transform(factor: 4.0, values: samples)
print(accumulate(transformed))
print(samples[0])
Make it your experiment.
Use the matching development source-build compiler SDK and C++20 toolchain. Save this program as examples/native_numeric.aner inside a folder for your experiment. Open a terminal in that folder, then check, build and execute the compiled program.
Choose fresh output paths and retain the generated C++ and JSON build manifest. On Windows, choose an .exe output and use the shell’s executable syntax. Building and the information command start no tasks.
aner check examples/native_numeric.aner
aner build examples/native_numeric.aner -o native-numeric
./native-numeric --aner-native-info
./native-numericWindows PowerShell:
aner check examples/native_numeric.aner
aner build examples/native_numeric.aner -o native-numeric.exe
.\native-numeric.exe --aner-native-info
.\native-numeric.exeSelect the matching aner compiler and SDK described in the native build guide; downloaded runtime packages do not provide a usable native SDK.
Requires the matching development source build compiler SDK and C++20 toolchain for native compilation. Downloaded runtime packages do not include a usable native compiler SDK. The interpreted source path remains available with the documented language subset.
This numerical example uses the development source-build compiler SDK. Retain its source, generated C++, build manifest and execution observations together when comparing results.
Read the native compiler contract