# CHOOSE - choose operation

Implements the choose operation, which chooses between elements of A or B.

## Usage

The CHOOSE stored procedure has the following syntax:
CHOOSE(expression,matrixAname,matrixBname,matrixCname)
Parameters
expression
An expression choosing between A and B matrix elements.
Type: NVARCHAR(ANY)
matrixAname
The name of input matrix A.
Type: NVARCHAR(ANY)
matrixBname
The name of input matrix B.
Type: NVARCHAR(ANY)
matrixCname
The name of input matrix C.
Type: NVARCHAR(ANY)
Returns
BOOLEAN TRUE, if successful.

## Details

The procedure implements the choose operation, which chooses between elements of A or B depending on the expression. Matrices A and B must be the same shape. The output matrix C is given the same shape. Each element of C is either the corresponding element of A or B depending on the value of the expression. In the expression the current element of A can be referred to as "a.value" and the current element of B referred to as "b.value" as shown in the example. The user is responsible for ensuring the expression is well-formed. Matrix C must not exist prior to the operation. Warning: Use "coalesce" in the user-supplied expression for sparse matrices to work.

## Examples

``````CALL nzm..shape('1,2,3,4,5,6,7,8,9',3,3,'AA');
CALL nzm..shape('1,15,5,7',3,3,'BB');
CALL nzm..choose('a.value > b.value','AA','BB','CC');
CALL nzm..print('AA');CALL nzm..print('BB');
CALL nzm..print('CC');
CALL nzm..delete_matrix('AA');
CALL nzm..delete_matrix('BB');
CALL nzm..delete_matrix('CC');

SHAPE
-------
t
(1 row)

SHAPE
-------
t
(1 row)

CHOOSE
--------
t
(1 row)

PRINT
------------------------------------------
-- matrix: AA --
1, 2, 3
4, 5, 6
7, 8, 9
(1 row)

PRINT
--------------------------------------------
-- matrix: BB --
1, 15, 5
7, 1, 15
5, 7, 1
(1 row)

PRINT
--------------------------------------------
-- matrix: CC --
1, 15, 5
7, 5, 15
7, 8, 9
(1 row)

DELETE_MATRIX
---------------
t
(1 row)

DELETE_MATRIX
---------------
t
(1 row)

DELETE_MATRIX
---------------
t
(1 row)

CALL nzm..shape('1,2,3,4,5,6,7,8,9',3,3,'AA');
CALL nzm..shape('1,15,5,7',3,3,'BB');
CALL nzm..choose('(a.value * b.value) < (a.value + b.value)', 'AA', 'BB', 'CC');
CALL nzm..print('CC');
CALL nzm..delete_matrix('AA');
CALL nzm..delete_matrix('BB');
CALL nzm..delete_matrix('CC');

SHAPE
-------
t
(1 row)

SHAPE
-------
t
(1 row)

CHOOSE
--------
t
(1 row)

PRINT
--------------------------------------------
-- matrix: CC --
1, 15, 5
7, 5, 15
5, 7, 9
(1 row)

DELETE_MATRIX
---------------
t
(1 row)

DELETE_MATRIX
---------------
t
(1 row)

DELETE_MATRIX
---------------
t
(1 row)

CALL nzm..shape('1,2,3,4,5,6,7,8,9',3,3,'AA');
CALL nzm..shape('1,15,5,7',3,3,'BB');
CALL nzm..choose('(a.value < b.value) and (a.value > (b.value -10))', 'AA', 'BB', 'CC');
CALL nzm..print('CC');
CALL nzm..delete_matrix('AA');
CALL nzm..delete_matrix('BB');
CALL nzm..delete_matrix('CC');

SHAPE
-------
t
(1 row)

SHAPE
-------
t
(1 row)

CHOOSE
--------
t
(1 row)

PRINT
-------------------------------------------
-- matrix: CC --
1, 15, 3
4, 1, 6
5, 7, 1
(1 row)

DELETE_MATRIX
---------------
t
(1 row)

DELETE_MATRIX
---------------
t
(1 row)

DELETE_MATRIX
---------------
t
(1 row)``````