Ejemplo n.º 1
0
        public object get_attr(string name)
        {
            AttrValue x = null;

            using (var buf = new Buffer())
            {
                c_api.TF_OperationGetAttrValueProto(_handle, name, buf, status);
                status.Check(true);
                x = AttrValue.Parser.ParseFrom(buf);
            }

            string oneof_value = x.ValueCase.ToString();

            if (string.IsNullOrEmpty(oneof_value))
            {
                return(null);
            }

            if (oneof_value == "list")
            {
                throw new NotImplementedException($"Unsupported field type in {x.ToString()}");
            }

            if (oneof_value == "type")
            {
                return(x.Type);
            }

            return(x.GetType().GetProperty(oneof_value).GetValue(x));
        }
Ejemplo n.º 2
0
        public object get_attr <T>(string name)
        {
            AttrValue x = null;

            using (var buf = new Buffer())
            {
                c_api.TF_OperationGetAttrValueProto(_handle, name, buf, status);
                status.Check(true);
                x = AttrValue.Parser.ParseFrom(buf);
            }

            switch (name)
            {
            case "T":
            case "dtype":
                return(x.Type);

            case "shape":
                return(x.Shape);

            default:
                switch (typeof(T).Name)
                {
                case "Boolean":
                    return(x.B);

                case "String":
                    return(x.S);

                default:
                    throw new NotImplementedException($"Unsupported field type in {x.ToString()}");
                }
            }
        }
Ejemplo n.º 3
0
        public object get_attr(string name)
        {
            AttrValue x = null;

            lock (Locks.ProcessWide)
                using (var status = new Status())
                    using (var buf = new Buffer())
                    {
                        c_api.TF_OperationGetAttrValueProto(_handle, name, buf, status);
                        status.Check(true);

                        x = AttrValue.Parser.ParseFrom(buf.MemoryBlock.Stream());
                    }

            string oneof_value = x.ValueCase.ToString();

            if (string.IsNullOrEmpty(oneof_value))
            {
                return(null);
            }

            if (oneof_value == "list")
            {
                throw new NotImplementedException($"Unsupported field type in {x.ToString()}");
            }

            if (oneof_value == "type")
            {
                return(x.Type);
            }

            object result = x.GetType().GetProperty(oneof_value).GetValue(x);

            if (result is Google.Protobuf.ByteString byteString)
            {
                return(byteString.ToStringUtf8());
            }
            return(result);
        }
Ejemplo n.º 4
0
        public virtual object get_attr(string name)
        {
            AttrValue x = null;

            lock (Locks.ProcessWide)
            {
                using var buf = new Buffer();
                c_api.TF_OperationGetAttrValueProto(_handle, name, buf.Handle, tf.Status.Handle);
                tf.Status.Check(true);

                x = AttrValue.Parser.ParseFrom(buf.DangerousMemoryBlock.Stream());
            }

            string oneof_value = x.ValueCase.ToString();

            if (string.IsNullOrEmpty(oneof_value))
            {
                return(null);
            }

            if (oneof_value == "list")
            {
                throw new NotImplementedException($"Unsupported field type in {x.ToString()}");
            }

            if (string.Equals("type", oneof_value, StringComparison.OrdinalIgnoreCase))
            {
                return(x.Type);
            }

            object result = x.GetType().GetProperty(oneof_value).GetValue(x);

            if (result is Google.Protobuf.ByteString byteString)
            {
                return(byteString.ToStringUtf8());
            }
            return(result);
        }