Example #1
0
        /// <summary>
        /// Creates an initializer that is defined by the given element type.
        /// </summary>
        /// <typeparam name="T">The element type.</typeparam>
        /// <typeparam name="TStride">The 1D stride of the target view.</typeparam>
        /// <param name="accelerator">The accelerator.</param>
        /// <returns>The loaded transformer.</returns>
        public static Initializer <T, TStride> CreateInitializer <T, TStride>(
            this Accelerator accelerator)
            where T : unmanaged
            where TStride : struct, IStride1D
        {
            var rawInitializer = accelerator.CreateRawInitializer <T, TStride>();

            return((stream, view, value) =>
            {
                if (!view.IsValid)
                {
                    throw new ArgumentNullException(nameof(view));
                }
                if (view.Length < 1)
                {
                    throw new ArgumentOutOfRangeException(nameof(view));
                }

                rawInitializer(
                    stream,
                    view.Length,
                    new InitializerImplementation <T, TStride>(
                        view,
                        value));
            });
        }