示例#1
0
 /// <summary>
 ///     A comparison method used when <see cref="DoubleArray.Equals(FinanceSharp.DoubleArray)"/> is called from <see cref="IEquatable{T}"/> to compare same types of <see cref="DoubleArray"/>.
 /// </summary>
 /// <param name="other">An DoubleArray to compare to this.</param>
 /// <returns>Are <see cref="this"/> equals to <see cref="other"/>. Null returned when test was not performed.</returns>
 protected internal override bool?IsEqualExactlyTo(DoubleArray other)
 {
     return(internalArray.IsEqualExactlyTo(other));
 }
示例#2
0
 public SlicedDoubleArray(DoubleArray slicedArray, int start, int stop) : base(stop - start, slicedArray.Properties)
 {
     this.internalArray = slicedArray;
     this.start         = start;
     this.stop          = stop;
 }
示例#3
0
        /// <summary>
        ///     Performs a binary function on lhs and rhs.
        /// </summary>
        /// <param name="rhs">The rhs of the equation, 'this' is lhs.</param>
        /// <param name="function">The function to call for every value in this array.</param>
        /// <returns></returns>
        public virtual DoubleArray Function(DoubleArray rhs, BinaryFunctionHandler function)
        {
            var lhs = this;

            if (lhs.IsScalar && lhs.Properties == 1 && rhs.IsScalar && lhs.Properties == 1)
            {
                return(function(lhs.Value, rhs.Value));
            }

            DoubleArray ret;
            int         len;

            if (lhs.IsScalar && lhs.Properties == 1)
            {
                ret = rhs.Clone();
                len = ret.LinearLength;
                var lhs_val = lhs.Value;

                fixed(double *rhs_ptr = rhs, ret_ptr = ret)
                for (int i = 0; i < len; i++)
                {
                    ret_ptr[i] = function(lhs_val, rhs_ptr[i]);
                }

                return(ret);
            }
            else if (rhs.IsScalar && rhs.Properties == 1)
            {
                ret = lhs.Clone();
                len = ret.LinearLength;
                var rhsVal = rhs.Value;

                fixed(double *lhs_ptr = lhs, ret_ptr = ret)
                for (int i = 0; i < len; i++)
                {
                    ret_ptr[i] = function(lhs_ptr[i], rhsVal);
                }

                return(ret);
            }
            else
            {
                var propsLhs = lhs.LinearLength;
                var propsRhs = rhs.LinearLength;
                ret = propsLhs >= propsRhs?lhs.Clone() : rhs.Clone();

                len = ret.LinearLength;

                if (propsRhs % propsLhs != 0)
                    throw new ReshapeException($"Unable to broadcast lhs against rhs, ({propsLhs}, {propsRhs}).");
                fixed(double *lhs_ptr = rhs, rhs_ptr = rhs, ret_ptr = ret)
                if (propsRhs != propsLhs)
                {
                    for (int i = 0; i < len; i++)
                    {
                        ret_ptr[i] = function(lhs_ptr[i % propsLhs], rhs_ptr[i % propsRhs]);
                    }
                }

                else
                {
                    for (int i = 0; i < len; i++)
                    {
                        ret_ptr[i] = function(lhs_ptr[i], rhs_ptr[i]);
                    }
                }

                return(ret);
            }
        }