Exemple #1
0
        /// <summary>
        /// Performs a generic reduce or accumulate operation on an input array.
        /// A reduce operation reduces the number of dimensions of the input array
        /// by one where accumulate does not.  Accumulate stores in incremental
        /// accumulated values in the extra dimension.
        /// </summary>
        /// <param name="arr">Input array</param>
        /// <param name="indices">Used only for reduceat</param>
        /// <param name="axis">Axis to reduce</param>
        /// <param name="otype">Output type of the array</param>
        /// <param name="outArr">Optional output array</param>
        /// <param name="operation">Reduce/accumulate operation to perform</param>
        /// <returns>Resulting array, either outArr or a new array</returns>
        private Object GenericReduce(ndarray arr, ndarray indices, int axis,
                                     dtype otype, ndarray outArr, GenericReductionOp operation)
        {
            if (signature() != null)
            {
                throw new RuntimeException("Reduction is not defined on ufunc's with signatures");
            }
            if (nin != 2)
            {
                throw new ArgumentException("Reduce/accumulate only supported for binary functions");
            }
            if (nout != 1)
            {
                throw new ArgumentException("Reduce/accumulate only supported for functions returning a single value");
            }

            if (arr.ndim == 0)
            {
                throw new ArgumentTypeException("Cannot reduce/accumulate a scalar");
            }

            if (arr.IsFlexible || (otype != null && NpyDefs.IsFlexible(otype.TypeNum)))
            {
                throw new ArgumentTypeException("Cannot perform reduce/accumulate with flexible type");
            }

            return(NpyCoreApi.GenericReduction(this, arr, indices,
                                               outArr, axis, otype, operation));
        }
Exemple #2
0

        
Exemple #3
0
 internal static NpyArray NpyUFunc_GenericReduction(NpyUFuncObject self, NpyArray arr, NpyArray indices,
                                                    NpyArray _out, int axis, NpyArray_Descr otype, GenericReductionOp operation)
 {
     return(numpyinternal.NpyUFunc_GenericReduction(self, arr, indices, _out, axis, otype, operation, false));
 }