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
| Function | Description |
|---|---|
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
| Method | Description |
|---|---|
.shape() | Tensor dimensions. |
.dtype() | Element data type. |
.requires_grad() | Whether gradient tracking is enabled. |
Operations
| Operation | Description |
|---|---|
+ - * / | 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
| Method | Description |
|---|---|
.backward() | Run reverse-mode differentiation from this tensor. |
.grad() | Read the accumulated gradient. |
Core components
| Type | Role |
|---|---|
TensorImpl | Underlying storage and metadata. |
GradFn | Base class for gradient functions. |
SumFunction, MeanFunction, … | Op-specific backward implementations. |
Testing
cd build
ctest --output-on-failureThe suite covers tensor creation and manipulation, autograd correctness, and edge cases — and is actively expanding.