Example #1
0
        QVoid ICallable.Apply(object args)
        {
            Debug.Assert(typeof(O) == typeof(QVoid), "Calling void Apply on an operation that doesn't return QVoid");
            this.Apply((I)PartialMapper.CastTuple(typeof(I), args));

            return(QVoid.Instance);
        }
        public FunctionPartial(Function <I, O> op, object partialTuple) : base(op.Factory)
        {
            Debug.Assert(op != null);
            Debug.Assert(partialTuple != null);

            this.BaseOp = op;
            this.Mapper = PartialMapper.Create <P, I>(partialTuple);
        }
Example #3
0
        public OperationPartial(Operation <I, O> op, object partialTuple) : base(op.Factory)
        {
            Debug.Assert(op != null);
            Debug.Assert(partialTuple != null);

            this.BaseOp   = op;
            this.Mapper   = PartialMapper.Create <P, I>(partialTuple);
            this.__qubits = new Lazy <Qubit[]>(() => op?.__dataIn(this.Mapper(default(P)))?.Qubits?.ToArray());
        }
Example #4
0
        public virtual GenO Apply <GenO>(object args)
        {
            Debug.Assert(args != null, "Calling Apply with null args. Can't verify type of args");
            Debug.Assert(typeof(GenO).IsAssignableFrom(typeof(O)), $"Apply received a wrong type of Input. Expected {typeof(GenO)}, but got {typeof(O)}");

            O result = this.Apply((I)PartialMapper.CastTuple(typeof(I), args));

            return((GenO)(object)result);
        }
Example #5
0
        protected override ICallable CreateCallable(Type P, Type O)
        {
            var baseArgsType = IdentifyBaseArgsType(P);
            var partialType  = IdentifyPartialArgsType(P);
            var outType      = O.Normalize();
            var op           = this.BaseOp.FindCallable(baseArgsType, outType);

            var(partialOperationType, typeArgs) = PartialApplicationTypes(partialType, baseArgsType, outType, op.GetType());
            var partialOpType = partialOperationType.MakeGenericType(typeArgs);
            var partialValues = this.Values.GetType().IsPartialMapper()
                ? PartialMapper.CastTuple(typeof(Func <,>).MakeGenericType(new Type[] { typeArgs[0], typeArgs[1] }), this.Values)
                : this.Values;

            var result = (ICallable)Activator.CreateInstance(partialOpType, op, partialValues);

            return(result);
        }
Example #6
0
 public O Apply <O>(object args) =>
 (O)Activator.CreateInstance(typeof(U), PartialMapper.CastTuple(typeof(B), args));