casacore
Public Member Functions | List of all members
casacore::ArrayUtil_global_functions_concatenateArray Struct Reference

Concatenate two Arrays. More...

#include <ArrayUtil.h>

Public Member Functions

template<class T >
Array< T > concatenateArray (const Array< T > &left, const Array< T > &right)
 

Detailed Description

Concatenate two Arrays.

Review Status

Reviewed By:
UNKNOWN
Date Reviewed:
before2004/08/25
Test programs:
tArrayUtil

Prerequisite

Etymology

concatenateArray concatenates two Arrays into a new Array.

Synopsis

The function concatenates two Arrays into a new Array. The shape of both arrays must match except for the last dimension. The shape of the resulting array is equal to that of the input arrays with its last dimension as the sum of both last dimensions.

An exception ArrayConformanceError is thrown when the shapes do not match.

Motivation

The table system needed this function.

Example

Vector<int> vector1(5);
Vector<int> vector2(10);
indgen (vector1); // fill with values 0..4
indgen (vector2); // fill with values 0..9
Vector<int> result = concatenateVector (vector1, vector2);
void indgen(TableVector< T > &tv, T start, T inc)
Definition: TabVecMath.h:400

The example above results in a vector with length 15 and values 0,1,2,3,4,0,1,2,3,4,5,6,7,8,9.

It can also be used with matrices or arrays with higher dimensionality as long as all dimensions but the last one have equal length.

Matrix<int> matrix1 (3,4);
Matrix<int> matrix2 (3,5);
Matrix<int> matrix3 (4,4);
// Concatenation of matrix1 and matrix 2 will succeed and result
// in a 3x9 matrix.
Matrix<int> matrixConc = concatenateArray (matrix1, matrix2);
if (matrixConc.shape() != IPosition(2,3,9)) {
cout << "Error in shape of concatenated matrices" << endl;
}
// Concatenation of matrix1 and matrix3 will fail, because the
// first dimensions have a different length (3 vs. 4).
try {
concatenateArray (matrix1, matrix2);
} catch (ArrayConformanceError x) {
cout << x.what() << endl;
}
Array< T > concatenateArray(const Array< T > &left, const Array< T > &right)

Example


Definition at line 167 of file ArrayUtil.h.

Member Function Documentation

◆ concatenateArray()

template<class T >
Array<T> casacore::ArrayUtil_global_functions_concatenateArray::concatenateArray ( const Array< T > &  left,
const Array< T > &  right 
)

The documentation for this struct was generated from the following file: