public void ApplyWithErrorMessageTheory(CustomDimensionsHint hint, TensorDimensions originalDims) { string errorMessage; var resultDims = hint.TryToApply(originalDims, out errorMessage); Assert.Equal(originalDims, resultDims); Assert.False(string.IsNullOrEmpty(errorMessage)); }
public void ApplyFallbackTheory(CustomDimensionsHint hint, TensorDimensions originalDims) { TensorDimensions resultDims; bool didApply = hint.TryToApply(originalDims, out resultDims); Assert.Equal(originalDims, resultDims); Assert.False(didApply); }
// TODO(Premek): Report warnings using a logger interface. internal static Size ComputeCustomTextureSize(TensorDimensions dims, CustomDimensionsHint customDims, RenderingMethod method, int vectorElements, out string warning) { warning = ""; if (dims.IsEmpty) { return(Size.Empty); } bool isDivisible; string divisorName = (method == RenderingMethod.RGB) ? "3 (RGB channel count)" : "vector element count"; bool isRowVector = (dims.Rank == 1) || (dims.Rank == 2 && dims[1] == 1); bool isColumnVector = !isRowVector && (dims.Rank == 2) && (dims[0] == 1); TensorDimensions adjustedDims; bool didApplyCustomDims = customDims.TryToApply(dims, out adjustedDims); if (!customDims.IsEmpty && !didApplyCustomDims) { warning = "Could not apply custom dimensions (the element count must match the original)."; } if (!didApplyCustomDims && (isRowVector || isColumnVector)) { return(ComputeTextureSizeForVector(dims.ElementCount, isRowVector, method, vectorElements, divisorName, ref warning)); } int shrinkedLastDim = ShrinkSizeForRenderingMethod(adjustedDims[adjustedDims.Rank - 1], method, vectorElements, out isDivisible); if (!isDivisible || (shrinkedLastDim == 0)) { if (string.IsNullOrEmpty(warning)) { warning = string.Format("The last dimension is {0} {1}. Ignoring dimensions.", (!isDivisible) ? "not divisible by" : "smaller than", divisorName); } return(ComputeTextureSize( ShrinkSizeForRenderingMethod(dims.ElementCount, method, vectorElements, out isDivisible))); } // Squash all dimensions except the first one together. // TODO(Premek): Decide according to actual sizes of the dimensions. int squashedOtherDims = shrinkedLastDim; for (int i = 1; i < adjustedDims.Rank - 1; i++) { squashedOtherDims *= adjustedDims[i]; } return(new Size(adjustedDims[0], squashedOtherDims)); }
private TensorDimensions GetTileDimensions() { if (UseCustomDimensions) { TensorDimensions d; bool didApplyCustomDims = m_customDimensions.TryToApply(Target.Dims, out d); if (!didApplyCustomDims) { MyLog.WARNING.WriteLine("Memory block '{0}: {1}' observer: {2}", Target.Owner.Name, Target.Name, "Could not apply custom dimensions, will use default ones"); return(Target.Dims); } return(d); } return(Target.Dims); }