Wiki

Clone wiki

blaze / Bitwise OR


Vector/Vector Bitwise OR

Via the bitwise OR operator (i.e. operator|()) it is possible to perform an elementwise bitwise OR with dense vectors:

blaze::DynamicVector<unsigned int> v1( 5UL ), v3;
blaze::DynamicVector<unsigned short> v2( 5UL );

// ... Initializing the vectors

v3 = v1 | v2;  // Elementwise bitwise OR of two dense column vectors of different data type

Note that it is necessary that both operands have exactly the same dimensions. Violating this precondition results in an exception. Also note that it is only possible to use vectors with the same transpose flag:

using blaze::columnVector;
using blaze::rowVector;

blaze::DynamicVector<unsigned int,columnVector> v1( 5UL );
blaze::DynamicVector<unsigned int,rowVector>    v2( 5UL );

v1 | v2;           // Compilation error: Cannot OR a column vector and a row vector
v1 | trans( v2 );  // OK: Bitwise OR of two column vectors

Furthermore, it is possible to use different element types in the two vector operands, but a bitwise OR of two vectors with the same element type is favorable due to possible vectorization of the operation:

blaze::DynamicVector<unsigned int> v1( 100UL ), v2( 100UL ), v3;

// ... Initialization of the vectors

v3 = v1 | v2;  // Vectorized bitwise OR of an unsigned int vector

Matrix/Matrix Bitwise OR

The bitwise OR operator (i.e. operator|()) can also be used to perform an elementwise bitwise OR with dense matrices:

using blaze::rowMajor;
using blaze::columnMajor;

blaze::DynamicMatrix<unsigned int,columnMajor> M1( 7UL, 3UL );
blaze::DynamicMatrix<unsigned short,rowMajor>  M2( 7UL, 3UL ), M3;

// ... Initializing the matrices

M3 = M1 | M2;  // Elementwise bitwise OR of two dense matrices of different data type

Note that it is necessary that both operands have exactly the same dimensions. Violating this precondition results in an exception. It is possible to use any combination of row-major and column-major matrices. Note however that in favor of performance using two matrices with the same storage order is favorable. The same argument holds for the element type: While it is possible to use matrices with different element type, using two matrices with the same element type potentially leads to better performance due to vectorization of the operation.

blaze::DynamicMatrix<unsigned int> M1( 50UL, 70UL ), M2( 50UL, 70UL ), M3;

// ... Initialization of the matrices

M3 = M1 | M2;  // Vectorized bitwise OR of two row-major, unsigned int dense matrices

Scalar Bitwise OR

Is is also possible to perform a bitwise OR between a dense vector or dense matrix and a scalar value, which has the same effect as performing a bitwise OR by means of a uniform vector or matrix (see UniformVector and UniformMatrix). In Blaze it is possible to use all built-in/fundamental data types except bool as scalar values. Examples:

blaze::DynamicVector<unsigned int> v1{ 3U, 2U, 5U, 4U, 1U, 6U };

// Perform a bitwise OR with all elements of v1; Results in
//
//    ( 3, 3, 7, 7, 3, 3 )
//
blaze::DynamicVector<int> v2( v1 | 3U );
blaze::DynamicMatrix<unsigned int> M1{ { 3U, 2U, 5U },
                                       { 4U, 1U, 6U } };

// Perform a bitwise OR with all elements of M1; Results in
//
//    ( 3, 3, 7 )
//    ( 7, 3, 3 )
//
blaze::DynamicMatrix<unsigned int> M2( M1 | 3U );

Previous: Bitwise AND ---- Next: Bitwise XOR

Updated