.. _program_listing_file_numerics_vector_macros.h: Program Listing for File vector_macros.h ======================================== |exhale_lsh| :ref:`Return to documentation for file ` (``numerics/vector_macros.h``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp #pragma once #include #include #include "lupnt/core/constants.h" // Function: // Real = func(Real) // New definitions: // Vec = func(Vec) #define VEC_DEF_REAL(func) VecX func(const VecX& x); #define VEC_IMP_REAL(func) \ VecX func(const VecX& x) { \ VecX out(x.size()); \ _Pragma("omp parallel for") for (int i = 0; i < x.size(); i++) { out(i) = func(x(i)); } \ return out; \ } // Function: // Vec = func(Vec) // New definitions: // Mat<-1,size> = (Mat<-1,size>) #define VEC_DEF_VECTOR(func, size) \ Vec func(const Vec& x); \ Mat<-1, size> func(const Mat<-1, size>& x); #define VEC_IMP_VECTOR(func, size) \ Vec func(const Vec& x) { return func(static_cast(x)); } \ Mat<-1, size> func(const Mat<-1, size>& x) { \ Mat<-1, size> out(x.rows(), size); \ _Pragma("omp parallel for") for (int i = 0; i < x.rows(); i++) { \ Vec x_ = x.row(i); \ out.row(i) = func(x_); \ } \ return out; \ } // Function: // Vec = func(Vec) // New definitions: // Mat<-1,size> = (Mat<-1,size>) #define VEC_DEF_VECTOR_SIZE(func, size1, size2) \ Vec func(const Vec& x); \ Mat<-1, size2> func(const Mat<-1, size1>& x); #define VEC_IMP_VECTOR_SIZE(func, size1, size2) \ Vec func(const Vec& x) { return func(static_cast(x)); } \ Mat<-1, size2> func(const Mat<-1, size1>& x) { \ Mat<-1, size2> out(x.rows(), size2); \ _Pragma("omp parallel for") for (int i = 0; i < x.rows(); i++) { \ Vec x_ = x.row(i); \ out.row(i) = func(x_); \ } \ return out; \ } // Function: // Vec = func(Vec, Real) // New definitions: // Mat<-1,size> = func(Vec, VecX) // Mat<-1,size> = func(Mat<-1,size>, Real) // Mat<-1,size> = func(Mat<-1,size>, VecX) #define VEC_DEF_VECTOR_REAL(func, size) \ Vec func(const Vec& x, Real y); \ Mat<-1, size> func(const Vec& x, const VecX& y); \ Mat<-1, size> func(const Mat<-1, size>& x, Real y); \ Mat<-1, size> func(const Mat<-1, size>& x, const VecX& y); #define VEC_IMP_VECTOR_REAL(func, size) \ Vec func(const Vec& x, Real y) { return func(static_cast(x), y); } \ Mat<-1, size> func(const Vec& x, const VecX& y) { \ Mat<-1, size> out(y.rows(), size); \ _Pragma("omp parallel for") for (int i = 0; i < y.rows(); i++) out.row(i) = func(x, y(i)); \ return out; \ } \ Mat<-1, size> func(const Mat<-1, size>& x, Real y) { \ Mat<-1, size> out(x.rows(), size); \ _Pragma("omp parallel for") for (int i = 0; i < x.rows(); i++) { \ Vec x_ = x.row(i); \ out.row(i) = func(x_, y); \ } \ return out; \ } \ Mat<-1, size> func(const Mat<-1, size>& x, const VecX& y) { \ LUPNT_CHECK(x.rows() == y.rows(), "Size mismatch", "VectorMacros"); \ Mat<-1, size> out(x.rows(), size); \ _Pragma("omp parallel for") for (int i = 0; i < x.rows(); i++) { \ Vec x_ = x.row(i); \ out.row(i) = func(x_, y(i)); \ } \ return out; \ } // Function: // Vec = func(Vec, Real, Real) // New definitions: // Mat<-1,size> = func(Mat<-1,size>, Real, Real) #define VEC_DEF_VECTOR_REAL_REAL(func, size) \ Vec func(const Vec& x, Real y, Real z); \ Mat<-1, size> func(const Mat<-1, size>& x, Real y, Real z); #define VEC_IMP_VECTOR_REAL_REAL(func, size) \ Vec func(const Vec& x, Real y, Real z) { \ return func(static_cast(x), y, z); \ } \ Mat<-1, size> func(const Mat<-1, size>& x, Real y, Real z) { \ Mat<-1, size> out(x.rows(), size); \ _Pragma("omp parallel for") for (int i = 0; i < x.rows(); i++) { \ Vec x_ = x.row(i); \ out.row(i) = func(x_, y, z); \ } \ return out; \ } // Function: // Vec = func(Vec, Vec, Real) // New definitions: // Mat<-1,size> = func(Mat<-1,size>, Vec, Real) // Mat<-1,size> = func(Vec, Mat<-1,size>, Real) // Mat<-1,size> = func(Mat<-1,size>, Mat<-1,size>, Real) #define VEC_DEF_VECTOR_VECTOR_REAL(func, size) \ Mat<-1, size> func(const Mat<-1, size>& x, const Vec& y, Real z); \ Mat<-1, size> func(const Vec& x, const Mat<-1, size>& y, Real z); \ Mat<-1, size> func(const Mat<-1, size>& x, const Mat<-1, size>& y, Real z); #define VEC_IMP_VECTOR_VECTOR_REAL(func, size) \ Mat<-1, size> func(const Mat<-1, size>& x, const Vec& y, Real z) { \ Mat<-1, size> out(x.rows(), size); \ _Pragma("omp parallel for") for (int i = 0; i < x.rows(); i++) { \ Vec x_ = x.row(i); \ out.row(i) = func(x_, y, z); \ } \ return out; \ } \ Mat<-1, size> func(const Vec& x, const Mat<-1, size>& y, Real z) { \ Mat<-1, size> out(y.rows(), size); \ _Pragma("omp parallel for") for (int i = 0; i < y.rows(); i++) { \ Vec y_ = y.row(i); \ out.row(i) = func(x, y_, z); \ } \ return out; \ } \ Mat<-1, size> func(const Mat<-1, size>& x, const Mat<-1, size>& y, Real z) { \ LUPNT_CHECK(x.rows() == y.rows(), "Size mismatch", "VectorMacros"); \ Mat<-1, size> out(x.rows(), size); \ _Pragma("omp parallel for") for (int i = 0; i < x.rows(); i++) { \ Vec x_ = x.row(i); \ Vec y_ = y.row(i); \ out.row(i) = func(x_, y_, z); \ } \ return out; \ } // Function: // Vec = func(Vec, Vec // New definitions: // Mat<-1,size> = func(Mat<-1,size>, Mat<-1,size>) // Mat<-1,size> = func(Mat<-1,size>, Vec) // Mat<-1,size> = func(Vec, Mat<-1,size>) #define VEC_DEF_VECTOR_VECTOR(func, size) \ Vec func(const Vec& x, const Vec& y); \ Mat<-1, size> func(const Mat<-1, size>& x, const Mat<-1, size>& y); \ Mat<-1, size> func(const Mat<-1, size>& x, const Vec& y); \ Mat<-1, size> func(const Vec& x, const Mat<-1, size>& y); #define VEC_IMP_VECTOR_VECTOR(func, size) \ Vec func(const Vec& x, const Vec& y) { \ return func(static_cast(x), static_cast(y)); \ } \ Mat<-1, size> func(const Mat<-1, size>& x, const Mat<-1, size>& y) { \ LUPNT_CHECK(x.rows() == y.rows(), "Size mismatch", "VectorMacros"); \ Mat<-1, size> out(x.rows(), size); \ _Pragma("omp parallel for") for (int i = 0; i < x.rows(); i++) { \ Vec x_ = x.row(i); \ Vec y_ = y.row(i); \ out.row(i) = func(x_, y_); \ } \ return out; \ } \ Mat<-1, size> func(const Mat<-1, size>& x, const Vec& y) { \ Mat<-1, size> out(x.rows(), size); \ _Pragma("omp parallel for") for (int i = 0; i < x.rows(); i++) { \ Vec x_ = x.row(i); \ out.row(i) = func(x_, y); \ } \ return out; \ } \ Mat<-1, size> func(const Vec& x, const Mat<-1, size>& y) { \ Mat<-1, size> out(y.rows(), size); \ _Pragma("omp parallel for") for (int i = 0; i < y.rows(); i++) { \ Vec y_ = y.row(i); \ out.row(i) = func(x, y_); \ } \ return out; \ } // Function: // Real = func(Real, Real) // New definitions: // vector = func(vector, Real) // vector = func(Real, vector) // vector = func(vector, vector) #define VEC_DEF_REAL_REAL(func) \ VecX func(const VecX& x, Real y); \ VecX func(Real x, const VecX& y); \ VecX func(const VecX& x, const VecX& y); #define VEC_IMP_REAL_REAL(func) \ VecX func(const VecX& x, Real y) { \ VecX out(x.size()); \ _Pragma("omp parallel for") for (int i = 0; i < x.size(); i++) { out(i) = func(x(i), y); } \ return out; \ } \ VecX func(Real x, const VecX& y) { \ VecX out(y.size()); \ _Pragma("omp parallel for") for (int i = 0; i < y.size(); i++) { out(i) = func(x, y(i)); } \ return out; \ } \ VecX func(const VecX& x, const VecX& y) { \ if (x.size() != y.size()) throw std::runtime_error("Size mismatch"); \ VecX out(x.size()); \ _Pragma("omp parallel for") for (int i = 0; i < x.size(); i++) { out(i) = func(x(i), y(i)); } \ return out; \ }