Beispiel #1
0
 /// <summary>
 /// Gets the function of specified logical operation
 /// </summary>
 /// <param name="operation"></param>
 /// <returns></returns>
 public static Func <double, double, double> GetLogicalOperationFunction(LogicalOperationEnum operation)
 {
     if (operation == LogicalOperationEnum.And)
     {
         return((x1, x2) => (x1 != 0d && x2 != 0d) ? 1d : 0d);
     }
     if (operation == LogicalOperationEnum.Or)
     {
         return((x1, x2) => (x1 != 0d || x2 != 0d) ? 1d : 0d);
     }
     if (operation == LogicalOperationEnum.Xor)
     {
         return((x1, x2) => (x1 != 0d ^ x2 != 0d) ? 1d : 0d);
     }
     if (operation == LogicalOperationEnum.NotAnd)
     {
         return((x1, x2) => !(x1 != 0d && x2 != 0d) ? 1d : 0d);
     }
     if (operation == LogicalOperationEnum.NotOr)
     {
         return((x1, x2) => !(x1 != 0d || x2 != 0d) ? 1d : 0d);
     }
     if (operation == LogicalOperationEnum.NotXor)
     {
         return((x1, x2) => !(x1 != 0d ^ x2 != 0d) ? 1d : 0d);
     }
     return((x1, x2) => (x1 == 0d) ? 1d : 0d); //Not
 }
 /// <summary>
 /// Executes a logical operation between two arrays
 /// </summary>
 public static double[] ExecuteLogicOperation(LogicalOperationEnum operation, double[] array1, double[] array2)
 {
     var output = MemoryPool.Pool.New<double>(Math.Max(array1.Length, array2.Length));
     var function = GetLogicalOperationFunction(operation);
     for (var i = 0; i < Math.Min(array1.Length, array2.Length); i++)
     {
         output[i] = function(array1[i], array2[i]);
     }
     return output;
 }
Beispiel #3
0
        /// <summary>
        /// Executes a logical operation between two arrays
        /// </summary>
        public static double[] ExecuteLogicOperation(LogicalOperationEnum operation, double[] array1, double[] array2)
        {
            var output   = MemoryPool.Pool.New <double>(Math.Max(array1.Length, array2.Length));
            var function = GetLogicalOperationFunction(operation);

            for (var i = 0; i < Math.Min(array1.Length, array2.Length); i++)
            {
                output[i] = function(array1[i], array2[i]);
            }
            return(output);
        }
Beispiel #4
0
        /// <summary>
        /// Executes a logical operation between two or more signals
        /// </summary>
        public static Signal ExecuteLogicOperation(LogicalOperationEnum operation, params Signal[] signals)
        {
            signals = signals.Where(it => it != null && it.Samples != null && it.Samples.Length > 0).OrderByDescending(it => it.Samples.Length).ToArray();
            if (signals.Length == 0)
            {
                return(null);
            }

            var newSignal = signals[0].Clone();

            for (var i = 1; i < signals.Length; i++)
            {
                newSignal.Samples = ExecuteLogicOperation(operation, newSignal.Samples, signals[i].Samples);
            }
            return(newSignal);
        }
        /// <summary>
        /// Executes a logical operation between two or more signals
        /// </summary>
        public static Signal ExecuteLogicOperation(LogicalOperationEnum operation, params Signal[] signals)
        {
            signals = signals.Where(it => it != null && it.Samples != null && it.Samples.Length > 0).OrderByDescending(it => it.Samples.Length).ToArray();
            if (signals.Length == 0)
                return null;

            var newSignal = signals[0].Clone();
            for (var i = 1; i < signals.Length; i++)
            {
                newSignal.Samples = ExecuteLogicOperation(operation, newSignal.Samples, signals[i].Samples);
            }
            return newSignal;
        }
 /// <summary>
 /// Gets the function of specified logical operation
 /// </summary>
 /// <param name="operation"></param>
 /// <returns></returns>
 public static Func<double, double, double> GetLogicalOperationFunction(LogicalOperationEnum operation)
 {
     if(operation == LogicalOperationEnum.And)
     {
         return (x1, x2) => (x1 != 0d && x2 != 0d) ? 1d : 0d;
     }
     if (operation == LogicalOperationEnum.Or)
     {
         return (x1, x2) => (x1 != 0d || x2 != 0d) ? 1d : 0d;
     }
     if (operation == LogicalOperationEnum.Xor)
     {
         return (x1, x2) => (x1 != 0d ^ x2 != 0d) ? 1d : 0d;
     }
     if (operation == LogicalOperationEnum.NotAnd)
     {
         return (x1, x2) => !(x1 != 0d && x2 != 0d) ? 1d : 0d;
     }
     if (operation == LogicalOperationEnum.NotOr)
     {
         return (x1, x2) => !(x1 != 0d || x2 != 0d) ? 1d : 0d;
     }
     if (operation == LogicalOperationEnum.NotXor)
     {
         return (x1, x2) => !(x1 != 0d ^ x2 != 0d) ? 1d : 0d;
     }
     return (x1, x2) => (x1 == 0d) ? 1d : 0d; //Not
 }