예제 #1
0
                #pragma warning restore
        #endregion fields & pins

        //called when data for any output pin is requested
        public void Evaluate(int SpreadMax)
        {
            FInput.Sync();
            FVec.Sync();
            FBin.Sync();

            if (FInput.IsChanged || FVec.IsChanged || FBin.IsChanged)
            {
                if (FInput.Length > 0 && FVec.Length > 0 && FBin.Length > 0)
                {
                    int vecSize = Math.Max(1, FVec.GetReader().Read());
                    VecBinSpread <double> spread = new VecBinSpread <double>(FInput, vecSize, FBin);

                    if (spread.ItemCount == 0)
                    {
                        FOutput.Length = 0;
                    }
                    else
                    {
                        FOutput.Length = spread.Count * vecSize;
                        using (var dataWriter = FOutput.GetWriter())
                            for (int b = 0; b < spread.Count; b++)
                            {
                                for (int v = 0; v < vecSize; v++)
                                {
                                    dataWriter.Write(spread.GetBinColumn(b, v).Select(f => f * f).Average(), 1);
                                }
                            }
                    }
                }
                else
                {
                    FOutput.Length = 0;
                }
            }
        }
예제 #2
0
                #pragma warning restore
        #endregion fields & pins

        //called when data for any output pin is requested
        public void Evaluate(int SpreadMax)
        {
            FInput.Sync();
            FVec.Sync();
            FBin.Sync();

            if (FInput.IsChanged || FVec.IsChanged || FBin.IsChanged)
            {
                if (FInput.Length > 0 && FVec.Length > 0 && FBin.Length > 0)
                {
                    int vecSize = Math.Max(1, FVec.GetReader().Read());
                    VecBinSpread <double> spread = new VecBinSpread <double>(FInput, vecSize, FBin);

                    if (spread.ItemCount == 0)
                    {
                        FOutput.Length = 0;
                    }
                    else
                    {
                        FOutput.Length = spread.Count * vecSize;
                        using (var dataWriter = FOutput.GetWriter())
                            for (int b = 0; b < spread.Count; b++)
                            {
                                for (int v = 0; v < vecSize; v++)
                                {
                                    dataWriter.Write(Math.Pow(spread.GetBinColumn(b, v).Aggregate((work, next) => work * next), 1 / (double)(spread[b].Length / vecSize)), 1);
                                }
                            }
                    }
                }
                else
                {
                    FOutput.Length = 0;
                }
            }
        }
예제 #3
0
                #pragma warning restore
        #endregion fields & pins

        //called when data for any output pin is requested
        public void Evaluate(int SpreadMax)
        {
            FInput.Sync();
            FVec.Sync();
            FBin.Sync();

            if (FInput.IsChanged || FVec.IsChanged || FBin.IsChanged || FTogPhase.IsChanged || FPhase.IsChanged)
            {
                if (FInput.Length > 0 && FVec.Length > 0 && FBin.Length > 0 && FTogPhase.SliceCount > 0 && FPhase.SliceCount > 0)
                {
                    int vecSize = Math.Max(1, FVec.GetReader().Read());
                    VecBinSpread <double> spread = new VecBinSpread <double>(FInput, vecSize, FBin, FPhase.CombineWith(FTogPhase));

                    FOutBin.Length = spread.Count;
                    FOutput.Length = spread.ItemCount;
                    using (var binWriter = FOutBin.GetWriter())
                        using (var dataWriter = FOutput.GetWriter())
                        {
                            int incr = 0;
                            for (int b = 0; b < spread.Count; b++)
                            {
                                int phase = 0;
                                if (FTogPhase[b])
                                {
                                    phase = (int)FPhase[b];
                                }
                                else
                                {
                                    phase = (int)Math.Round(FPhase[b] * (spread[b].Length / vecSize));
                                }

                                if (spread[b].Length > 0)
                                {
                                    for (int v = 0; v < vecSize; v++)
                                    {
                                        dataWriter.Position = incr + v;
                                        double[] src = spread.GetBinColumn(b, v).ToArray();
                                        phase = VMath.Zmod(phase, src.Length);

                                        if (phase != 0)
                                        {
                                            double[] dst = new double[src.Length];
                                            Array.Copy(src, 0, dst, phase, src.Length - phase);
                                            Array.Copy(src, src.Length - phase, dst, 0, phase);
                                            for (int s = 0; s < dst.Length; s++)
                                            {
                                                dataWriter.Write(dst[s], vecSize);
                                            }
                                        }
                                        else
                                        {
                                            for (int s = 0; s < src.Length; s++)
                                            {
                                                dataWriter.Write(src[s], vecSize);
                                            }
                                        }
                                    }
                                    incr += spread[b].Length;
                                }
                                binWriter.Write((spread[b].Length / vecSize), 1);
                            }
                        }
                }
                else
                {
                    FOutput.Length = FOutBin.Length = 0;
                }
            }
        }
예제 #4
0
                #pragma warning restore
        #endregion fields & pins

        //called when data for any output pin is requested
        public void Evaluate(int SpreadMax)
        {
            FInput.Sync();
            FVec.Sync();
            FBin.Sync();

            if (FInput.IsChanged || FVec.IsChanged || FBin.IsChanged || FClose.IsChanged)
            {
                if (FVec.Length > 0)
                {
                    int vecSize = Math.Max(1, FVec.GetReader().Read());
                    VecBinSpread <double> spread = new VecBinSpread <double>(FInput, vecSize, FBin, FClose.SliceCount);

                    int outCount = 0;
                    for (int o = 0; o < spread.Count; o++)
                    {
                        int curCount = spread[o].Length * 2;
                        if (!FClose[o])
                        {
                            curCount -= 2 * spread.VectorSize;
                        }
                        outCount += Math.Max(curCount, 0);
                    }


                    FOutBin.Length = spread.Count;
                    FOutput.Length = outCount;
                    using (var binWriter = FOutBin.GetWriter())
                        using (var dataWriter = FOutput.GetWriter())
                        {
                            int incr = 0;
                            for (int b = 0; b < spread.Count; b++)
                            {
                                int c       = FClose[b] ? 0:1;
                                int binSize = Math.Max((spread[b].Length / vecSize - c) * 2, 0);
                                if (spread[b].Length > 0)
                                {
                                    for (int v = 0; v < vecSize; v++)
                                    {
                                        dataWriter.Position = incr + v;
                                        double[] src = spread.GetBinColumn(b, v).ToArray();

                                        int s = 0;
                                        while (s < src.Length - 1)
                                        {
                                            dataWriter.Write(src[s], vecSize);
                                            s++;
                                            dataWriter.Write(src[s], vecSize);
                                        }
                                        if (FClose[b])
                                        {
                                            dataWriter.Write(src[s], vecSize);
                                            dataWriter.Write(src[0], vecSize);
                                        }
                                    }
                                    incr += binSize * vecSize;
                                }
                                binWriter.Write(binSize, 1);
                            }
                            FOutput.Length = incr;
                        }
                }
                else
                {
                    FOutBin.Length = FOutput.Length = 0;
                }
            }
        }