예제 #1
0
 public PyUniValNdArray(string dtype, int[] shape, string data)
 {
     this.rpc_tag = RpcTag.__RPC_VAL_NDARRAY__;
     this.dtype   = dtype;
     this.shape   = shape;
     this.data    = data;
 }
예제 #2
0
        private static object[] ReadAnswer(ISession session, bool blocking)
        {
            Debug.WriteLineIf(CLI.FnTrace.Enabled, "Future.ReadAnswer ()");
            Debug.Assert(session != null);

            object response = null;

            if (blocking)
            {
                response = session.Read();
            }
            else
            {
                try
                {
                    response = session.ReadNonBlocking();
                }
                catch (System.Net.Sockets.SocketException e)
                {
                    if (e.ErrorCode == 10035)                     // WSAEWOULDBLOCK
                    {
                        return(null);
                    }
                    throw;
                }
            }

            if (!(response is object[]))
            {
                throw new SystemException("Invalid future answer.");
            }

            object[] answer = (object[])response;
            if (answer.Length != RpcMessageLayout.DA_ANSWER_LENGTH)
            {
                throw new SystemException("Invalid future answer size.");
            }

            RpcTag tag = (RpcTag)answer[RpcMessageLayout.DA_MESSAGE_TYPE];

            if (tag != RpcTag.DA_FUTURE_ANSWER && tag != RpcTag.DA_FUTURE_PARTIAL_ANSWER)
            {
                throw new SystemException("Invalid future answer type.");
            }

            return(answer);
        }
예제 #3
0
        public PyUniValNdArray(Array array, int[] shape = null)
        {
            this.rpc_tag = RpcTag.__RPC_VAL_NDARRAY__;
            this.dtype   = CSharp2NumpyDict[array.GetType().GetElementType()];
            if (shape != null)
            {
                this.shape = shape;
            }
            else
            {
                this.shape = new int[array.Rank];
                for (int i = 0; i < array.Rank; i++)
                {
                    this.shape[i] = array.GetLength(i);
                }
            }

            int length = Buffer.ByteLength(array);

            byte[] buffer = new byte[length];
            Buffer.BlockCopy(array, 0, buffer, 0, length);
            this.data = Convert.ToBase64String(buffer);
        }