Page 1 of 1

Einen FloatVector umkehren (1/jedes Element)

Posted: 20 Jan 2025, 14:40
by Guest
In Java gibt es eine API namens VectorApi. Es ermöglicht die Durchführung arithmetischer Operationen für ein ganzes float[]-Array in einem einzigen CPU-Zyklus.
Zum Beispiel:

Code: Select all

FloatVector fv = FloatVector.fromArray(SPECIES, new float[]{1, 2, 3, 4, 5, 6, 7}, 0);
//multiplies the wohle array in a single cycle by 2 (if the CPU supports this)
fv.mul(2f);
Jetzt möchte ich das Ergebnis von 1f / FloatVector berechnen. Im Moment mache ich das per

Code: Select all

fv.pow(-1f);
Ich gehe davon aus, dass dies ein langsamer Vorgang sein könnte. Gibt es einen besseren Weg, dies zu tun?