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); }