All examplesScientific computing Install Aner
Native Tensor operations and one optimizer update
Construct small tensors, multiply matrices, choose precision explicitly and apply one native parameter update.
// Neutral tensor construction, explicit numerical operations, and one gradient update.
import aner.tensor
import aner.nn
let samples: Tensor = [[1.0, 2.0], [3.0, 4.0]]
let weights: Tensor = [[2.0], [1.0]]
let product = nn.matmul(samples, weights)
print("Product shape and values")
print(tensor.rows(product))
print(tensor.cols(product))
print(tensor.value(product, 0, 0))
print(tensor.value(product, 1, 0))
print("Default precision and device")
print(samples.dtype())
print(samples.device())
print("Explicit detached Float32 conversion")
print(samples.astype("Float32").dtype())
let input: Tensor = [[1.0, 2.0]]
let target: Tensor = [[1.0]]
let parameter = nn.parameter([[0.0], [0.0]])
let loss = nn.mse(nn.matmul(input, parameter), target)
nn.backward(loss)
let updated = nn.sgd(parameter, rate: 0.1)
print("Loss before and after one gradient update")
print(tensor.item(loss))
print(tensor.item(nn.mse(nn.matmul(input, updated), target)))
print("First weight gradient")
print(tensor.value(nn.grad(parameter), 0, 0))
Make it your experiment.
With Aner installed, save this program as examples/tensor_basics.aner inside a folder for your experiment. Open a terminal in that folder, then check and run the program.
aner check examples/tensor_basics.aner
aner run examples/tensor_basics.anerThe aner command must be on your PATH. Follow the installation guide if your terminal cannot find it.
Use a compatible current native Aner executable. This complete example runs locally with the declared inputs; the guide explains exact shapes, expected results and resource limits.
Bundled datasets retain their own source attribution and license notices. Example outcomes are not comparative benchmarks or evidence of clinical validity.
Dataset sources & attribution