谁能更好地举例说明 System.Numerics.Vector.ConditionalSelect
可以使用什么/何时/如何使用?
我对 docs 的了解不多.
最佳答案
condition
参数实际上是Vector<int>
当使用 ConditionalSelect
的 4 字节重载时例如带有 Vector<int>
的那些或 Vector<float>
争论。 condition
是Vector<long>
当使用 8 字节版本等时
要扩展@Hans 在您的问题中的评论,condition
意思是这样的:double c = cond == -1 ? a : b;
.也就是说,当cond == -1
, 它选择左边的值。当cond == 0
,它会选择正确的值。
当 cond
是另外一回事,我看到了一些我还不是特别了解的结果,并没有真正研究。
class Program
{
static void Main(string[] args)
{
//Length depends on your Vector<int>.Count. In my computer it is 4
Vector<int> vector1 = new Vector<int>(4); //vector1 == {<4, 4, 4, 4>}
Vector<int> vector2 = new Vector<int>(5); //vector2 == {<5, 5, 5, 5>}
Vector<int> mask = Vector.GreaterThan(vector1, vector2); //mask == {<0, 0, 0, 0>}
Vector<int> selected = Vector.ConditionalSelect(mask, vector1, vector2); //selected == {<5, 5, 5, 5>}
vector1 = new Vector<int>(4); //vector1 == {<4, 4, 4, 4>}
vector2 = new Vector<int>(3); //vector2 == {<3, 3, 3, 3>}
mask = Vector.GreaterThan(vector1, vector2); //mask == {<-1, -1, -1, -1>}
selected = Vector.ConditionalSelect(mask, vector1, vector2); //selected == {<4, 4, 4, 4>}
mask = new Vector<int>(123); //mask == {<123, 123, 123, 123>}
selected = Vector.ConditionalSelect(mask, vector1, vector2); //selected == {<0, 0, 0, 0>}
mask = new Vector<int>(4);
selected = Vector.ConditionalSelect(mask, vector1, vector2); //selected == {<7, 7, 7, 7>}
}
}
关于c# - System.Numerics.Vector.ConditionalSelect 的用途是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49545905/