Example #1
0
        /// <summary>
        ///     Gets the identity matrix which has the specified dimension.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="n"></param>
        /// <returns></returns>
        public static NdArray <T> Identity <T>(int n)
        {
            var array = NdArray.CreateMutable(new T[n, n]);

            for (var i = 0; i < n; ++i)
            {
                array[i, i] = ValueTrait.One <T>();
            }

            return(array.MoveToImmutable());
        }
        public static Vector <T> GetVector <T>()
            where T : unmanaged
        {
            Span <T> span = stackalloc T[Vector <T> .Count];
            var      x    = ValueTrait.UnaryNegate(ValueTrait.One <T>());

            for (var i = 0; i < Vector <T> .Count; ++i)
            {
                span[i] = x;
                x       = ValueTrait.Increment(x);
            }
            return(new Vector <T>(span));
        }