Exemple #1
0
 /// <inheritdoc/>
 public bool Equals([AllowNull] DpiScale other)
 {
     return
         (other != null &&
          Precision.AlmostEqual(other.DpiScaleX, this.DpiScaleX) &&
          Precision.AlmostEqual(other.DpiScaleY, this.DpiScaleY));
 }
Exemple #2
0
        public void DCTestCircuit_SolveX()
        {
            var builder = Vector <double> .Build;
            var testCkt = DCTestCircuit();

            double[] shouldArr = { -8, 24, 20, -4, 1 };
            var      should    = builder.DenseOfArray(shouldArr);

            Assert.True(Precision.AlmostEqual(DCAnalysis.SolveX(testCkt), should, 8));
        }
Exemple #3
0
        public void DCTestCircuit_GenZ()
        {
            var builder = Vector <double> .Build;
            var testCkt = DCTestCircuit();

            double[] shouldArr = { 0, 0, 0, 32, 20 };
            var      should    = builder.DenseOfArray(shouldArr);

            Assert.True(Precision.AlmostEqual(DCAnalysis.GenZ(testCkt), should, 8));
        }
Exemple #4
0
        /*
         * Determines whether the specified quantum gate is equal to the current quantum gate, ignoring floating-point precision issues
         */
        public bool AlmostEquals(object obj)
        {
            QuantumGate quantumGate = obj as QuantumGate;

            if (quantumGate == null || this.Matrix.ColumnCount != quantumGate.Matrix.ColumnCount || this.Matrix.RowCount != quantumGate.Matrix.RowCount)
            {
                return(false);
            }

            return(Precision.AlmostEqual <Complex>(this.Matrix, quantumGate.Matrix, 15));
        }
Exemple #5
0
        /*
         * Determines whether the specified quantum register is equal to the current quantum register, ignoring floating-point precision issues
         */
        public bool AlmostEquals(object obj)
        {
            QuantumRegister quantumRegister = obj as QuantumRegister;

            if (quantumRegister == null || this.Vector.Count != quantumRegister.Vector.Count)
            {
                return(false);
            }

            return(Precision.AlmostEqual <Complex>(this.Vector, quantumRegister.Vector, 15));
        }
Exemple #6
0
        /// <summary>
        /// Checks whether two Buckets are equal; this method tolerates a difference in lowerbound, upperbound
        /// and count given by <seealso cref="Precision.AlmostEqual(double,double)"/>.
        /// </summary>
        public override bool Equals(object obj)
        {
            if (!(obj is Bucket))
            {
                return(false);
            }

            Bucket b = (Bucket)obj;

            return(Precision.AlmostEqual(this.LowerBound, b.LowerBound) &&
                   Precision.AlmostEqual(this.UpperBound, b.UpperBound) &&
                   Precision.AlmostEqual(this.Count, b.Count));
        }
        private Vector FindNearestNeighbour(Vector location,
                                            KdTreeNode node, Vector bestValue, float bestDistance, int depth)
        {
            if (node == null) // no where left to search, return best value
            {
                return(bestValue);
            }

            var dimension = depth % this.Dimensionality;
            var nodeValue = node.Value;
            var distance  = (nodeValue - location).Norm(this.Dimensionality);

            // Check if current node is better than best node.
            // Current node cannot be same as search location.
            if (!Precision.AlmostEqual(distance, 0) &&
                (distance < bestDistance))
            {
                bestValue    = nodeValue;
                bestDistance = distance;
            }

            // Check for best node in sub-tree of near child. i.e., which side of Node is the query point?
            var nearChildNode = (location[dimension] < nodeValue[dimension]) ?
                                node.LeftChild : node.RightChild;

            if (nearChildNode != null)
            {
                var nearBestValue    = FindNearestNeighbour(location, nearChildNode, bestValue, bestDistance, depth + 1);
                var nearBestDistance = (nearBestValue - location).Norm(this.Dimensionality);
                bestValue    = nearBestValue;
                bestDistance = nearBestDistance;
            }

            // Check whether splitting hyperplane given by current node intersects with hypersphere of current smallest
            // distance around given location.
            if (bestDistance > Math.Abs(nodeValue[dimension] - location[dimension]))
            {
                // Check for best node in sub-tree of far child.
                var farChildNode = nearChildNode == node.LeftChild ? node.RightChild : node.LeftChild; // i.e. not the near child

                if (farChildNode != null)
                {
                    var farBestValue    = FindNearestNeighbour(location, farChildNode, bestValue, bestDistance, depth + 1);
                    var farBestDistance = (farBestValue - location).Norm(this.Dimensionality);
                    bestValue    = farBestValue;
                    bestDistance = farBestDistance;
                }
            }

            return(bestValue);
        }
Exemple #8
0
        public void DCTestCircuit_GenA()
        {
            var builder = Matrix <double> .Build;
            var testCkt = DCTestCircuit();

            double[,] shouldArr =
            {
                { 0.5,     0,     0, -1, 0 },
                {   0, 0.375, -0.25,  1, 0 },
                {   0, -0.25,  0.25,  0, 1 },
                {  -1,     1,     0,  0, 0 },
                {   0,     0,     1,  0, 0 },
            };
            var should = builder.DenseOfArray(shouldArr);

            Assert.True(Precision.AlmostEqual(DCAnalysis.GenA(testCkt), should, 8));
        }
        static void TestACISource()
        {
            var ckt  = ACISourceTestCircuit();
            var data = new TransientAnalysisData(ckt, 1E-2, 2);

            TransientAnalysis.Analyze(ckt, ref data);
            var dataVList = new List <double>();

            foreach (var item in data.Result)
            {
                dataVList.Add(item[0]);
            }
            double[] dataV = dataVList.ToArray();

            double[] shouldDataV =
            {
                2,
                2,
                2,
                2,
                2,
                1.2928932188134525,
                1.4909585842496287,
                1.7210088939607708,
                1.9685892409218717,
                2.2181432413965423,
                2.4539904997395467,
                2.6613118653236514,
                2.8270805742745617,
                2.940880768954225,
                2.99556196460308,
                2.9876883405951378,
                2.9177546256839815,
                2.79015501237569,
                2.612907053652976,
                2.39714789063478,
            };

            for (int i = 0; i < 20; i++)
            {
                Assert.True(Precision.AlmostEqual(dataV[i], shouldDataV[i], 8));
            }
        }
        static void RLTestCircuit_TransAnalysis()
        {
            var ckt  = RLTestCircuit();
            var data = new TransientAnalysisData(ckt, 1E-5, 6E-3);

            TransientAnalysis.Analyze(ckt, ref data);
            var dataVList = new List <double>();

            foreach (var item in data.Result)
            {
                dataVList.Add(item[0] - item[1]);
            }
            double[] dataV = dataVList.ToArray();

            double[] shouldDataV =
            {
                0,
                0.009900990099009901,
                0.019703950593079108,
                0.029409852072355552,
                0.039019655517183706,
                0.048534312393251185,
                0.057954764745793245,
                0.06728194529286459,
                0.0765167775176877,
                0.08566017576008682,
                0.09471304530701664,
                0.10367628248219468,
                0.1125507747348462,
                0.12133740072757047,
                0.13003703042333706,
                0.13865052517162083,
                0.14717873779368396,
                0.1556225126670138,
                0.16398268580892456,
                0.1722600849593312,
            };

            for (int i = 0; i < 20; i++)
            {
                Assert.True(Precision.AlmostEqual(dataV[i], shouldDataV[i], 8));
            }
        }
Exemple #11
0
        /// <summary>
        /// Comparison of two disjoint buckets. The buckets cannot be overlapping.
        /// </summary>
        public int CompareTo(Bucket bucket)
        {
            if (this.UpperBound > bucket.LowerBound && this.LowerBound < bucket.LowerBound)
            {
                throw new ArgumentException(Resources.PartialOrderException);
            }

            if (Precision.AlmostEqual(this.UpperBound, bucket.UpperBound) &&
                Precision.AlmostEqual(this.LowerBound, bucket.LowerBound))
            {
                return(0);
            }

            if (bucket.UpperBound <= this.LowerBound)
            {
                return(1);
            }

            return(-1);
        }
        private void FindInRange(Vector location,
                                 KdTreeNode node, float range, IList <Vector> valuesList, int depth)
        {
            if (node == null)
            {
                return;
            }

            var dimension = depth % this.Dimensionality;
            var distance  = (node.Value - location).Norm(this.Dimensionality);

            // Add current node to list if it lies within given range.
            // Current node cannot be same as search location.
            if (!Precision.AlmostEqual(distance, 0.0f) &&
                (distance < range))
            {
                valuesList.Add(node.Value);
            }

            // Check for nodes in sub-tree of near child.
            var nearChildNode = (location[dimension] < node.Value[dimension]) ?
                                node.LeftChild : node.RightChild;

            if (nearChildNode != null)
            {
                FindInRange(location, nearChildNode, range, valuesList, depth + 1);
            }

            // Check whether splitting hyperplane given by current node intersects with hypersphere of current
            // smallest distance around given location.
            if ((range > Math.Abs(node.Value[dimension] - location[dimension])))
            {
                // Check for nodes in sub-tree of far child.
                var farChildNode = nearChildNode == node.LeftChild ? node.RightChild : node.LeftChild;

                if (farChildNode != null)
                {
                    FindInRange(location, farChildNode, range, valuesList, depth + 1);
                }
            }
        }
Exemple #13
0
 /// <inheritdoc/>
 public bool Equals([AllowNull] System.Windows.DpiScale other)
 {
     return
         (Precision.AlmostEqual(this.DpiScaleX, other.DpiScaleX) &&
          Precision.AlmostEqual(this.DpiScaleY, other.DpiScaleY));
 }
Exemple #14
0
 public override bool AlmostEqual(double a, double b)
 {
     return(Precision.AlmostEqual(a, b));
 }
Exemple #15
0
 public static bool LengthAlmostEqual(this Vector2D thisPoint, double length, double thresholdInPercent)
 {
     return(Precision.AlmostEqual(thisPoint.Length, length, length * thresholdInPercent));
 }
Exemple #16
0
 public static bool AlmostEqual(this Point2D thisPoint, Point2D thatPoint, double threshold)
 {
     return(Precision.AlmostEqual(thisPoint.X, thatPoint.X, threshold) && Precision.AlmostEqual(thisPoint.Y, thatPoint.Y, threshold));
 }