/// <summary> /// Create a new sparse vector and initialize each value using the provided init function. /// </summary> public static Vector <T> Sparse <T>(int length, Func <int, T> init) where T : struct, IEquatable <T>, IFormattable { VectorBuilder <T> v_builder = BuilderInstance <T> .Vector; return(v_builder.Sparse(length, init)); }
/// <summary> /// Create a new sparse vector straight from an initialized vector storage instance. /// The storage is used directly without copying. /// Intended for advanced scenarios where you're working directly with /// storage for performance or interop reasons. /// </summary> /// <summary> /// Create a sparse vector of T with the given size. /// </summary> /// <param name="size">The size of the vector.</param> public static Vector <T> Sparse <T>(int size) where T : struct, IEquatable <T>, IFormattable { VectorBuilder <T> v_builder = BuilderInstance <T> .Vector; return(v_builder.Sparse(size)); }
/// <summary> /// Create a vector of the same kind with the provided dimension. /// </summary> /// <param name="size">The size of the vector.</param> /// <remarks>Creates a vector of the same type as the current matrix.</remarks> public Vector <T> CreateVector(int size) { return(Storage.IsDense ? Build.Dense(size) : Build.Sparse(size)); }