public virtual void Add(Tensor t, Tensor result) { Debug.Assert(SameDimensionsExceptBatches(t)); Debug.Assert(t.BatchSize == result.BatchSize || t.BatchSize == 1); Op.Add(this, t, result); }
public virtual void Add(float alpha, float beta, Tensor t, Tensor result) { Debug.Assert(SameDimensionsExceptBatches(t)); Debug.Assert(t.BatchSize == result.BatchSize || t.BatchSize == 1); Op.Add(alpha, this, beta, t, result); }
public static T BilinearSample <T>(T[,] data, float u, float v) where T : Software.Texel.ITexel { int width = data.GetLength(0), height = data.GetLength(1); int iu = (int)(u * width - 0.5); int iv = (int)(v * height - 0.5); T[] samples = new T[4]; for (int i = 0; i < 4; i++) { samples[i] = PointSampleT(data, iu + iuvOffsets[i].X, iv + iuvOffsets[i].Y); } Vector2[] sampleIUVs = new Vector2[4]; for (int i = 0; i < 4; i++) { sampleIUVs[i] = new Vector2( (iu + iuvOffsets[i].X + 0.5f), (iv + iuvOffsets[i].Y + 0.5f)); } float totalWeight = 0; for (int i = 0; i < 4; i++) { float udist = Math.Max(Math.Min(Math.Abs(sampleIUVs[i].X - u * (float)width), 1), 0); float vdist = Math.Max(Math.Min(Math.Abs(sampleIUVs[i].Y - v * (float)height), 1), 0); float weight = Math.Min(udist, vdist); totalWeight += weight; samples[i] = Op.Mul(samples[i], weight); } return(Op.Div(Op.Add(Op.Add(samples[0], samples[1]), Op.Add(samples[2], samples[3])), totalWeight)); }