Class Matrix2Vector

Streams a matrix frame row-by-row, emitting one Vector[nChannels] per clock tick.

JSON configuration

Use these block entries inside a pipeline configuration. Input names must match other blocks in that pipeline; device addresses and file paths must match your setup.

"stream": {
  "Type": "Matrix2Vector",
  "Inputs": ["timerFast", "window"],
  "Params": ["timer:timerFast"]
}

How Type, Inputs and Params work · Block catalogue and parameter reference

Inheritance
Matrix2Vector
Namespace: MOSAIC.Models.FlowControl
Assembly: MOSAIC.dll
Syntax
public sealed class Matrix2Vector : BaseBlock, INotifyPropertyChanged, INotifyPropertyChanging, ISubscriber, IPublisher, IBaseBlockProps, IJsonExportable, IDisposable, IAsyncDisposable
Remarks

Purpose: Converts block-oriented matrix output (e.g., from a SlidingWindow) into a continuous sample-by-sample stream at the clock rate. Each row of the matrix represents one timestep; each column represents one channel. On every clock tick, the next row is published as a Vector[nChannels].

Timing: With a window of 200 samples, stride 100, and a 200 Hz timer:

  • The window outputs a [200 × nCh] matrix every 0.5 s (stride 100 / 200 Hz).
  • Matrix2Vector iterates 200 rows at 200 Hz = 1 second to exhaust the frame.
  • After 100 rows (0.5 s), the next window frame arrives and resets the cursor.
  • The overlap is natural — rows 100–199 of frame N are identical to rows 0–99 of frame N+1, so the reset produces seamless continuous output.

Dual-input design:

  • Data source: Provides frames of shape (nTimesteps × nChannels). Each new frame replaces the buffer and resets the row cursor.
  • Timer (identified by name via Params): Each tick advances the row cursor and publishes the next row as Vector[nChannels].

Timer identification: Uses the same timer:<name> convention as Joiner. The sender's Name is matched against the configured timer name.

Rate propagation: The output rate is forced from the timer block's DesiredRate on the first tick, overriding any rate inherited from the data source.

JSON configuration:

"stream": {
  "Type": "Matrix2Vector",
  "Inputs": ["timerFast", "window"],
  "Params": ["timer:timerFast"]
}

Constructors

Matrix2Vector(string, double, string)

Creates a new Matrix2Vector block.

Declaration
public Matrix2Vector(string name = "Matrix2Vector", double desiredRate = 0, string timerSource = "")
Parameters
Type Name Description
string name

Block name.

double desiredRate

Desired execution rate in Hz.

string timerSource

Name of the upstream block that triggers row emission. Must not be empty.

Fields

_channelCount

Number of channels (columns) in the current frame.

Declaration
[ObservableProperty]
private int _channelCount
Field Value
Type Description
int

_currentFrame

Currently buffered frame [timesteps × channels].

Declaration
private Matrix<double>? _currentFrame
Field Value
Type Description
Matrix<double>

_currentRow

Current row position in the frame.

Declaration
[ObservableProperty]
private int _currentRow
Field Value
Type Description
int

_frameCount

Total frames received.

Declaration
[ObservableProperty]
private long _frameCount
Field Value
Type Description
long

_frameLength

Number of timesteps (rows) in the current frame.

Declaration
[ObservableProperty]
private int _frameLength
Field Value
Type Description
int

_frameLock

Lock guarding frame replacement and cursor access.

Declaration
private readonly object _frameLock
Field Value
Type Description
object

_publishCount

Total vectors published.

Declaration
[ObservableProperty]
private long _publishCount
Field Value
Type Description
long

_rateLatched

Whether we've already forced our rate from the timer block.

Declaration
private bool _rateLatched
Field Value
Type Description
bool

_rowCursor

Next row index to emit on the next clock tick.

Declaration
private int _rowCursor
Field Value
Type Description
int

_timerName

Name of the timer source (for UI display).

Declaration
[ObservableProperty]
private string _timerName
Field Value
Type Description
string

_timerSource

Name of the upstream block whose arrival triggers row emission.

Declaration
private readonly string _timerSource
Field Value
Type Description
string

Properties

ChannelCount

Number of channels (columns) in the current frame.

Declaration
[ExcludeFromCodeCoverage]
public int ChannelCount { get; set; }
Property Value
Type Description
int

CurrentRow

Current row position in the frame.

Declaration
[ExcludeFromCodeCoverage]
public int CurrentRow { get; set; }
Property Value
Type Description
int

FrameCount

Total frames received.

Declaration
[ExcludeFromCodeCoverage]
public long FrameCount { get; set; }
Property Value
Type Description
long

FrameLength

Number of timesteps (rows) in the current frame.

Declaration
[ExcludeFromCodeCoverage]
public int FrameLength { get; set; }
Property Value
Type Description
int

JsonTypeName

Block type identifier for JSON serialization. Override for a custom name.

Declaration
protected override string JsonTypeName { get; }
Property Value
Type Description
string
Overrides
BaseBlock.JsonTypeName

MaxInputs

Needs exactly two inputs (e.g. a data stream + a Trigger/TriggerBuffer).

Declaration
public override int MaxInputs { get; }
Property Value
Type Description
int
Overrides
BaseBlock.MaxInputs

MinInputs

Needs exactly two inputs (e.g. a data stream + a Trigger/TriggerBuffer).

Declaration
public override int MinInputs { get; }
Property Value
Type Description
int
Overrides
BaseBlock.MinInputs

PublishCount

Total vectors published.

Declaration
[ExcludeFromCodeCoverage]
public long PublishCount { get; set; }
Property Value
Type Description
long

TimerName

Name of the timer source (for UI display).

Declaration
[ExcludeFromCodeCoverage]
public string TimerName { get; set; }
Property Value
Type Description
string

Visualization

This block's visualization, or null when it has none.

Declaration
protected override BlockVisualization? Visualization { get; }
Property Value
Type Description
BlockVisualization
Overrides
BaseBlock.Visualization
Remarks

Blocks own their scope as a public Viz property rather than inheriting one, so the base class has no way to reach it. Overriding this is what lets the rate below be wired up automatically. With correct publication metadata, the bundle derives the time axis for one vector per publication or fixed-size contiguous sample packets from the feed shape.

When a plot needs a rate that publication frequency and feed shape cannot express (for example, variable-sized packets or overlapping windows), declare it with Viz.UpdateSignalRate. An explicit declaration wins over the derived rate. A block with several bundles must configure each one; this hook exposes only one bundle.

Viz

Visualization bundle for scope display.

Declaration
public BlockVisualization Viz { get; }
Property Value
Type Description
BlockVisualization

Methods

ConfigureInput(IServiceProvider, JsonModel)

Creates a Matrix2Vector from JSON pipeline configuration.

Declaration
public static Matrix2Vector ConfigureInput(IServiceProvider sp, JsonModel m)
Parameters
Type Name Description
IServiceProvider sp
JsonModel m
Returns
Type Description
Matrix2Vector

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

Declaration
public override void Dispose()
Overrides
BaseBlock.Dispose()

EmitNextRow()

Emits the next row from the current frame as a Vector[nChannels]. Skips silently if no frame is available or all rows have been consumed (the next frame arrival will reset the cursor).

Declaration
private void EmitNextRow()

GetJsonParams()

Block-specific parameters for JSON. Override to provide custom parameters.

Declaration
protected override IReadOnlyList<object>? GetJsonParams()
Returns
Type Description
IReadOnlyList<object>

The values for Params, in the order this block's ConfigureInput reads them, or null when the block takes no parameters.

Overrides
BaseBlock.GetJsonParams()

OnChannelCountChanged(int)

Executes the logic for when ChannelCount just changed.

Declaration
private void OnChannelCountChanged(int value)
Parameters
Type Name Description
int value

The new property value that was set.

Remarks

This method is invoked right after the value of ChannelCount is changed.

OnChannelCountChanged(int, int)

Executes the logic for when ChannelCount just changed.

Declaration
private void OnChannelCountChanged(int oldValue, int newValue)
Parameters
Type Name Description
int oldValue

The previous property value that was replaced.

int newValue

The new property value that was set.

Remarks

This method is invoked right after the value of ChannelCount is changed.

OnChannelCountChanging(int)

Executes the logic for when ChannelCount is changing.

Declaration
private void OnChannelCountChanging(int value)
Parameters
Type Name Description
int value

The new property value being set.

Remarks

This method is invoked right before the value of ChannelCount is changed.

OnChannelCountChanging(int, int)

Executes the logic for when ChannelCount is changing.

Declaration
private void OnChannelCountChanging(int oldValue, int newValue)
Parameters
Type Name Description
int oldValue

The previous property value that is being replaced.

int newValue

The new property value being set.

Remarks

This method is invoked right before the value of ChannelCount is changed.

OnCurrentRowChanged(int)

Executes the logic for when CurrentRow just changed.

Declaration
private void OnCurrentRowChanged(int value)
Parameters
Type Name Description
int value

The new property value that was set.

Remarks

This method is invoked right after the value of CurrentRow is changed.

OnCurrentRowChanged(int, int)

Executes the logic for when CurrentRow just changed.

Declaration
private void OnCurrentRowChanged(int oldValue, int newValue)
Parameters
Type Name Description
int oldValue

The previous property value that was replaced.

int newValue

The new property value that was set.

Remarks

This method is invoked right after the value of CurrentRow is changed.

OnCurrentRowChanging(int)

Executes the logic for when CurrentRow is changing.

Declaration
private void OnCurrentRowChanging(int value)
Parameters
Type Name Description
int value

The new property value being set.

Remarks

This method is invoked right before the value of CurrentRow is changed.

OnCurrentRowChanging(int, int)

Executes the logic for when CurrentRow is changing.

Declaration
private void OnCurrentRowChanging(int oldValue, int newValue)
Parameters
Type Name Description
int oldValue

The previous property value that is being replaced.

int newValue

The new property value being set.

Remarks

This method is invoked right before the value of CurrentRow is changed.

OnFrameCountChanged(long)

Executes the logic for when FrameCount just changed.

Declaration
private void OnFrameCountChanged(long value)
Parameters
Type Name Description
long value

The new property value that was set.

Remarks

This method is invoked right after the value of FrameCount is changed.

OnFrameCountChanged(long, long)

Executes the logic for when FrameCount just changed.

Declaration
private void OnFrameCountChanged(long oldValue, long newValue)
Parameters
Type Name Description
long oldValue

The previous property value that was replaced.

long newValue

The new property value that was set.

Remarks

This method is invoked right after the value of FrameCount is changed.

OnFrameCountChanging(long)

Executes the logic for when FrameCount is changing.

Declaration
private void OnFrameCountChanging(long value)
Parameters
Type Name Description
long value

The new property value being set.

Remarks

This method is invoked right before the value of FrameCount is changed.

OnFrameCountChanging(long, long)

Executes the logic for when FrameCount is changing.

Declaration
private void OnFrameCountChanging(long oldValue, long newValue)
Parameters
Type Name Description
long oldValue

The previous property value that is being replaced.

long newValue

The new property value being set.

Remarks

This method is invoked right before the value of FrameCount is changed.

OnFrameLengthChanged(int)

Executes the logic for when FrameLength just changed.

Declaration
private void OnFrameLengthChanged(int value)
Parameters
Type Name Description
int value

The new property value that was set.

Remarks

This method is invoked right after the value of FrameLength is changed.

OnFrameLengthChanged(int, int)

Executes the logic for when FrameLength just changed.

Declaration
private void OnFrameLengthChanged(int oldValue, int newValue)
Parameters
Type Name Description
int oldValue

The previous property value that was replaced.

int newValue

The new property value that was set.

Remarks

This method is invoked right after the value of FrameLength is changed.

OnFrameLengthChanging(int)

Executes the logic for when FrameLength is changing.

Declaration
private void OnFrameLengthChanging(int value)
Parameters
Type Name Description
int value

The new property value being set.

Remarks

This method is invoked right before the value of FrameLength is changed.

OnFrameLengthChanging(int, int)

Executes the logic for when FrameLength is changing.

Declaration
private void OnFrameLengthChanging(int oldValue, int newValue)
Parameters
Type Name Description
int oldValue

The previous property value that is being replaced.

int newValue

The new property value being set.

Remarks

This method is invoked right before the value of FrameLength is changed.

OnPublishCountChanged(long)

Executes the logic for when PublishCount just changed.

Declaration
private void OnPublishCountChanged(long value)
Parameters
Type Name Description
long value

The new property value that was set.

Remarks

This method is invoked right after the value of PublishCount is changed.

OnPublishCountChanged(long, long)

Executes the logic for when PublishCount just changed.

Declaration
private void OnPublishCountChanged(long oldValue, long newValue)
Parameters
Type Name Description
long oldValue

The previous property value that was replaced.

long newValue

The new property value that was set.

Remarks

This method is invoked right after the value of PublishCount is changed.

OnPublishCountChanging(long)

Executes the logic for when PublishCount is changing.

Declaration
private void OnPublishCountChanging(long value)
Parameters
Type Name Description
long value

The new property value being set.

Remarks

This method is invoked right before the value of PublishCount is changed.

OnPublishCountChanging(long, long)

Executes the logic for when PublishCount is changing.

Declaration
private void OnPublishCountChanging(long oldValue, long newValue)
Parameters
Type Name Description
long oldValue

The previous property value that is being replaced.

long newValue

The new property value being set.

Remarks

This method is invoked right before the value of PublishCount is changed.

OnReceive(object, object)

Processes incoming data from an upstream block. Must be implemented by derived classes.

Declaration
protected override void OnReceive(object sender, object data)
Parameters
Type Name Description
object sender

The publishing block, or whatever else delivered the value.

object data
Overrides
BaseBlock.OnReceive(object, object)
Remarks

Called on the dispatching thread, not the UI thread.

OnTimerNameChanged(string)

Executes the logic for when TimerName just changed.

Declaration
private void OnTimerNameChanged(string value)
Parameters
Type Name Description
string value

The new property value that was set.

Remarks

This method is invoked right after the value of TimerName is changed.

OnTimerNameChanged(string?, string)

Executes the logic for when TimerName just changed.

Declaration
private void OnTimerNameChanged(string? oldValue, string newValue)
Parameters
Type Name Description
string oldValue

The previous property value that was replaced.

string newValue

The new property value that was set.

Remarks

This method is invoked right after the value of TimerName is changed.

OnTimerNameChanging(string)

Executes the logic for when TimerName is changing.

Declaration
private void OnTimerNameChanging(string value)
Parameters
Type Name Description
string value

The new property value being set.

Remarks

This method is invoked right before the value of TimerName is changed.

OnTimerNameChanging(string?, string)

Executes the logic for when TimerName is changing.

Declaration
private void OnTimerNameChanging(string? oldValue, string newValue)
Parameters
Type Name Description
string oldValue

The previous property value that is being replaced.

string newValue

The new property value being set.

Remarks

This method is invoked right before the value of TimerName is changed.

StoreFrame(object)

Stores an incoming frame and resets the row cursor.

Declaration
private void StoreFrame(object data)
Parameters
Type Name Description
object data

Implements

INotifyPropertyChanged
INotifyPropertyChanging
ISubscriber
IPublisher
IBaseBlockProps
IJsonExportable
IDisposable
IAsyncDisposable

Search documentation

Start typing to search the documentation.