Exemple #1
0
        /// <summary>最小値</summary>
        public static VariableNode Min(VariableNode x, int[] axes = null, bool keepdims = false)
        {
            if (axes == null)
            {
                axes = (new int[x.Shape.Ndim]).Select((_, dim) => dim).ToArray();
            }

            foreach (int axis in axes.OrderBy((val) => val))
            {
                if (x.Shape[axis] == 1)
                {
                    continue;
                }

                Function function = new Functions.Aggregation.Min(axis);

                x = Apply(function, x)[0];
            }

            if (!keepdims)
            {
                List <int> lengths = ((int[])x.Shape).ToList();

                foreach (int axis in axes.OrderByDescending((val) => val))
                {
                    lengths.RemoveAt(axis);
                }

                x = Reshape(x, new Shape(x.Shape.Type, lengths.ToArray()));
            }

            return(x);
        }
Exemple #2
0
        /// <summary>最小値</summary>
        public static Tensor Min(Tensor x, int[] axes = null, bool keepdims = false)
        {
            if (axes == null)
            {
                axes = (new int[x.Shape.Ndim]).Select((_, dim) => dim).ToArray();
            }

            foreach (int axis in axes.OrderBy((val) => val))
            {
                if (x.Shape[axis] == 1)
                {
                    continue;
                }

                Function function = new Functions.Aggregation.Min(axis);

                Tensor y = new Tensor(function.OutputShapes(x.Shape)[0]);

                function.Execute(new Tensor[] { x }, new Tensor[] { y });

                x = y;
            }

            if (!keepdims)
            {
                List <int> lengths = ((int[])x.Shape).ToList();

                foreach (int axis in axes.OrderByDescending((val) => val))
                {
                    lengths.RemoveAt(axis);
                }

                x = Reshape(x, new Shape(x.Shape.Type, lengths.ToArray()));
            }

            return(x);
        }