public void MapInplace(Func <T, T, T> f, VolumeStorage <T> other) { for (var i = 0; i < this.Shape.TotalLength; i++) { this.Set(i, f(this.Get(i), other.Get(i))); } }
public void Map(Func <T, T, T> f, VolumeStorage <T> other, VolumeStorage <T> result) { for (var i = 0; i < this.Shape.TotalLength; i++) { result.Set(i, f(this.Get(i), other.Get(i))); } }
public void MapEx(Func <T, T, T> f, VolumeStorage <T> other, VolumeStorage <T> result) { var w = (int)this.Shape.GetDimension(0); var h = (int)this.Shape.GetDimension(1); var C = (int)this.Shape.GetDimension(2); var N = (int)this.Shape.GetDimension(3); var otherWIsOne = (int)other.Shape.GetDimension(0) == 1; var otherHIsOne = (int)other.Shape.GetDimension(1) == 1; var otherCIsOne = (int)other.Shape.GetDimension(2) == 1; var otherNIsOne = (int)other.Shape.GetDimension(3) == 1; for (var n = 0; n < N; n++) { for (var c = 0; c < C; c++) { for (var j = 0; j < h; j++) { for (var i = 0; i < w; i++) { result.Set(i, j, c, n, f(Get(i, j, c, n), other.Get(otherWIsOne ? 0 : i, otherHIsOne ? 0 : j, otherCIsOne ? 0 : c, otherNIsOne ? 0 : n))); } } } } }