Esempio n. 1
0
        public override void Validate(MyValidator validator)
        {
            switch (Operation)
            {
            case MyJoinOperation.StackInputs:
                return;

            case MyJoinOperation.DistanceSquared:
            case MyJoinOperation.CosineDistance:
            case MyJoinOperation.DotProduct:
                validator.AssertError(InputBranches == 2, this, "Two operands are needed for distance measures");
                break;

            case MyJoinOperation.MatMultiplication:
                bool is_correct = Input0ColHint == (Input1Count / Input1ColHint);
                // if (Input1ColHint==1) /// BrainSim. bug for Nx1 vector, column hint is one, although it should be N...
                //     is_correct = Input0ColHint == Input1Count;
                validator.AssertError(is_correct, this, "# of columns in Mat1 needs to correspond to # of rows in Mat2!");
                break;

            case MyJoinOperation.AddToIdcs:
            case MyJoinOperation.AddToIdcs_Normalize:
                validator.AssertError(InputBranches >= 3, this, "Must provide the Target vector, Source vector and the idcs as the first three inputs");
                validator.AssertError(GetInputSize(1) == GetInputSize(2), this, "Dimensions of the Source vector and idcs must be the same");
                validator.AssertError(GetInputSize(0) >= GetInputSize(1), this, "Target vector must be bigger than Source vector");
                return;

            case MyJoinOperation.GatherFromIdcs:
                validator.AssertError(InputBranches >= 2, this, "Must provide the Target vector and the idcs as the first two inputs");
                validator.AssertError(GetInputSize(0) >= GetInputSize(1), this, "Target vector must be bigger than the idcs");
                return;

            default:
                validator.AssertError(InputBranches >= 2, this, "Operation needs at least two operands");
                break;
            }

            TensorDimensions firstInputDimensions        = null;
            bool             firstInputDimensionsRankOne = false;

            for (int i = 0; i < InputBranches; i++)
            {
                MyMemoryBlock <float> ai = GetInput(i);
                if (ai == null)
                {
                    validator.AddError(this, $"Missing input {i}.");
                    return;
                }

                if (InputBranches > 2) // Two inputs are allowed to be of variable size
                {
                    validator.AssertError(ai.Count == OutputSize, this, $"Operand #{i} size differs from output size");
                }

                if (firstInputDimensions == null)
                {
                    firstInputDimensions        = ai.Dims;
                    firstInputDimensionsRankOne = IsRankOne(firstInputDimensions);
                }

                var bothDimensionsRankOne = firstInputDimensionsRankOne && IsRankOne(ai.Dims);

                if (firstInputDimensions.Rank != ai.Dims.Rank && !bothDimensionsRankOne)
                {
                    // TODO(Premek): replace warning with error when the check gets smart enough
                    validator.AddWarning(this, $"Incompatible input ranks (input #{i}).");
                }
            }
        }