Exemplo n.º 1
0
        /// <summary>
        /// Performs matrix multiplication on the two operands, using the supplied methods
        /// </summary>
        /// <typeparam name="T">The type of data to operate on</typeparam>
        /// <param name="addop">The add operator</param>
        /// <param name="mulop">The multiply operator</param>
        /// <param name="in1">The left-hand-side argument</param>
        /// <param name="in2">The right-hand-side argument</param>
        /// <param name="out">An optional output argument, use for in-place operations</param>
        /// <returns>An array with the matrix multiplication result</returns>
        public static NdArray <T> Matmul <T>(IBinaryOp <T> addop, IBinaryOp <T> mulop, NdArray <T> in1, NdArray <T> in2, NdArray <T> @out = null)
        {
            var method = typeof(UFunc).GetMethod("Matmul_Entry", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic);
            var gm     = method.MakeGenericMethod(typeof(T), addop.GetType(), mulop.GetType());

            return((NdArray <T>)gm.Invoke(null, new object[] { addop, mulop, in1, in2, @out }));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Reduces the input argument on the specified axis
        /// </summary>
        /// <typeparam name="T">The type of data to operate on</typeparam>
        /// <param name="op">The operation to reduce with</param>
        /// <param name="in1">The input argument</param>
        /// <param name="axis">The axis to reduce</param>
        /// <param name="out">The output target</param>
        /// <returns>The output target</returns>
        public static NdArray <T> Reduce <T>(IBinaryOp <T> op, NdArray <T> in1, long axis = 0, NdArray <T> @out = null)
        {
            var method = typeof(UFunc).GetMethod("Reduce_Entry", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic);
            var gm     = method.MakeGenericMethod(typeof(T), op.GetType());

            return((NdArray <T>)gm.Invoke(null, new object[] { op, in1, axis, @out }));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Calculates the scalar result of applying the binary operation to all elements
        /// </summary>
        /// <typeparam name="T">The value to operate on</typeparam>
        /// <param name="op">The operation to perform</param>
        /// <param name="in1">The array to aggregate</param>
        /// <returns>A scalar value that is the result of aggregating all elements</returns>
        public static T Aggregate <T>(IBinaryOp <T> op, NdArray <T> in1)
        {
            var method = typeof(UFunc).GetMethod("Aggregate_Entry", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic);
            var gm     = method.MakeGenericMethod(typeof(T), op.GetType());

            return((T)gm.Invoke(null, new object[] { op, in1 }));
        }
Exemplo n.º 4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LazyMatmulOperation&lt;T&gt;"/> class
 /// </summary>
 /// <param name="addOperation">The add operator</param>
 /// <param name="mulOperation">The multiply operator</param>
 public LazyMatmulOperation(IBinaryOp <T> addOperation, IBinaryOp <T> mulOperation)
 {
     this.AddOperator = addOperation;
     this.MulOperator = mulOperation;
 }
Exemplo n.º 5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LazyReduceOperation&lt;T&gt;"/> struct.
 /// </summary>
 /// <param name="operation">The operation to reduce with</param>
 /// <param name="axis">The axis to reduce over</param>
 public LazyReduceOperation(IBinaryOp <T> operation, long axis)
 {
     Operation = operation;
     Axis      = axis;
 }
Exemplo n.º 6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LazyReduceOperation&lt;T&gt;"/> struct.
 /// </summary>
 /// <param name="operation">The operation to reduce with</param>
 public LazyAggregateOperation(IBinaryOp <T> operation)
 {
     Operation = operation;
 }