Esempio n. 1
0
        public virtual DoubleArray Function(UnaryFunctionHandler function, bool copy = true)
        {
            var @this = (copy ? this.Clone() : this);

            fixed(double *arr = @this)
            {
                var len = @this.LinearLength;

                for (int i = 0; i < len; i++)
                {
                    arr[i] = function(arr[i]);
                }
            }

            return(@this);
        }
Esempio n. 2
0
        /// <summary>
        ///     Performs a math <paramref name="op"/> over <see cref="DoubleArray.Value"/> or value from <paramref name="selector"/>. The result is stored in a <see cref="Identity"/>.
        /// </summary>
        /// <param name="first">The indicator that sends data via <see cref="IUpdatable.Updated"/> even to the math <paramref name="op"/></param>
        /// <param name="op">The operation to perform on <see cref="DoubleArray.Value"/>.</param>
        /// <param name="selector">A selector to choose what <see cref="double"/> to pass to math <paramref name="op"/>. By default <see cref="DoubleArray.Value"/> is used.</param>
        /// <param name="waitForFirstToReady">First must be ready in order to push the updates forward.</param>
        /// <param name="name">Name of the new returned <see cref="Identity"/> representing the <paramref name="op"/>.</param>
        public static Identity Function(this IUpdatable first, UnaryFunctionHandler op, SelectorFunctionHandler selector = null, bool waitForFirstToReady = true, string name = null)
        {
            if (op == null)
            {
                throw new ArgumentNullException(nameof(op));
            }

            var idn = new Identity(ResolveName(first, name));


            if (selector == null)
            {
                if (waitForFirstToReady)
                {
                    first.Updated += (time, updated) => {
                        if (first.IsReady)
                        {
                            idn.Update(time, op(updated.Value));
                        }
                    };
                }
                else
                {
                    first.Updated += (time, updated) => idn.Update(time, op(updated.Value));
                }
            }
            else
            {
                if (waitForFirstToReady)
                {
                    first.Updated += (time, updated) => {
                        if (first.IsReady)
                        {
                            idn.Update(time, new DoubleArrayScalar(op(selector(updated))));
                        }
                    };
                }
                else
                {
                    first.Updated += (time, updated) => idn.Update(time, new DoubleArrayScalar(op(selector(updated))));
                }
            }

            first.Resetted += sender => idn.Reset();

            return(idn);
        }
Esempio n. 3
0
        public virtual DoubleArray Function(int property, UnaryFunctionHandler function, bool copy = true)
        {
            var @this = (copy ? this.Clone() : this);

            fixed(double *src = @this)
            {
                var len    = @this.Count;
                var props  = @this.Properties;
                int offset = property;

                for (int i = 0; i < len; i++, offset += props)
                {
                    src[offset] = function(src[offset]);
                }
            }

            return(@this);
        }