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 ); }
public abstract void Fill( Tensor blob );
public void ShareDiff(Tensor other) { switch (this.Location) { case TensorLocation.Cpu: this._diff = other._diff; break; case TensorLocation.Gpu: throw new NotImplementedException(); } }
public void ReshapeAs( Tensor other ) { if (other == null) throw new ArgumentNullException("other"); Contract.EndContractBlock(); this.Reshape(other.Num, other.Channels, other.Height, other.Width); }
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(); }
public Tensor( Tensor blob ) { Guard.That(() => blob).IsNotNull(); ReshapeAs(blob); }
internal GpuTensorScope(Tensor @this) { Contract.Requires(@this != null); Contract.Requires(@this.Count != 0); this.Tensor = @this; }
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 ); }
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); }
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 }); }