c# - System.Numerics.Vector.ConditionalSelect 的用途是什么?

标签 c# .net simd system.numerics

谁能更好地举例说明 System.Numerics.Vector.ConditionalSelect 可以使用什么/何时/如何使用?

我对 docs 的了解不多.

最佳答案

condition参数实际上是Vector<int>当使用 ConditionalSelect 的 4 字节重载时例如带有 Vector<int> 的那些或 Vector<float>争论。 conditionVector<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/

相关文章:

c# - IDE0057 子串可以简化

c# - ListView 控件中的闪烁(OwnerDraw、Virtual)

c# - 现在更新到 EF5 NotMapped 注释不起作用

c# - Monogame-音乐和声音效果无法同时播放

c# - 将二维集合绑定(bind)到 DataGridView

c++ - avx2 寄存器位反转

javascript - LiveEngage - LivePerson 聊天标签不显示任何内容

c# - GDI+ 在基线上绘制不同大小的文本存在 off-by-1px 问题

c++ - 如何将 2 个 16 位 vector 相乘并将结果存储在 sse 中的 32 位 vector 中?

c - Altivec编译错误