Sto tentando di utilizzare System.Numerics.Vector<T>
(documentation).Perché il vettore è <T> .Count statico?
ho scritto un semplice test di unità:
var v = new System.Numerics.Vector<double>(new double[] { 12, 13, 14 });
Assert.AreEqual(3, v.Count);
ma mi ha dato un errore di generazione:
Member 'Vector.Count' cannot be accessed with an instance reference; qualify it with a type name instead
Con mia grande sorpresa, Vector<T>.Count
è statico.
Così ho provato:
var v = new System.Numerics.Vector<double>(new double[] { 12, 13, 14 });
Assert.AreEqual(3, Vector<double>.Count);
Ora il codice costruisce ma il test di unità fallisce:
Assert.AreEqual failed. Expected:<3>. Actual:<2>.
Cosa sta succedendo?
Investigating ho trovato:
Assert.AreEqual(2, Vector<double>.Count);
Assert.AreEqual(4, Vector<float>.Count);
Assert.AreEqual(4, Vector<int>.Count);
Assert.AreEqual(2, Vector<long>.Count);
I suoi due frammenti sono identici. – BoltClock
@BoltClock grazie risolto. –
Bene, stai scoprendo perché la classe non è stata aggiunta al framework. Anche il valore che si ottiene è tristemente sbagliato, in un processore Haswell o Broadwell dovrebbe essere il doppio del valore dato che utilizzerà i registri YMM a 256 bit forniti da AVX2. Lascia 2x perf sul tavolo, difficile da nascondere i dettagli di implementazione. AVX-512 è in arrivo :) –