[simd.permute.mask] # 29 Numerics library [[numerics]](./#numerics) ## 29.10 Data-parallel types [[simd]](simd#permute.mask) ### 29.10.8 basic_vec non-member operations [[simd.nonmembers]](simd.nonmembers#simd.permute.mask) #### 29.10.8.9 vec mask permute [simd.permute.mask] [🔗](#lib:compress,simd) `template<[simd-vec-type](simd.expos#concept:simd-vec-type "29.10.2 Exposition-only types, variables, and concepts [simd.expos]") V> constexpr V compress(const V& v, const typename V::mask_type& selector); template<[simd-mask-type](simd.expos#concept:simd-mask-type "29.10.2 Exposition-only types, variables, and concepts [simd.expos]") M> constexpr M compress(const M& v, const type_identity_t& selector); ` [1](#1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L18847) Let: - [(1.1)](#1.1) *bit-index*(i) be a function which returns the index of the ith element of selector that is true[.](#1.1.sentence-1) - [(1.2)](#1.2) *select-value*(i) be a function which returnsv[*bit-index*(i)] for i in the range [0, reduce_count(selector)) and a valid but unspecified value otherwise[.](#1.2.sentence-1) [*Note [1](#note-1)*: Different calls to *select-value* can return different unspecified values[.](#1.2.sentence-2) — *end note*] [2](#2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L18863) *Returns*: A data-parallel object where the ith element is initialized to the result of *select-value*(i) for all i in the range [0, V​::​size())[.](#2.sentence-1) [🔗](#lib:compress,simd_) `template<[simd-vec-type](simd.expos#concept:simd-vec-type "29.10.2 Exposition-only types, variables, and concepts [simd.expos]") V> constexpr V compress(const V& v, const typename V::mask_type& selector, const typename V::value_type& fill_value); template<[simd-mask-type](simd.expos#concept:simd-mask-type "29.10.2 Exposition-only types, variables, and concepts [simd.expos]") M> constexpr M compress(const M& v, const type_identity_t& selector, const typename M::value_type& fill_value); ` [3](#3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L18881) Let: - [(3.1)](#3.1) *bit-index*(i) be a function which returns the index of the ith element of selector that is true[.](#3.1.sentence-1) - [(3.2)](#3.2) *select-value*(i) be a function which returnsv[*bit-index*(i)] for i in the range [0, reduce_count(selector)) and fill_value otherwise[.](#3.2.sentence-1) [4](#4) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L18893) *Returns*: A data-parallel object where the ith element is initialized to the result of *select-value*(i) for all i in the range [0, V​::​size())[.](#4.sentence-1) [🔗](#lib:expand,simd) `template<[simd-vec-type](simd.expos#concept:simd-vec-type "29.10.2 Exposition-only types, variables, and concepts [simd.expos]") V> constexpr V expand(const V& v, const typename V::mask_type& selector, const V& original = {}); template<[simd-mask-type](simd.expos#concept:simd-mask-type "29.10.2 Exposition-only types, variables, and concepts [simd.expos]") M> constexpr M expand(const M& v, const type_identity_t& selector, const M& original = {}); ` [5](#5) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L18909) Let: - [(5.1)](#5.1) *set-indices* be a list of the index positions of true elements in selector[.](#5.1.sentence-1) - [(5.2)](#5.2) *bit-lookup*(b) be a function which returns the index where b appears in *set-indices*[.](#5.2.sentence-1) - [(5.3)](#5.3) *select-value*(i) be a function which returnsv[*bit-lookup*(i)] if selector[i] istrue, otherwise returns original[i][.](#5.3.sentence-1) [6](#6) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L18924) *Returns*: A data-parallel object where the ith element is initialized to the result of *select-value*(i) for all i in the range [0, V​::​size())[.](#6.sentence-1)