Exemplo n.º 1
0
        public void ApplyWithoutErrorMessage()
        {
            string errorMessage;
            var    resultDims = CustomDimensionsHint.Parse("3, 2").TryToApply(new TensorDimensions(6), out errorMessage);

            Assert.Equal(new TensorDimensions(3, 2), resultDims);
            Assert.Equal(string.Empty, errorMessage);
        }
        public void CustomDimensionsAreSameAsHintWhenCountMatches()
        {
            TensorDimensions dims;
            bool             didApply = CustomDimensionsHint.Parse("2, 3, 5").TryToApply(new TensorDimensions(30), out dims);

            Assert.Equal(new TensorDimensions(2, 3, 5), dims);
            Assert.True(didApply);
        }
Exemplo n.º 3
0
        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));
        }
Exemplo n.º 4
0
 public CustomDimsTestCase(TensorDimensions dims, CustomDimensionsHint customDims,
                           RenderingMethod method, int vectorElements, Size expectedSize)
 {
     Dims           = dims;
     CustomDims     = customDims;
     Method         = method;
     VectorElements = vectorElements;
     ExpectedSize   = expectedSize;
 }
        public void ApplyFallbackTheory(CustomDimensionsHint hint, TensorDimensions originalDims)
        {
            TensorDimensions resultDims;

            bool didApply = hint.TryToApply(originalDims, out resultDims);

            Assert.Equal(originalDims, resultDims);
            Assert.False(didApply);
        }
        public void ParsingAndFlaggingTheory(
            string source, CustomDimensionsHint expectedHint, bool isEmpty, bool isFullyDefined)
        {
            var hint = CustomDimensionsHint.Parse(source);

            Assert.True(hint.Equals(expectedHint));
            Assert.Equal(isEmpty, hint.IsEmpty);
            Assert.Equal(isFullyDefined, hint.IsFullyDefined);
        }
        // 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));
        }
        public void WildcardDimensionIsCorrectlyComputed()
        {
            TensorDimensions dims = CustomDimensionsHint.Parse("2, *, 3").TryToApply(new TensorDimensions(30));

            Assert.Equal(dims, new TensorDimensions(2, 5, 3));
        }
 public void ElementCountWorksForWildcardHints()
 {
     Assert.Equal(6, CustomDimensionsHint.Parse("2, *, 3").ElementCount);
 }
 public void ParsingErrorsTheory(string source)
 {
     Assert.Throws <InvalidDimensionsException>(() => { var hint = CustomDimensionsHint.Parse(source); });
 }
        public void ParsesSimpleDimensions()
        {
            var dimensionsHint = CustomDimensionsHint.Parse("2, 3, 5");

            Assert.Equal(new CustomDimensionsHint(2, 3, 5), dimensionsHint);
        }