using System; using System.Collections.Generic; using System.Linq; using System.Text; using UnitTestSharp; using Azimuth.DenseLinearAlgebra; using Azimuth.SparseLinearAlgebra; namespace Azimuth.UnitTests.SparseLinearAlgebra { public class CirculantMatrixTests : UnitTestSharp.TestFixture { public void Basic_x8() { DenseVector circulant = new Scalar[] { 0, 1, 2, 3, 4, 5, 6, 7, }; DenseVector b = new Scalar[] { 1, 1, 1, 1, 2, 2, 2, 2 }; var C = new CirculantMatrix(circulant); C.SolveSystem(b, ref b); var expected = new DenseVector(new Scalar[] { 0.0535714285714286, 0.0535714285714286, 0.0535714285714286, 0.1785714285714286, 0.0535714285714286, 0.0535714285714286, 0.0535714285714286, -0.0714285714285715, }); CheckEqual(expected, b); } public void NonPowerOf2() { var circulant = new DenseVector(new Scalar[] { 0, 1, 2, 3, 4, }); var b = new DenseVector(new Scalar[] { 1, 1, 1, 1, 2, }); var C = new CirculantMatrix(circulant); C.SolveSystem(b, ref b); var expected = new DenseVector(new Scalar[] { .12, .12, .12, .32, -0.08, }); CheckEqual(expected, b); } public void SizeMismatch() { var circulant = new DenseVector(new Scalar[] { 0, 1, 2, 3, }); var b = new DenseVector(new Scalar[] { 1, 1, 1, }); var x = new DenseVector(4); var C = new CirculantMatrix(circulant); CheckThrow(typeof(Exception)); C.SolveSystem(b, ref x); } } }