Research CommonsResearch Commons
cppgrad/API reference

API reference

A summary of the cppgrad public surface — tensor factories, properties, operations, and core components.

This page summarizes the public API. The canonical reference is the source and the DeepWiki overview.

cppgrad::Tensor

The primary type. Include it via:

#include <cppgrad/tensor/tensor.hpp>

Factories

FunctionDescription
Tensor::zeros(shape)Tensor filled with zeros.
Tensor::full(shape, value)Tensor filled with a constant.
Tensor::full(shape, value, requires_grad)Constant tensor that tracks gradients.
Tensor::rand(shape)Tensor of random values.

Properties

MethodDescription
.shape()Tensor dimensions.
.dtype()Element data type.
.requires_grad()Whether gradient tracking is enabled.

Operations

OperationDescription
+ - * /Elementwise arithmetic.
.sum()Sum reduction.
.mean()Mean reduction.
.max()Max reduction.
.exp()Elementwise exponential.

Prebuilt gradient functions also cover Neg, Log, and Pow, among others.

Autograd

MethodDescription
.backward()Run reverse-mode differentiation from this tensor.
.grad()Read the accumulated gradient.

Core components

TypeRole
TensorImplUnderlying storage and metadata.
GradFnBase class for gradient functions.
SumFunction, MeanFunction, …Op-specific backward implementations.

Testing

cd build
ctest --output-on-failure

The suite covers tensor creation and manipulation, autograd correctness, and edge cases — and is actively expanding.