Exemplo n.º 1
0
        /// <summary>
        ///     Saves <see cref="NdArray{String}"/> instance to .npy binary.
        /// </summary>
        /// <param name="stream"></param>
        /// <param name="ndArray"></param>
        /// <exception cref="NotSupportedException"></exception>
        public static void Save(Stream stream, NdArray <string> ndArray)
        {
            var temp   = ndArray.Select(x => Encoding.UTF32.GetBytes(x));
            var maxlen = temp.AsEnumerable().Select(x => x.Length).Max();

            SaveCore(stream, temp, new DType($"<U{maxlen / 4}"), (i, buf) =>
            {
                var buffer = temp.GetItem(i);
                Buffer.BlockCopy(buffer, 0, buf, i * maxlen, buffer.Length);
            });
        }
Exemplo n.º 2
0
        public void SuccessfulLegacy(NdArray <int> x, NdArray <int> y,
                                     NdArray <int> answer)
        {
            void core <T>(NdArray <T> x, NdArray <T> y, NdArray <T> answer)
            {
                Assert.Equal(answer, NdLinAlg.DotLegacy(x, y));
            }

            core(x.Select(t => (byte   )t), y.Select(t => (byte   )t), answer.Select(t => (byte   )t));
            core(x.Select(t => (ushort )t), y.Select(t => (ushort )t), answer.Select(t => (ushort )t));
            core(x.Select(t => (uint   )t), y.Select(t => (uint   )t), answer.Select(t => (uint   )t));
            core(x.Select(t => (ulong  )t), y.Select(t => (ulong  )t), answer.Select(t => (ulong  )t));
            core(x.Select(t => (sbyte  )t), y.Select(t => (sbyte  )t), answer.Select(t => (sbyte  )t));
            core(x.Select(t => (short  )t), y.Select(t => (short  )t), answer.Select(t => (short  )t));
            core(x.Select(t => (int    )t), y.Select(t => (int    )t), answer.Select(t => (int    )t));
            core(x.Select(t => (long   )t), y.Select(t => (long   )t), answer.Select(t => (long   )t));
            core(x.Select(t => (float  )t), y.Select(t => (float  )t), answer.Select(t => (float  )t));
            core(x.Select(t => (double )t), y.Select(t => (double )t), answer.Select(t => (double )t));
            core(x.Select(t => (decimal)t), y.Select(t => (decimal)t), answer.Select(t => (decimal)t));
            core(x.Select(t => (Complex)t), y.Select(t => (Complex)t), answer.Select(t => (Complex)t));
        }
Exemplo n.º 3
0
 /// <summary>
 ///     [Pure] Projects each element of a NdArray into a new form.
 /// </summary>
 /// <typeparam name="TSource"> The type of the elements of <paramref name="ndarray"/>. </typeparam>
 /// <typeparam name="TResult"> The type of the value returned by <paramref name="selector"/>. </typeparam>
 /// <param name="ndarray"> A NdArray for values to invoke a transform function on. </param>
 /// <param name="selector"> A transform function to apply to each element. </param>
 /// <returns> [<c>$ReturnValue.Shape == NdArray.Shape</c>] </returns>
 public static NdArray <TResult> Select <TSource, TResult>(
     this NdArray <TSource> ndarray,
     Func <TSource, TResult> selector)
 => ndarray.Select(selector, default);