コード例 #1
0
        /// <summary>
        /// Parses the parameter from a RawProto.
        /// </summary>
        /// <param name="rp">Specifies the RawProto to parse.</param>
        /// <returns>A new instance of the parameter is returned.</returns>
        public static ScalarParameter FromProto(RawProto rp)
        {
            string          strVal;
            ScalarParameter p = new ScalarParameter();

            if ((strVal = rp.FindValue("value")) != null)
            {
                p.value = double.Parse(strVal);
            }

            if ((strVal = rp.FindValue("operation")) != null)
            {
                if (strVal == ScalarOp.MUL.ToString())
                {
                    p.m_op = ScalarOp.MUL;
                }
                else if (strVal == ScalarOp.ADD.ToString())
                {
                    p.m_op = ScalarOp.ADD;
                }
                else
                {
                    throw new Exception("Unknown scalar operation '" + strVal + "'");
                }
            }

            if ((strVal = rp.FindValue("passthrough_gradient")) != null)
            {
                p.passthrough_gradient = bool.Parse(strVal);
            }

            return(p);
        }
コード例 #2
0
        /// <summary>
        /// Creates a new copy of this instance of the parameter.
        /// </summary>
        /// <returns>A new instance of this parameter is returned.</returns>
        public override LayerParameterBase Clone()
        {
            ScalarParameter p = new ScalarParameter();

            p.Copy(this);
            return(p);
        }
コード例 #3
0
        /// <summary>
        /// Copy on parameter to another.
        /// </summary>
        /// <param name="src">Specifies the parameter to copy.</param>
        public override void Copy(LayerParameterBase src)
        {
            ScalarParameter p = (ScalarParameter)src;

            m_dfVal = p.m_dfVal;
            m_op    = p.m_op;
            m_bPassthroughGradient = p.m_bPassthroughGradient;
        }
コード例 #4
0
        /// <summary>
        /// Load the parameter from a binary reader.
        /// </summary>
        /// <param name="br">Specifies the binary reader.</param>
        /// <param name="bNewInstance">When <i>true</i> a new instance is created (the default), otherwise the existing instance is loaded from the binary reader.</param>
        /// <returns>Returns an instance of the parameter.</returns>
        public override object Load(System.IO.BinaryReader br, bool bNewInstance = true)
        {
            RawProto        proto = RawProto.Parse(br.ReadString());
            ScalarParameter p     = FromProto(proto);

            if (!bNewInstance)
            {
                Copy(p);
            }

            return(p);
        }