Vector.fromSimdList constructor
Creates a vector from a simd-typed collection. It accepts only Float32x4List or Float64x2List lists as a source.
Warning: The vector shares the underlying buffer with source; it
does not copy the values. Mutating source can change this vector and
leave cached values stale.
Avoid modifying source while using the vector.
A usage example:
import 'dart:typed_data';
import 'package:ml_linalg/vector.dart';
final source1 = Float64x2List.fromList([1, 2, 3, 4, 5]);
final source2 = Float32x4List.fromList([1, 2, 3, 4, 5]);
final vector1 = Vector.fromSimdList(source1, 5, dtype: DType.float64);
final vector2 = Vector.fromSimdList(source2, 5, dtype: DType.float32);
print(vector1);
print(vector2);
the output will be like that:
(1.0, 2.0, 3.0, 4.0, 5.0)
(1.0, 2.0, 3.0, 4.0, 5.0)
Implementation
factory Vector.fromSimdList(
List source,
int actualLength, {
DType dtype = DType.float32,
}) {
switch (dtype) {
case DType.float32:
return Float32x4Vector.fromSimdList(
source as Float32x4List,
actualLength,
CacheManagerFactoryImpl().create(vectorCacheKeys),
const Float32x4Helper(),
);
case DType.float64:
return Float64x2Vector.fromSimdList(
source as Float64x2List,
actualLength,
CacheManagerFactoryImpl().create(vectorCacheKeys),
const Float64x2Helper(),
);
default:
throw UnimplementedError(
'Vector of $dtype type is not implemented yet');
}
}