/// <summary>
        /// Computes dot product of two operands.
        /// </summary>
        public Operand Dot(Operand in1, Operand in2)
        {
            if (in1.IsArray || !in1.Equals(in2))
            {
                throw new IncompatibleOperandsException("Dot operation requires both formats to be the same.");
            }

            PinFormat fmt;

            if (!PinFormatHelper.IsVector(in1.Format, out fmt))
            {
                throw new IncompatibleOperandsException("Dot operation requires both formats to be vectors.");
            }

            // We check if we can precache it, this is copy only op.
            if (in1.IsFixed && in2.IsFixed)
            {
                return(CreateFixed(fmt, in1.ArraySize, Math.MathHelper.Dot(in1.Value, in2.Value)));
            }

            // Else create temp and return.
            Operand tmp = CreateTemporary(fmt, in1.ArraySize);

            compiler.Mul(in1.Name, in2.Name, tmp.Name);
            return(tmp);
        }
        /// <summary>
        /// Computes dot product of two operands.
        /// </summary>
        /// <returns>Result of operation.</returns>
        public void Dot(Operand in1, Operand in2, Operand outOp)
        {
            if (in1.IsArray || !in1.Equals(in2) || !outOp.IsWritable)
            {
                throw new IncompatibleOperandsException("Addition operation requires both formats to be the same.");
            }

            PinFormat fmt;

            if (!PinFormatHelper.IsVector(in1.Format, out fmt) || outOp.Format != fmt)
            {
                throw new IncompatibleOperandsException("Only vector types can be used in dot product, scalars must match vector types.");
            }

            // We check if we can precache it, this is copy only op.
            if (in1.IsFixed && in2.IsFixed)
            {
                Operand tmp = CreateFixed(in1.Format, in1.ArraySize, Math.MathHelper.Dot(in1.Value, in2.Value));

                // We must create a mem copy.
                compiler.Mov(tmp.Name, outOp.Name);

                return;
            }

            compiler.Dot(in1.Name, in2.Name, outOp.Name);
        }
Exemple #3
0
        protected override Pin[] CreateOutputs()
        {
            // We search for vector-* and *-vector operations.
            PinFormat scalar;

            if (PinFormatHelper.IsVector(inputs[0].Format, out scalar))
            {
                // The result must be matrix.
                return(new Pin[] { inputs[0].Clone(this) });
            }
            if (PinFormatHelper.IsVector(inputs[1].Format, out scalar))
            {
                return(new Pin[] { inputs[1].Clone(this) });
            }

            // We search for matrix-* and *-matrix operations.
            if (PinFormatHelper.IsMatrix(inputs[0].Format, out scalar))
            {
                // The result must be matrix.
                return(new Pin[] { inputs[0].Clone(this) });
            }
            if (PinFormatHelper.IsMatrix(inputs[1].Format, out scalar))
            {
                // The result must be matrix.
                return(new Pin[] { inputs[1].Clone(this) });
            }

            // Must be equal, we simply output.
            return(new Pin[] { inputs[0].Clone(this) });
        }
Exemple #4
0
        protected override Pin[] CreateOutputs()
        {
            PinFormat scalar;

            PinFormatHelper.IsVector(inputs[0].Format, out scalar);

            // We now create result.
            return(new Pin[] { new Pin(scalar, Pin.NotArray, this) });
        }