Operators¶
This section describes all the conventional C++
operators which have been overloaded in matrix
. To the exception of <<
, they all work element-wise.
operator<<¶
-
template<typename T>
std::ostream &castor::operator<<(std::ostream &flux, matrix<T> const &A)¶ Flux operator.
Insert matrix A inside a stream flux respecting standard C++ conventions.
matrix<> A = eye(3,4); std::cout << A << std::endl;
See disp.
operator!¶
-
template<typename T>
matrix<logical> castor::operator!(matrix<T> const &A)¶ Logical not.
!A performs a logical not of input array A, and returns an array containing elements set to either logical 1 (TRUE) or logical 0 (FALSE). An element of the output array is set to 1 if A contains a zero value element at that same array location. Otherwise, that element is set to 0.
matrix<logical> A = {{0,0,0},{1,1,1}}; matrix<logical> B = !A; disp(B);
See operator&&, operator||.
operator&&¶
-
template<typename R, typename S>
matrix<logical> castor::operator&&(matrix<R> const &A, matrix<S> const &B)¶ Logical and.
A&&B performs a logical and of arrays A and B and returns an array containing elements set to either logical 1 (TRUE) or logical 0 (FALSE). An element of the output array is set to 1 if both input arrays contain a non-zero element at that same array location. Otherwise, that element is set to 0. A and B must have compatible sizes. Two inputs have compatible sizes if, for every dimension, the dimension sizes of the inputs are the same.
matrix<logical> A = {{0,0,0},{1,1,1}}; matrix<logical> B = {{0,1,0},{1,0,1}}; matrix<logical> C = A&&B; matrix<logical> D = A&&1; disp(C); disp(D);
See operator||, operator!.
operator||¶
-
template<typename R, typename S>
matrix<logical> castor::operator||(matrix<R> const &A, matrix<S> const &B)¶ Logical or.
A||B performs a logical or of arrays A and B and returns an array containing elements set to either logical 1 (TRUE) or logical 0 (FALSE). An element of the output array is set to 1 if either input array contains a non-zero element at that same array location. Otherwise, that element is set to 0. A and B must have compatible sizes. Two inputs have compatible sizes if, for every dimension, the dimension sizes of the inputs are the same.
matrix<logical> A = {{0,0,0},{1,1,1}}; matrix<logical> B = {{0,1,0},{1,0,1}}; matrix<logical> C = A||B; matrix<logical> D = A||1; disp(C); disp(D);
See operator&&, operator!.
operator==¶
-
template<typename R, typename S>
matrix<logical> castor::operator==(matrix<R> const &A, matrix<S> const &B)¶ Equal.
A==B does element by element comparisons between A and B and returns an array with elements set to logical 1 (TRUE) where the relation is true and elements set to logical 0 (FALSE) where it is not. A and B must have compatible sizes. In the simplest cases, they can be the same size or one can be a scalar. Two inputs have compatible sizes if, for every dimension, the dimension sizes of the inputs are the same.
matrix<> A = {{1,2,3},{4,5,6}}; matrix<> B = {{0,2,0},{4,0,6}}; matrix<logical> C = (A==B); matrix<logical> D = (A==1); disp(C); disp(D);
See operator!=, operator<=, operator>=.
operator!=¶
-
template<typename R, typename S>
matrix<logical> castor::operator!=(matrix<R> const &A, matrix<S> const &B)¶ Not equal.
A!=B does element by element comparisons between A and B and returns an array with elements set to logical 1 (TRUE) where the relation is true and elements set to logical 0 (FALSE) where it is not. A and B must have compatible sizes. In the simplest cases, they can be the same size or one can be a scalar. Two inputs have compatible sizes if, for every dimension, the dimension sizes of the inputs are the same.
matrix<> A = {{1,2,3},{4,5,6}}; matrix<> B = {{0,2,0},{4,0,6}}; matrix<logical> C = (A!=B); matrix<logical> D = (A!=1); disp(C); disp(D);
See operator==, operator<=, operator>=.
operator<=¶
-
template<typename R, typename S>
matrix<logical> castor::operator<=(matrix<R> const &A, matrix<S> const &B)¶ Less than or equal.
A<=B does element by element comparisons between A and B and returns an array with elements set to logical 1 (TRUE) where the relation is true and elements set to logical 0 (FALSE) where it is not. A and B must have compatible sizes. In the simplest cases, they can be the same size or one can be a scalar. Two inputs have compatible sizes if, for every dimension, the dimension sizes of the inputs are the same.
matrix<> A = {{1,2,3},{4,5,6}}; matrix<> B = {{0,2,0},{4,0,6}}; matrix<logical> C = (A<=B); matrix<logical> D = (A<=3); disp(C); disp(D);
See operator==, operator>=, operator<.
operator<¶
-
template<typename R, typename S>
matrix<logical> castor::operator<(matrix<R> const &A, matrix<S> const &B)¶ Less than.
A<B does element by element comparisons between A and B and returns an array with elements set to logical 1 (TRUE) where the relation is true and elements set to logical 0 (FALSE) where it is not. A and B must have compatible sizes. In the simplest cases, they can be the same size or one can be a scalar. Two inputs have compatible sizes if, for every dimension, the dimension sizes of the inputs are the same.
matrix<> A = {{1,2,3},{4,5,6}}; matrix<> B = {{0,2,0},{4,0,6}}; matrix<logical> C = (A<B); matrix<logical> D = (A<3); disp(C); disp(D);
See operator<=, operator>, operator>=.
operator>=¶
-
template<typename R, typename S>
matrix<logical> castor::operator>=(matrix<R> const &A, matrix<S> const &B)¶ Greater than or equal.
A>=B does element by element comparisons between A and B and returns an array with elements set to logical 1 (TRUE) where the relation is true and elements set to logical 0 (FALSE) where it is not. A and B must have compatible sizes. In the simplest cases, they can be the same size or one can be a scalar. Two inputs have compatible sizes if, for every dimension, the dimension sizes of the inputs are the same.
matrix<> A = {{1,2,3},{4,5,6}}; matrix<> B = {{0,2,0},{4,0,6}}; matrix<logical> C = (A>=B); matrix<logical> D = (A>=3); disp(C); disp(D);
See operator>, operator<=, operator<.
operator>¶
-
template<typename R, typename S>
matrix<logical> castor::operator>(matrix<R> const &A, matrix<S> const &B)¶ Greater.
A>B does element by element comparisons between A and B and returns an array with elements set to logical 1 (TRUE) where the relation is true and elements set to logical 0 (FALSE) where it is not. A and B must have compatible sizes. In the simplest cases, they can be the same size or one can be a scalar. Two inputs have compatible sizes if, for every dimension, the dimension sizes of the inputs are the same.
matrix<> A = {{1,2,3},{4,5,6}}; matrix<> B = {{0,2,0},{4,0,6}}; matrix<logical> C = (A>B); matrix<logical> D = (A>3); disp(C); disp(D);
See operator>=, operator<, operator<=.
operator+¶
-
template<typename R, typename S>
auto castor::operator+(matrix<R> const &A, matrix<S> const &B)¶ Plus.
A+B adds matrices A and B. A and B must have compatible sizes. In the simplest cases, they can be the same size or one can be a scalar. Two inputs have compatible sizes if, for every dimension, the dimension sizes of the inputs are the same.
matrix<> A = {{1,2,3},{4,5,6}}; matrix<> B = {{6,5,4},{3,2,1}}; matrix<> C = A+B; matrix<> D = A+1; disp(C); disp(D);
operator-¶
-
template<typename S>
auto castor::operator-(matrix<S> const &A)¶ Unary or binary minus.
-A negates the elements of A.
matrix<> A = {{1,2,3},{4,5,6}}; matrix<> B = -A; disp(B);
A-B subtracts matrix B from A. A and B must have compatible sizes. In the simplest cases, they can be the same size or one can be a scalar. Two inputs have compatible sizes if, for every dimension, the dimension sizes of the inputs are the same.
matrix<> A = {{1,2,3},{4,5,6}}; matrix<> B = {{6,5,4},{3,2,1}}; matrix<> C = A-B; matrix<> D = A-1; disp(C); disp(D);
operator*¶
-
template<typename R, typename S>
auto castor::operator*(matrix<R> const &A, matrix<S> const &B)¶ Array multiply.
A*B denotes element-by-element multiplication. A and B must have compatible sizes. In the simplest cases, they can be the same size or one can be a scalar. Two inputs have compatible sizes if, for every dimension, the dimension sizes of the inputs are the same.
matrix<> A = {{1,2,3},{4,5,6}}; matrix<> B = {{6,5,4},{3,2,1}}; matrix<> C = A*B; matrix<> D = A*2; disp(C); disp(D);
operator/¶
-
template<typename R, typename S>
auto castor::operator/(matrix<R> const &A, matrix<S> const &B)¶ Right array divide.
A/B denotes element-by-element division. A and B must have compatible sizes. In the simplest cases, they can be the same size or one can be a scalar. Two inputs have compatible sizes if, for every dimension, the dimension sizes of the inputs are the same.
matrix<> A = {{1,2,3},{4,5,6}}; matrix<> B = {{6,5,4},{3,2,1}}; matrix<> C = A/B; matrix<> D = A/2; disp(C); disp(D);