当前位置: 首页>>代码示例>>C#>>正文


C# Vector.InnerProduct方法代码示例

本文整理汇总了C#中Vector.InnerProduct方法的典型用法代码示例。如果您正苦于以下问题:C# Vector.InnerProduct方法的具体用法?C# Vector.InnerProduct怎么用?C# Vector.InnerProduct使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Vector的用法示例。


在下文中一共展示了Vector.InnerProduct方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SimpleInnerProduct

        public void SimpleInnerProduct()
        {
            Vector vector1 = new Vector(new double[] { 1.0, 2.0, 3.0 });
            Vector vector2 = new Vector(new double[] { 4.0, 5.0, 6.0 });

            double result = vector1.InnerProduct(vector2);
            Assert.AreEqual((1.0 * 4.0) + (2.0 * 5.0) + (3.0 * 6.0), result);
        }
开发者ID:ajlopez,项目名称:MathelSharp,代码行数:8,代码来源:VectorTests.cs

示例2: InnerProductRaiseExceptionIfVectorsHaveDifferenteLengths

        public void InnerProductRaiseExceptionIfVectorsHaveDifferenteLengths()
        {
            Vector vector1 = new Vector(new double[] { 1.0, 2.0, 3.0 });
            Vector vector2 = new Vector(new double[] { 4.0, 5.0, 6.0, 7.0 });

            try
            {
                vector1.InnerProduct(vector2);
                Assert.Fail();
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(ex, typeof(InvalidOperationException));
                Assert.AreEqual("Vectors have different lengths", ex.Message);
            }
        }
开发者ID:ajlopez,项目名称:MathelSharp,代码行数:16,代码来源:VectorTests.cs

示例3: vector_inner_product_throws_error_when_orientation_is_the_same

    public void vector_inner_product_throws_error_when_orientation_is_the_same()
    {
      var v1 = new Vector<int>(new int[] { 1, 2, 3 }, Orientation.Row
        , AdditiveMonoid.IntAdditionMonoid, MultiplicativeMonoid.IntMultiplicationMonoid);
      var v2 = new Vector<int>(new int[] { 1, 2, 3 }, Orientation.Row
        , AdditiveMonoid.IntAdditionMonoid, MultiplicativeMonoid.IntMultiplicationMonoid);

      var ex = Assert.Throws<ArgumentException>(() => v1.InnerProduct(v2));
      Assert.That(ex.Message, Is.EqualTo("Vector<T>.InnerProduct - dot product requires a row vector followed by a column vector"));
    }
开发者ID:JoeDumoulin,项目名称:Algebraic.Net,代码行数:10,代码来源:VectorTests.cs

示例4: vector_inner_product_throws_error_when_vectors_have_different_length

    public void vector_inner_product_throws_error_when_vectors_have_different_length()
    {
      var v1 = new Vector<int>(new int[] { 1, 2, 3 }, Orientation.Row
        , AdditiveMonoid.IntAdditionMonoid, MultiplicativeMonoid.IntMultiplicationMonoid);
      var v2 = new Vector<int>(new int[] { 1, 2, 3, 4 }, Orientation.Column
        , AdditiveMonoid.IntAdditionMonoid, MultiplicativeMonoid.IntMultiplicationMonoid);

      var ex = Assert.Throws<ArgumentException>(() => v1.InnerProduct(v2));
      Assert.That(ex.Message, Is.EqualTo("Vector<T>.InnerProduct - vectors must have equal length"));
    }
开发者ID:JoeDumoulin,项目名称:Algebraic.Net,代码行数:10,代码来源:VectorTests.cs

示例5: vector_created_with_semiring_inner_product_produces_2norm

    public void vector_created_with_semiring_inner_product_produces_2norm()
    {
      var v1 = new Vector<int>(new int[] { 1, 2, 3 }, Orientation.Row
        , new SemiRing<int>(AdditiveMonoid.IntAdditionMonoid, MultiplicativeMonoid.IntMultiplicationMonoid));
      var v2 = new Vector<int>(new int[] { 1, 2, 3 }, Orientation.Column
        , new SemiRing<int>(AdditiveMonoid.IntAdditionMonoid, MultiplicativeMonoid.IntMultiplicationMonoid));

      Assert.That(v1.InnerProduct(v2), Is.EqualTo(14));
    }
开发者ID:JoeDumoulin,项目名称:Algebraic.Net,代码行数:9,代码来源:VectorTests.cs


注:本文中的Vector.InnerProduct方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。