Exemple #1
0
        private INDArray CheckNice(INDArray array, string paramName = "unspecified")
        {
            if (!Enabled)
            {
                return(array);
            }

            if (array == null)
            {
                Report($"ndarray \"{paramName}\" is null.");
            }
            else
            {
                if (array.Rank != array.Shape.Length)
                {
                    Report($"ndarray \"{paramName}\" has inconsistent rank ({array.Rank}) / shape (length {array.Length}).", array);
                }

                if (CheckNaN && UnderlyingHandler.IsNaN(array))
                {
                    Report($"ndarray \"{paramName}\" contains NaN values.", array);
                }

                if (CheckInfinite && UnderlyingHandler.IsNotFinite(array))
                {
                    Report($"ndarray \"{paramName}\" contains infinite values.", array);
                }
            }

            return(array);
        }
Exemple #2
0
        private INumber CheckNice(INumber number, string paramName = "unspecified")
        {
            if (!Enabled)
            {
                return(number);
            }

            if (number == null)
            {
                Report($"number {paramName} is null.");
            }
            else
            {
                if (CheckNaN && UnderlyingHandler.IsNaN(number))
                {
                    Report($"number {paramName} is a NaN value.", number);
                }

                if (CheckInfinite && UnderlyingHandler.IsNotFinite(number))
                {
                    Report($"number {paramName} is an infinite value.", number);
                }
            }

            return(number);
        }
Exemple #3
0
        public INDArray NDArray(params long[] shape)
        {
            INDArray array = UnderlyingHandler.NDArray(shape);

            CheckNice(array);

            return(array);
        }
Exemple #4
0
        public INDArray NDArray <TOther>(TOther[] values, params long[] shape)
        {
            INDArray array = UnderlyingHandler.NDArray(values, shape);

            CheckNice(array);

            return(array);
        }
Exemple #5
0
        public INDArray MergeBatch(params INDArray[] arrays)
        {
            for (int i = 0; i < arrays.Length; i++)
            {
                CheckNice(arrays[i], $"arrays[{i}]");
            }

            return(CheckNice(UnderlyingHandler.MergeBatch(arrays)));
        }
Exemple #6
0
        /// <inheritdoc />
        public INDArray RowWise(INDArray array, Func <INDArray, INDArray> function)
        {
            if (function == null)
            {
                Report("function was null");
            }

            return(CheckNice(UnderlyingHandler.RowWise(CheckNice(array), function)));
        }
Exemple #7
0
        /// <inheritdoc />
        public TOther[] RowWiseTransform <TOther>(INDArray array, Func <INDArray, TOther> transformFunction)
        {
            if (transformFunction == null)
            {
                Report("transform function was null");
            }

            return(UnderlyingHandler.RowWiseTransform(CheckNice(array), transformFunction));
        }
Exemple #8
0
        /// <inheritdoc />
        public INDArray FlattenTimeAndFeatures(INDArray array)
        {
            if (Enabled && array.Rank < 3)
            {
                Report($"ndarray needs to have a rank of 3 or higher (was {array.Rank}) for {nameof(FlattenTimeAndFeatures)} operation", array);
            }

            return(CheckNice(UnderlyingHandler.FlattenTimeAndFeatures(CheckNice(array))));
        }
Exemple #9
0
        public INDArray FlattenTime(INDArray array)
        {
            if (Enabled && array.Rank < 2)             // two or three? technically 2 is enough ([BT]F) but 3 makes more sense
            {
                Report($"ndarray needs to have a rank of 2 or higher (was {array.Rank}) for {nameof(FlattenTime)} operation", array);
            }

            return(CheckNice(UnderlyingHandler.FlattenTime(CheckNice(array))));
        }
Exemple #10
0
        /// <inheritdoc />
        public void FillWithProbabilityMask(INDArray array, double probability)
        {
            if (Enabled && (probability < 0.0 || probability > 1.0))
            {
                Report($"probability for fill with probability mask should be 0.0 <= p <= 1.0 (was {probability}).");
            }

            UnderlyingHandler.FillWithProbabilityMask(CheckNice(array), probability);
            CheckNice(array);
        }
Exemple #11
0
        public INDArray Dot(INDArray a, INDArray b)
        {
            CheckMatrix(a, "dot product");
            CheckMatrix(b, "dot product");

            if (Enabled && a.Shape[1] != b.Shape[0])
            {
                Report($"ndarray a.Shape[1] (={a.Shape[1]}) should be b.Shape[0] (={b.Shape[0]}) for operation matrix dot product", a, b);
            }

            return(CheckNice(UnderlyingHandler.Dot(CheckNice(a), CheckNice(b))));
        }
Exemple #12
0
        public INDArray StackRows(int numberRows, INDArray row)
        {
            if (numberRows < 1)
            {
                Report($"number of rows must be >= 1 but was {numberRows}", numberRows);
            }

            if (!row.IsVector)
            {
                Report($"row must be vector", row);
            }

            return(CheckNice(UnderlyingHandler.StackRows(numberRows, CheckNice(row))));
        }
Exemple #13
0
        public INDArray GetSlice(INDArray array, int rowIndex, int columnIndex, int rowLength, int columnLength)
        {
            if (Enabled)
            {
                if (rowIndex < 0 || columnIndex < 0)
                {
                    Report($"row index and column index must be > 0, but were {rowIndex} and {columnIndex}", array, rowIndex, columnIndex);
                }

                if (rowLength <= 0 || columnLength <= 0)
                {
                    Report($"row and column length must be > 0, but were {rowLength} and {columnLength}", array, rowLength, columnLength);
                }

                if (rowIndex + rowLength > array.Shape[0] || columnIndex + columnLength > array.Shape[1])
                {
                    Report($"row index and column index must be < ndarray.shape[i], but were {rowIndex + rowLength} and {columnIndex + columnLength} (bounds were {array.Shape[0]} and {array.Shape[1]})", array, rowIndex, columnIndex, rowLength, columnLength);
                }
            }

            CheckMatrix(array, "get slice from matrix");

            return(CheckNice(UnderlyingHandler.GetSlice(CheckNice(array), rowIndex, columnIndex, rowLength, columnLength)));
        }
Exemple #14
0
 /// <inheritdoc />
 public void FreeLimbo(INDArray array)
 {
     UnderlyingHandler.FreeLimbo(array);
 }
Exemple #15
0
 /// <inheritdoc />
 public void MarkLimbo(INDArray array)
 {
     UnderlyingHandler.MarkLimbo(array);
 }
Exemple #16
0
 /// <inheritdoc />
 public void ClearSession()
 {
     UnderlyingHandler.ClearSession();
 }
Exemple #17
0
 /// <inheritdoc />
 public void EndSession()
 {
     UnderlyingHandler.EndSession();
 }
Exemple #18
0
 /// <inheritdoc />
 public void BeginSession()
 {
     UnderlyingHandler.BeginSession();
 }
Exemple #19
0
 /// <inheritdoc />
 public INDArray SoftMax(INDArray array)
 {
     return(CheckNice(UnderlyingHandler.SoftMax(CheckNice(array))));
 }
Exemple #20
0
 /// <inheritdoc />
 public bool IsNotFinite(INumber number)
 {
     return(UnderlyingHandler.IsNotFinite(number));
 }
Exemple #21
0
 /// <inheritdoc />
 public TTraceable ClearTrace <TTraceable>(TTraceable traceable) where TTraceable : ITraceable
 {
     return(UnderlyingHandler.ClearTrace(traceable));
 }
Exemple #22
0
 /// <inheritdoc />
 public TTraceable Trace <TTraceable>(TTraceable traceable, uint traceTag) where TTraceable : ITraceable
 {
     return(UnderlyingHandler.Trace(traceable, traceTag));
 }
Exemple #23
0
 /// <inheritdoc />
 public INDArray Clip(INDArray array, INumber minValue, INumber maxValue)
 {
     return(CheckNice(UnderlyingHandler.Clip(CheckNice(array), CheckNice(minValue), CheckNice(maxValue))));
 }
Exemple #24
0
 /// <inheritdoc />
 public INumber Variance(INDArray array)
 {
     return(CheckNice(UnderlyingHandler.Variance(CheckNice(array))));
 }
Exemple #25
0
 /// <inheritdoc />
 public INumber StandardDeviation(INDArray array)
 {
     return(CheckNice(UnderlyingHandler.StandardDeviation(CheckNice(array))));
 }
Exemple #26
0
 /// <inheritdoc />
 public bool IsNaN(INDArray array)
 {
     return(UnderlyingHandler.IsNaN(array));
 }
Exemple #27
0
 /// <inheritdoc />
 public bool IsNaN(INumber number)
 {
     return(UnderlyingHandler.IsNaN(number));
 }
Exemple #28
0
 /// <inheritdoc />
 public void ComputeDerivativesTo(ITraceable traceable)
 {
     UnderlyingHandler.ComputeDerivativesTo(traceable);
 }
Exemple #29
0
 /// <inheritdoc />
 public uint BeginTrace()
 {
     return(UnderlyingHandler.BeginTrace());
 }
Exemple #30
0
 /// <inheritdoc />
 public TTraceable GetDerivative <TTraceable>(TTraceable traceable) where TTraceable : ITraceable
 {
     return(UnderlyingHandler.GetDerivative(traceable));
 }