simdMul
simdMul multiplica los elementos correspondientes de dos arrays del mismo tamaño y devuelve un array nuevo dentro de Result<T[], SimdError>.
Firma
simdMul<T>(left: T[], right: T[]): Result<T[], SimdError>tyrus
import { simdMul, SimdError } from "tyrus:simd";
const left: f32[] = [2.0, 3.0, 4.0, 5.0, 6.0];
const right: f32[] = [3.0, 4.0, 5.0, 6.0, 7.0];
const result: Result<f32[], SimdError> = simdMul(left, right);
match (result) {
Ok(values) => {
print(values); // [6.0, 12.0, 20.0, 30.0, 42.0]
}
Err(error) => {
printError(error.code, error.message);
}
}Los tipos aceptados son i8, i16, i32, i64, u8, u16, u32, u64, f32 y f64. La multiplicación de enteros con y sin signo usa wrap por defecto según el ancho del elemento; por ejemplo, multiplicar 255 por 2 como u8 da 254. Los literales enteros deben caber en el tipo declarado para los elementos. Las diferencias de tamaño dinámico y los fallos al asignar el resultado devuelven SimdError. Los arrays fijos con longitudes diferentes se rechazan con E0308 en compilación.
Errores
error
tyrus
import { simdMul, SimdError } from "tyrus:simd";
const left: i32[] = [1, 2];
const right: i32[] = [3, 4, 5];
const result: Result<i32[], SimdError> = simdMul(left, right);
match (result) {
Ok(_) => {}
Err(error) => { printError(error.code, error.message); }
}text
ERR_SIMD_LENGTH_MISMATCH simdMul requires arrays of equal lengtherror
tyrus
import { simdMul } from "tyrus:simd";
const left: i32[] = [1, 2];
const right: i64[] = [3, 4];
const result = simdMul(left, right); text
error[E0308]: type mismatch for argument 2 of `simdMul`: expected `i32[]`, found `i64[]`
at /src/main.tyr:5:16
const result = simdMul(left, right);
^^^^^^^