예제 #1
0
            public bool GetWordVector(ref ReadOnlyMemory <char> word, float[] wordVector)
            {
                NormStr str = _pool.Get(word);

                if (str != null)
                {
                    WordVectors.CopyTo(str.Id * Dimension, wordVector, Dimension);
                    return(true);
                }
                return(false);
            }
예제 #2
0
        public static void CopyTo()
        {
            var distibutedArray = new BigArray <int> {
                1, 2, 3
            };
            var array = new int[8];

            distibutedArray.CopyTo(array);
            distibutedArray.CopyTo(array, 3);
            distibutedArray.CopyTo(1, array, 6, 2);

            var resultArray = new[] { 1, 2, 3, 1, 2, 3, 2, 3 };

            var emptyArray = new BigArray <int>();

            emptyArray.CopyTo(array);

            CheckEqual(array, resultArray);

            //Exceptions
            Assert.IsTrue(ExceptionManager.IsThrowActionException
                          <ArgumentNullException, int[]>
                              (distibutedArray.CopyTo, null));

            Assert.IsTrue(ExceptionManager.IsThrowActionException
                          <ArgumentOutOfRangeException, int[], int>
                              (distibutedArray.CopyTo, array, array.Length - distibutedArray.Count + 1));
            Assert.IsTrue(ExceptionManager.IsThrowActionException
                          <ArgumentOutOfRangeException, int[], int>
                              (distibutedArray.CopyTo, array, -1));

            Assert.IsTrue(ExceptionManager.IsThrowActionException
                          <ArgumentOutOfRangeException, int, int[], int, int>
                              (distibutedArray.CopyTo, 0, array, array.Length - distibutedArray.Count + 1, 3));
            Assert.IsTrue(ExceptionManager.IsThrowActionException
                          <ArgumentOutOfRangeException, int, int[], int, int>
                              (distibutedArray.CopyTo, 0, array, 0, -1));
        }
예제 #3
0
        /// <summary>
        /// Add incoming samples to the buffer
        /// </summary>
        public void AddSamples(BigArray <float> incomingSamples)
        {
            int writeIndex = samples.Count * 4;
            int newLength  = samples.Count + incomingSamples.Length;
            int writeBytes = incomingSamples.Length * 4;

            samples.EnsureCapacity(newLength);
            samples.ForceCount(newLength);
            incomingSamples.CopyTo(0, samples.Items, writeIndex, writeBytes);

            //for( int i = 0; i < incomingSamples.Length; i++ )
            //{
            //	samples[ writeIndex + i ] = incomingSamples[ i ];
            //}
        }
            public bool GetWordVector(ref DvText word, float[] wordVector)
            {
                if (word.IsNA)
                {
                    return(false);
                }
                string  rawWord = word.GetRawUnderlyingBufferInfo(out int ichMin, out int ichLim);
                NormStr str     = _pool.Get(rawWord, ichMin, ichLim);

                if (str != null)
                {
                    _wordVectors.CopyTo(str.Id * Dimension, wordVector, Dimension);
                    return(true);
                }
                return(false);
            }
예제 #5
0
        public void TestCopyTo()
        {
            BigArray<int> bigArray = new BigArray<int>(10);
            bigArray[0] = 1;
            bigArray[1] = 2;
            bigArray[2] = 1;
            bigArray[3] = 3;
            bigArray[4] = 4;
            bigArray[5] = 5;
            bigArray[6] = 1;
            bigArray[7] = 6;
            bigArray[8] = 7;
            bigArray[9] = 8;

            int[] array = new int[10];
            try
            {
                int sourceIndex = 0;
                int destIndex = 0;
                int count = 10;
                bigArray.CopyTo(sourceIndex, array, count);
                for (int i = 0; i < count; i++)
                {
                    if (bigArray[i + sourceIndex] != array[i + destIndex])
                    {
                        Assert.Fail();
                    }
                }

                array = new int[5];
                sourceIndex = 4;
                destIndex = 0;
                count = 5;
                bigArray.CopyTo(sourceIndex, array, count);
                for (int i = 0; i < count; i++)
                {
                    if (bigArray[i + sourceIndex] != array[i + destIndex])
                    {
                        Assert.Fail();
                    }
                }

                array = new int[10];
                sourceIndex = 4;
                destIndex = 3;
                count = 5;
                bigArray.CopyTo(sourceIndex, array, destIndex, count);
                for (int i = 0; i < count; i++)
                {
                    if (bigArray[i + sourceIndex] != array[i + destIndex])
                    {
                        Assert.Fail();
                    }
                }
            }
            catch
            {
                Assert.Fail();
            }
        }
예제 #6
0
        public void TestCopyTo()
        {
            BigArray <int> bigArray = new BigArray <int>(10);

            bigArray[0] = 1;
            bigArray[1] = 2;
            bigArray[2] = 1;
            bigArray[3] = 3;
            bigArray[4] = 4;
            bigArray[5] = 5;
            bigArray[6] = 1;
            bigArray[7] = 6;
            bigArray[8] = 7;
            bigArray[9] = 8;

            int[] array = new int[10];
            try
            {
                int sourceIndex = 0;
                int destIndex   = 0;
                int count       = 10;
                bigArray.CopyTo(sourceIndex, array, count);
                for (int i = 0; i < count; i++)
                {
                    if (bigArray[i + sourceIndex] != array[i + destIndex])
                    {
                        Assert.Fail();
                    }
                }

                array       = new int[5];
                sourceIndex = 4;
                destIndex   = 0;
                count       = 5;
                bigArray.CopyTo(sourceIndex, array, count);
                for (int i = 0; i < count; i++)
                {
                    if (bigArray[i + sourceIndex] != array[i + destIndex])
                    {
                        Assert.Fail();
                    }
                }

                array       = new int[10];
                sourceIndex = 4;
                destIndex   = 3;
                count       = 5;
                bigArray.CopyTo(sourceIndex, array, destIndex, count);
                for (int i = 0; i < count; i++)
                {
                    if (bigArray[i + sourceIndex] != array[i + destIndex])
                    {
                        Assert.Fail();
                    }
                }
            }
            catch
            {
                Assert.Fail();
            }
        }