# Concat¶

Concat  // Concatenation operation


## Description¶

Produce from Nodes of args some outputs with the same attributes

### Inputs¶

Name Type Notes
args Nodes All element types the same. All shapes the same except on concatenation_axis

### Attributes¶

Name Notes
concatenation_axis Less than the rank of the shape

### Outputs¶

Name Element Type Shape
output
Same as args | Same as arg on non-concatenation_axis
Sum of concatenation_axis lengths of args

## Mathematical Definition¶

We map each tensor in args to a segment of output based on the coordinate at coordinate_axis.

Let

$\begin{split}s(i) &= \sum_{j<i} \mathtt{args}[i].\mathtt{shape}\left[\mathtt{concatenation_axis}\right]\\ t(i) &= \text{The greatest }j\text{ such that }i \ge s(j)\\ p(C)_i &= \begin{cases} C_i-s(t(i))&\text{if }i==\mathtt{concatenation_axis}\\ C_i&\text{otherwise} \end{cases}\\ \mathtt{output}_C&=\mathtt{args}[t(C_i)]_{p(C)}\end{split}$

## Backprop¶

We slice the backprop value into the backprops associated with the inputs.

## C++ Interface¶

class Concat : public ngraph::op::Op

Concatenation operation.

Public Functions

Concat(const NodeVector &args, size_t concatenation_axis)

Constructs a concatenation operation.

Parameters
• args: The nodes producing the input tensors.
• concatenation_axis: The axis along which to concatenate the input tensors.

void validate_and_infer_types()

Throws if the node is invalid.

std::vector<std::shared_ptr<op::Constant>> as_constants() const

Produce a vector of constant nodes (one for each of this node’s outputs) that can replace this node’s outputs. May return an empty vector to signal that conversion to constants is not possible or not supported.

Conversion does not have to be complete. That means that subclasses *may* override as_constants, but do not have to. It is allowed for as_constants to return an empty vector even in cases where the output values are statically computable. Thus, any user of as_constants must allow for the possibility that conversion will fail (i.e., as_constants will return {}).

Return
If conversion is successful, a vector of op::Constant nodes, corresponding to this node’s outputs in order. If unsuccessful, an empty vector.

Conversion must be sound. That means that if as_constants returns a non-empty vector, the value of each constant in the vector must be exactly the value that would have been returned for the corresponding output at runtime.

size_t get_concatenation_axis() const

Return
The concatenation axis.