Beispiel #1
0
        internal CpuTensorScope(Tensor @this)
        {
            Contract.Requires(@this != null);
            Contract.Requires(@this.Count != 0);

            this.Tensor = @this;

            var tensorImpl = (ITensorHostImpl) @this;
            this._data = Vector<double>.Build.OfStorage( tensorImpl.Data );
            this._diff = Vector<double>.Build.OfStorage( tensorImpl.Diff );
        }
Beispiel #2
0
 public abstract void Fill( Tensor blob );
Beispiel #3
0
 public void ShareDiff(Tensor other)
 {
     switch (this.Location)
     {
         case TensorLocation.Cpu:
             this._diff = other._diff;
             break;
         case TensorLocation.Gpu:
             throw new NotImplementedException();
     }
 }
Beispiel #4
0
        public void ReshapeAs( Tensor other )
        {
            if (other == null)
                throw new ArgumentNullException("other");
            Contract.EndContractBlock();

            this.Reshape(other.Num, other.Channels, other.Height, other.Width);
        }  
Beispiel #5
0
        public void CopyFrom(Tensor other, bool copyDiff = false, bool reshape = false)
        {
            if (other == null)
                throw new ArgumentNullException("other");
            Contract.EndContractBlock();           

            // If reshaping needed we reshape the instance with new memory.
            if (reshape)
                ReshapeAs(other);

            switch (this.Location)
            {
                case TensorLocation.Cpu:
                    using (var @thisCpu = this.OnCpu())
                    using (var @otherCpu = other.OnCpu())
                    {
                        // We copy the data
                        @otherCpu.Data.CopyTo(@thisCpu.Data);

                        // If copying differential is needed, we copy it too.
                        if (copyDiff)
                            @otherCpu.Diff.CopyTo(@thisCpu.Diff);
                    }
                    break;
                case TensorLocation.Gpu:
                    break;
            }

            throw new NotImplementedException();


        }
Beispiel #6
0
        public Tensor( Tensor blob )
        {
            Guard.That(() => blob).IsNotNull();

            ReshapeAs(blob);
        }
Beispiel #7
0
        internal GpuTensorScope(Tensor @this)
        {
            Contract.Requires(@this != null);
            Contract.Requires(@this.Count != 0);

            this.Tensor = @this;
        }
Beispiel #8
0
        public void Setup( Tensor bottom, Tensor top )
        {
            Contract.Requires(bottom != null);
            Contract.Requires(top != null);

            var bottomList = new TensorCollection { bottom };
            var topList = new TensorCollection { top };
            this.Setup( bottomList, topList );
        }
Beispiel #9
0
        public double Forward(Tensor bottom, Tensor top)
        {
            Contract.Requires(bottom != null && top != null);

            Guard.That(() => bottom).IsNotNull();
            Guard.That(() => top).IsNotNull();

            var bottomList = new TensorCollection { bottom };
            var topList = new TensorCollection { top };

            return this.Forward(bottomList, topList);
        }
Beispiel #10
0
        public void Backward(Tensor top, IList<bool> propagateDown, Tensor bottom)
        {
            Contract.Requires(bottom != null && top != null);

            Guard.That(() => bottom).IsNotNull();
            Guard.That(() => top).IsNotNull();

            this.Backward(new TensorCollection { top }, propagateDown, new TensorCollection { bottom });
        }