Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Interpretml Interpret Tensor

From Leeroopedia


Knowledge Sources
Domains Machine_Learning, EBM_Core
Last Updated 2026-02-07 12:00 GMT

Overview

Tensor is a C++ module that implements a dynamically-sized multi-dimensional tensor data structure used to store and manipulate EBM model update scores and split points.

Description

The Tensor class is a core data structure in the EBM library that represents a multi-dimensional array of scores with associated split points along each dimension. It supports dynamic resizing, copying, expansion, and transposition operations.

Key operations include:

  • Allocate: Factory method that creates a new Tensor with specified maximum dimensions and score count. Allocates initial storage for scores and split arrays per dimension.
  • Free: Deallocates all tensor memory including per-dimension split arrays and the aligned score buffer.
  • Reset: Resets all dimensions to a single slice and zeros the base scores without deallocating memory.
  • SetCountSlices: Sets the number of slices for a given dimension, growing the split buffer by 50% if needed (using realloc).
  • EnsureTensorScoreCapacity: Ensures the score buffer can hold the required number of values, growing with aligned allocation.
  • Copy: Deep copies all splits and scores from another tensor.
  • Add: Element-wise addition of another tensor's scores to this tensor's scores, requiring matching dimensions and slices.
  • Expand: Expands the tensor to its full size by adding slices for missing and unseen categories. This involves expanding each dimension in turn and redistributing scores via stride-based memory copying.
  • Transpose: Reorders the tensor dimensions according to a specified index mapping, transposing both the split arrays and the score data.

Each dimension is tracked via a DimensionInfo struct containing the slice count, slice capacity, and split point array (UIntSplit).

Usage

The Tensor class is used extensively throughout the EBM boosting pipeline. During each boosting step, a Tensor stores the model update scores produced by the partitioning algorithms. These updates are then added to the cumulative model tensor. The Expand and Transpose operations are used when preparing tensors for external consumption.

Code Reference

Source Location

Signature

class Tensor {
public:
    static Tensor* Allocate(const size_t cDimensionsMax, const size_t cScores);
    static void Free(Tensor* const pTensor);

    void Reset();
    ErrorEbm SetCountSlices(const size_t iDimension, const size_t cSlices);
    ErrorEbm EnsureTensorScoreCapacity(const size_t cTensorScores);
    ErrorEbm Copy(const Tensor& rhs);
    ErrorEbm Add(const Tensor& rhs);
    ErrorEbm Expand(const Term* const pTerm);
    ErrorEbm Transpose(const Term* const pTerm, const size_t* const aiTranspose);

    FloatScore* GetTensorScoresPointer();
    UIntSplit* GetSplitPointer(const size_t iDimension);
    DimensionInfo* GetDimensions();
};

I/O Contract

Inputs

Name Type Required Description
cDimensionsMax size_t Yes Maximum number of dimensions the tensor can hold
cScores size_t Yes Number of scores per tensor cell (classes for classification)

Outputs

Name Type Description
Tensor* Tensor pointer Allocated tensor instance (from Allocate), or nullptr on failure
ErrorEbm ErrorEbm Error code returned by mutating operations

Usage Examples

Pipeline Context

# This C++ module is called internally via the native bindings
# to store and manage model update tensors during boosting
from interpret.glassbox import ExplainableBoostingClassifier
ebm = ExplainableBoostingClassifier()
ebm.fit(X, y)  # Internally uses Tensor for model updates

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment