public void It_will_not_throw_with_equal_ordered_lists()
 {
     IList<string> lhs = new List<string>(3){ item0, item1, item2 };
     IList<string> rhs = new List<string>(3){ item0, item1, item2 };
     KeyCompatibilityValidator<string, string> SUT = new KeyCompatibilityValidator<string, string>(lhs, rhs);
     SUT.ThrowIfInvalid();
 }
Exemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="other"></param>
        /// <returns></returns>
        public KeyedVector <TKey> CrossProduct(KeyedVector <TKey> other)
        {
            Guard.AgainstNullArgument(other, "other");
            Guard.AgainstBadArgument(
                "other",
                () => { return(other.Count != 3); },
                "Cross product can only be carried out with a 3 dimensional vector");
            Guard.AgainstInvalidState(
                () => { return(this.Count != 3); },
                "Cross product can only be carried out with a 3 dimensional vector. Number of dimensions of this vectors are {0}",
                this.Count);

            KeyCompatibilityValidator <TKey, TKey> kcv = new KeyCompatibilityValidator <TKey, TKey>(this.Keys, other.Keys);

            kcv.ThrowIfInvalid();
            ////TODO If the keys match but are in the wrong order, swap the other vector items and keys to match exactly

            IList <TKey> keyz = this.Keys;
            TKey         key0 = keyz[0];
            TKey         key1 = keyz[1];
            TKey         key2 = keyz[2];

            KeyedVector <TKey> result = new KeyedVector <TKey>(keyz);

            result[key0] = (this[key1] * other[key2]) - (this[key2] * other[key1]);
            result[key1] = (this[key2] * other[key0]) - (this[key0] * other[key2]);
            result[key2] = (this[key0] * other[key1]) - (this[key1] * other[key0]);

            return(result);
        }
Exemplo n.º 3
0
        public double DotProduct(KeyedVector <TKey> other)
        {
            KeyCompatibilityValidator <TKey, TKey> kcv = new KeyCompatibilityValidator <TKey, TKey>(this.Keys, other.Keys);

            kcv.ThrowIfInvalid();

            double sum = 0.0;

            sum = this.store.Sum(kvp => kvp.Value * other[kvp.Key]);

            return(sum);
        }
Exemplo n.º 4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="rightSide"></param>
        /// <returns></returns>
        public KeyedVector <TRowKey> Multiply(KeyedVector <TColumnKey> rightSide)
        {
            KeyCompatibilityValidator <TColumnKey, TColumnKey> kcv = new KeyCompatibilityValidator <TColumnKey, TColumnKey>(this.ColumnKeys, rightSide.Keys);

            kcv.ThrowIfInvalid();

            ////FIXME If the column keys and vector keys are compatible but are stored or returned in the wrong order then this will return the wrong results.  Need to swap the vector items and keys to match exactly

            Vector <double> result = this.underlyingMatrix.Multiply(rightSide.ToVector());

            return(new KeyedVector <TRowKey>(this.RowKeys, result));
        }
Exemplo n.º 5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="other"></param>
        /// <returns></returns>
        public KeyedRowColumnMatrix <TRowKey, TOtherColumnKey> Multiply <TOtherRowKey, TOtherColumnKey>(KeyedRowColumnMatrix <TOtherRowKey, TOtherColumnKey> other)
        {
            KeyCompatibilityValidator <TColumnKey, TOtherRowKey> kcv = new KeyCompatibilityValidator <TColumnKey, TOtherRowKey>(this.ColumnKeys, other.RowKeys);

            kcv.ThrowIfInvalid();

            ////FIXME If the column keys and other row keys are compatible but are stored or returned in the wrong order then this will return the wrong results.  Need to swap the vector items and keys to match exactly

            Matrix <double> multipliedUnderlyingMatrix = this.underlyingMatrix.Multiply(other.underlyingMatrix);

            return(new KeyedRowColumnMatrix <TRowKey, TOtherColumnKey>(this.keysForRows, other.keysForColumns, multipliedUnderlyingMatrix));
        }
Exemplo n.º 6
0
        public void It_will_not_throw_with_equal_ordered_lists()
        {
            IList <string> lhs = new List <string>(3)
            {
                item0, item1, item2
            };
            IList <string> rhs = new List <string>(3)
            {
                item0, item1, item2
            };
            KeyCompatibilityValidator <string, string> SUT = new KeyCompatibilityValidator <string, string>(lhs, rhs);

            SUT.ThrowIfInvalid();
        }
Exemplo n.º 7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="other"></param>
        /// <returns></returns>
        public KeyedVector <TKey> Add(KeyedVector <TKey> other)
        {
            var kcv = new KeyCompatibilityValidator <TKey, TKey>(this.Keys, other.Keys);

            kcv.ThrowIfInvalid();

            IList <TKey>       keyz   = this.Keys;
            KeyedVector <TKey> result = Clone();

            foreach (TKey key in keyz)
            {
                result[key] += other[key];
            }
            return(result);
        }
 public void It_will_throw_if_lists_are_of_the_wrong_length()
 {
     IList<string> lhs = new List<string>(3){ item0, item1, item2, item3 };
     IList<string> rhs = new List<string>(3){ item0, item1, item2 };
     KeyCompatibilityValidator<string, string> SUT = new KeyCompatibilityValidator<string, string>(lhs, rhs);
     try
     {
         SUT.ThrowIfInvalid();
     }
     catch(ArgumentException e)
     {
         Console.WriteLine(e.Message);
         throw e;
     }
 }
Exemplo n.º 9
0
        public void It_will_throw_if_lists_are_of_the_wrong_length()
        {
            IList <string> lhs = new List <string>(3)
            {
                item0, item1, item2, item3
            };
            IList <string> rhs = new List <string>(3)
            {
                item0, item1, item2
            };
            KeyCompatibilityValidator <string, string> SUT = new KeyCompatibilityValidator <string, string>(lhs, rhs);

            try
            {
                SUT.ThrowIfInvalid();
            }
            catch (ArgumentException e)
            {
                Console.WriteLine(e.Message);
                throw e;
            }
        }
Exemplo n.º 10
0
        public void It_will_throw_with_null_item_in_lhs()
        {
            IList <string> lhs = new List <string>(3)
            {
                item0, item1, null
            };
            IList <string> rhs = new List <string>(3)
            {
                item0, item1, item2
            };
            KeyCompatibilityValidator <string, string> SUT = new KeyCompatibilityValidator <string, string>(lhs, rhs);

            try
            {
                SUT.ThrowIfInvalid();
            }
            catch (ArgumentException e)
            {
                Console.WriteLine(e.Message);
                throw e;
            }
        }
 public void It_will_throw_with_null_item_in_lhs()
 {
     IList<string> lhs = new List<string>(3){ item0, item1, null };
     IList<string> rhs = new List<string>(3){ item0, item1, item2 };
     KeyCompatibilityValidator<string, string> SUT = new KeyCompatibilityValidator<string, string>(lhs, rhs);
     try
     {
         SUT.ThrowIfInvalid();
     }
     catch(ArgumentException e)
     {
         Console.WriteLine(e.Message);
         throw e;
     }
 }