Exemplo n.º 1
0
        public int CountEquals(ContiguousMemoryBuffer rhs, MemoryBuffer cache)
        {
            Debug.Assert(Buffer.pointer != 0);
            Debug.Assert(rhs.Buffer.pointer != 0);
            Debug.Assert(Size == rhs.Size);

            bool needToFreeCache = cache.pointer == 0;

            if (needToFreeCache)
            {
                cache.memorySpace = memorySpace;
                cache.mathDomain  = mathDomain;
                cache.size        = (uint)Size;
                Alloc(cache);
            }

            // calculate the difference
            CuBlasApi.Subtract(cache, Buffer, rhs.Buffer);

            // calculate how many non-zeros, overriding cache
            CuBlasApi.IsNonZero(cache, cache);

            double ret = CubApi.Sum(cache);

            // we are counting the zero entries
            ret = Size - ret;

            if (needToFreeCache)
            {
                Free(cache);
            }

            return((int)ret);
        }
Exemplo n.º 2
0
        public void SubtractEqual(ContiguousMemoryBuffer rhs)
        {
            Debug.Assert(Size == rhs.Size);
            Debug.Assert(memorySpace == rhs.memorySpace);
            Debug.Assert(mathDomain == rhs.mathDomain);
            Debug.Assert(Buffer.pointer != 0);
            Debug.Assert(rhs.Buffer.pointer != 0);

            CuBlasApi.SubtractEqual(Buffer, rhs.Buffer);
        }
Exemplo n.º 3
0
        public void AddEqual(ContiguousMemoryBuffer rhs, double alpha = 1.0)
        {
            Debug.Assert(Size == rhs.Size);
            Debug.Assert(memorySpace == rhs.memorySpace);
            Debug.Assert(mathDomain == rhs.mathDomain);
            Debug.Assert(Buffer.pointer != 0);
            Debug.Assert(rhs.Buffer.pointer != 0);

            CuBlasApi.AddEqual(Buffer, rhs.Buffer, alpha);
        }
Exemplo n.º 4
0
        public bool Equals(ContiguousMemoryBuffer rhs)
        {
            if (mathDomain != rhs.mathDomain)
            {
                return(false);
            }
            if (memorySpace != rhs.memorySpace)
            {
                return(false);
            }

            switch (mathDomain)
            {
            case MathDomain.Null:
                throw new ArgumentNullException();

            case MathDomain.Int:
            {
                var thisVec = GetRaw <int>();
                var thatVec = rhs.GetRaw <int>();
                if (thisVec.Length != thatVec.Length)
                {
                    return(false);
                }

                for (int i = 0; i < thisVec.Length; ++i)
                {
                    if (thisVec[i] != thatVec[i])
                    {
                        return(false);
                    }
                }

                return(true);
            }

            case MathDomain.Float:
            {
                var thisVec = Get <float>();
                var thatVec = rhs.Get <float>();
                return((thisVec - thatVec).AbsoluteMaximum() <= 1e-7);
            }

            case MathDomain.Double:
            {
                var thisVec = Get <double>();
                var thatVec = rhs.Get <double>();
                return((thisVec - thatVec).AbsoluteMaximum() <= 1e-15);
            }

            default:
                throw new NotImplementedException();
            }
        }
Exemplo n.º 5
0
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }

            ContiguousMemoryBuffer buf = obj as ContiguousMemoryBuffer;

            if (buf == null)
            {
                return(false);
            }

            return(Equals(buf));
        }
Exemplo n.º 6
0
 internal void ReadFrom(ContiguousMemoryBuffer rhs)
 {
     Debug.Assert(Buffer.pointer != 0);
     Debug.Assert(rhs.Buffer.pointer != 0);
     MemoryManagerApi.AutoCopy(Buffer, rhs.Buffer);
 }
Exemplo n.º 7
0
        public int CountEquals(ContiguousMemoryBuffer rhs)
        {
            MemoryBuffer cache = new MemoryBuffer();

            return(CountEquals(rhs, cache));
        }