// // Math.NET Numerics, part of the Math.NET Project // http://numerics.mathdotnet.com // http://github.com/mathnet/mathnet-numerics // // Copyright (c) 2009-2015 Math.NET // // Permission is hereby granted, free of charge, to any person // obtaining a copy of this software and associated documentation // files (the "Software"), to deal in the Software without // restriction, including without limitation the rights to use, // copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the // Software is furnished to do so, subject to the following // conditions: // // The above copyright notice and this permission notice shall be // included in all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR // OTHER DEALINGS IN THE SOFTWARE. // using System; using System.Collections.Generic; using IStation.Numerics.Distributions; using IStation.Numerics.LinearAlgebra.Storage; namespace IStation.Numerics.LinearAlgebra { public static class CreateVector { /// /// Create a new vector straight from an initialized matrix storage instance. /// If you have an instance of a discrete storage type instead, use their direct methods instead. /// public static Vector WithStorage(VectorStorage storage) where T : struct, IEquatable, IFormattable { return Vector.Build.OfStorage(storage); } /// /// Create a new vector with the same kind of the provided example. /// public static Vector SameAs(Vector example, int length) where T : struct, IEquatable, IFormattable where TU : struct, IEquatable, IFormattable { return Vector.Build.SameAs(example, length); } /// /// Create a new vector with the same kind and dimension of the provided example. /// public static Vector SameAs(Vector example) where T : struct, IEquatable, IFormattable where TU : struct, IEquatable, IFormattable { return Vector.Build.SameAs(example); } /// /// Create a new vector with the same kind of the provided example. /// public static Vector SameAs(Matrix example, int length) where T : struct, IEquatable, IFormattable where TU : struct, IEquatable, IFormattable { return Vector.Build.SameAs(example, length); } /// /// Create a new vector with a type that can represent and is closest to both provided samples. /// public static Vector SameAs(Vector example, Vector otherExample, int length) where T : struct, IEquatable, IFormattable { return Vector.Build.SameAs(example, otherExample, length); } /// /// Create a new vector with a type that can represent and is closest to both provided samples and the dimensions of example. /// public static Vector SameAs(Vector example, Vector otherExample) where T : struct, IEquatable, IFormattable { return Vector.Build.SameAs(example, otherExample); } /// /// Create a new vector with a type that can represent and is closest to both provided samples. /// public static Vector SameAs(Matrix matrix, Vector vector, int length) where T : struct, IEquatable, IFormattable { return Vector.Build.SameAs(matrix, vector, length); } /// /// Create a new dense vector with values sampled from the provided random distribution. /// public static Vector Random(int length, IContinuousDistribution distribution) where T : struct, IEquatable, IFormattable { return Vector.Build.Random(length, distribution); } /// /// Create a new dense vector with values sampled from the standard distribution with a system random source. /// public static Vector Random(int length) where T : struct, IEquatable, IFormattable { return Vector.Build.Random(length); } /// /// Create a new dense vector with values sampled from the standard distribution with a system random source. /// public static Vector Random(int length, int seed) where T : struct, IEquatable, IFormattable { return Vector.Build.Random(length, seed); } /// /// Create a new dense 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. /// public static Vector Dense(DenseVectorStorage storage) where T : struct, IEquatable, IFormattable { return Vector.Build.Dense(storage); } /// /// Create a dense vector of T with the given size. /// /// The size of the vector. public static Vector Dense(int size) where T : struct, IEquatable, IFormattable { return Vector.Build.Dense(size); } /// /// Create a dense vector of T that is directly bound to the specified array. /// public static Vector Dense(T[] array) where T : struct, IEquatable, IFormattable { return Vector.Build.Dense(array); } /// /// Create a new dense vector and initialize each value using the provided value. /// public static Vector Dense(int length, T value) where T : struct, IEquatable, IFormattable { return Vector.Build.Dense(length, value); } /// /// Create a new dense vector and initialize each value using the provided init function. /// public static Vector Dense(int length, Func init) where T : struct, IEquatable, IFormattable { return Vector.Build.Dense(length, init); } /// /// Create a new dense vector as a copy of the given other vector. /// This new vector will be independent from the other vector. /// A new memory block will be allocated for storing the vector. /// public static Vector DenseOfVector(Vector vector) where T : struct, IEquatable, IFormattable { return Vector.Build.DenseOfVector(vector); } /// /// Create a new dense vector as a copy of the given array. /// This new vector will be independent from the array. /// A new memory block will be allocated for storing the vector. /// public static Vector DenseOfArray(T[] array) where T : struct, IEquatable, IFormattable { return Vector.Build.DenseOfArray(array); } /// /// Create a new dense vector as a copy of the given enumerable. /// This new vector will be independent from the enumerable. /// A new memory block will be allocated for storing the vector. /// public static Vector DenseOfEnumerable(IEnumerable enumerable) where T : struct, IEquatable, IFormattable { return Vector.Build.DenseOfEnumerable(enumerable); } /// /// Create a new dense vector as a copy of the given indexed enumerable. /// Keys must be provided at most once, zero is assumed if a key is omitted. /// This new vector will be independent from the enumerable. /// A new memory block will be allocated for storing the vector. /// public static Vector DenseOfIndexed(int length, IEnumerable> enumerable) where T : struct, IEquatable, IFormattable { return Vector.Build.DenseOfIndexed(length, enumerable); } /// /// 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. /// public static Vector Sparse(SparseVectorStorage storage) where T : struct, IEquatable, IFormattable { return Vector.Build.Sparse(storage); } /// /// Create a sparse vector of T with the given size. /// /// The size of the vector. public static Vector Sparse(int size) where T : struct, IEquatable, IFormattable { return Vector.Build.Sparse(size); } /// /// Create a new sparse vector and initialize each value using the provided value. /// public static Vector Sparse(int length, T value) where T : struct, IEquatable, IFormattable { return Vector.Build.Sparse(length, value); } /// /// Create a new sparse vector and initialize each value using the provided init function. /// public static Vector Sparse(int length, Func init) where T : struct, IEquatable, IFormattable { return Vector.Build.Sparse(length, init); } /// /// Create a new sparse vector as a copy of the given other vector. /// This new vector will be independent from the other vector. /// A new memory block will be allocated for storing the vector. /// public static Vector SparseOfVector(Vector vector) where T : struct, IEquatable, IFormattable { return Vector.Build.SparseOfVector(vector); } /// /// Create a new sparse vector as a copy of the given array. /// This new vector will be independent from the array. /// A new memory block will be allocated for storing the vector. /// public static Vector SparseOfArray(T[] array) where T : struct, IEquatable, IFormattable { return Vector.Build.SparseOfArray(array); } /// /// Create a new sparse vector as a copy of the given enumerable. /// This new vector will be independent from the enumerable. /// A new memory block will be allocated for storing the vector. /// public static Vector SparseOfEnumerable(IEnumerable enumerable) where T : struct, IEquatable, IFormattable { return Vector.Build.SparseOfEnumerable(enumerable); } /// /// Create a new sparse vector as a copy of the given indexed enumerable. /// Keys must be provided at most once, zero is assumed if a key is omitted. /// This new vector will be independent from the enumerable. /// A new memory block will be allocated for storing the vector. /// public static Vector SparseOfIndexed(int length, IEnumerable> enumerable) where T : struct, IEquatable, IFormattable { return Vector.Build.SparseOfIndexed(length, enumerable); } } }