Skip to main content

Tensor Inspector (Dev)

The Tensor Inspector is designed to view and manipulate TensorData objects.

Architecture

  • Data Storage: Uses TensorData (a multi-dimensional array wrapper).
  • UI:
    • Inspector: TensorInspector (manages callbacks, side panels).
    • View: TensorDataView (the main table/grid view).
    • Designer: TensorDesigner (side panel for adding/editing columns).

Row Source Guidance

TensorDesigner row-type combo items expose Qt::ToolTipRole descriptions for each category (interval, timestamp, ordinal, derived, TimeFrame). A description label below the combo mirrors the current selection so users do not need to hover to read it.

Pipeline Integration

The TensorDesigner uses TransformPipeline to define how computed columns are populated.

  • Lazy Columns: Columns can be defined by a pipeline but not computed until requested.
  • Serialization: TensorDesigner save/load files use a JSON envelope (row_source + columns with embedded pipeline_json strings). The same format is consumed headlessly by the TensorDesign library for integration tests and future workspace hooks.

Column Views

The Column Views section allows creating zero-copy AnalogTimeSeries views for each column of a 2D TensorData. This is useful for visualizing individual channels in DataViewer_Widget and applying per-channel transforms.

How it works

  1. User selects a TensorData in the data tree.
  2. In the Column Views collapsible section, set a key prefix (defaults to tensor key).
  3. Click Create Column Views.
  4. For each column, an AnalogTimeSeries backed by TensorColumnAnalogStorage is inserted into DataManager under {prefix}/{column_name}.

Implementation

File Description
src/TensorDesign/TensorColumnViews.hpp Qt-free API: createTensorColumnViews, discoverAnalogKeyGroups
src/TensorDesign/TensorColumnViews.cpp Implementation using tensorToAnalog()
src/WhiskerToolbox/DataInspector_Widget/TensorData/TensorInspector.cpp UI section; delegates to TensorDesign
tests/TransformsV2/test_tensor_column_views.test.cpp Integration tests

The utility calls tensorToAnalog() internally, which creates TensorColumnAnalogStorage views — zero-copy spans into the Armadillo matrix columns. The views share ownership of the source TensorData via shared_ptr, so they remain valid as long as any view exists.

Note

Column names from the TensorData are used as suffixes in the generated keys. If no column names are set, the fallback is ch0, ch1, etc.

Populate from AnalogTimeSeries

When a TensorData object is empty (e.g., freshly created via the New Data widget), the inspector shows a Create from AnalogTimeSeries section instead of Column Views / Export.

Workflow

  1. Create an empty TensorData in the DataManager (via New Data → Tensor).
  2. Select it in the data tree. The inspector shows “Create from AnalogTimeSeries”.
  3. Click Refresh to scan the DataManager for groups of analog channels that share a common prefix (e.g., voltage_1, voltage_2, voltage_3 → group “voltage”).
  4. Select a group from the combo box.
  5. Click Populate Tensor to pack the channels into the tensor.

After population, the section hides and the standard Column Views / Export sections appear.

Key Group Discovery

discoverAnalogKeyGroups() extracts the prefix before the last _ character in each AnalogTimeSeries key, groups keys by prefix, and returns only groups with ≥2 keys. Keys without an underscore (or with _ only at position 0) are excluded.

Implementation

File Description
TensorColumnViews.hpp AnalogKeyGroup, discoverAnalogKeyGroups(), populateTensorFromAnalogKeys()
TensorColumnViews.cpp Implementation using analogToTensor() algorithm
TensorInspector.cpp UI section with combo box, refresh/populate buttons, visibility toggling
test_tensor_column_views.test.cpp Tests for group discovery and tensor population

Lifetime Safety

_onPopulateFromAnalog() calls DataManager::setData(), which triggers observer notifications that can destroy the TensorInspector widget (the properties widget recreates inspectors when the inspected key changes). To prevent use-after-free:

  • All member data (_active_key, group keys) is copied to locals before the call.
  • A QPointer<TensorInspector> guard detects destruction; if triggered, the slot returns without accessing this.

TimeFrame Validation

populateTensorFromAnalogKeys() checks that the target tensor’s existing TimeKey (if non-empty) matches the source analog channels’ TimeKey. This prevents accidentally overwriting a tensor that lives in a different temporal coordinate system.

Performance

analogToTensor() builds an arma::fmat directly column-by-column. Each analog channel maps to one Armadillo column (contiguous memory), so the copy is cache-friendly with zero intermediate allocation. The matrix is moved into TensorData::createTimeSeries2D(arma::fmat, ...) — no row-major-to-column-major conversion is needed.

Section Visibility

_updateSectionVisibility() checks TensorData::isEmpty() and toggles:

  • Empty tensor: Show “Create from AnalogTimeSeries”, hide Column Views and Export.
  • Non-empty tensor: Hide “Create from AnalogTimeSeries”, show Column Views and Export.