Make IMethod cache mutable so getArgument works on const IMethod (#62834)
authorWill Constable <whc@fb.com>
Sat, 7 Aug 2021 05:56:54 +0000 (22:56 -0700)
committerFacebook GitHub Bot <facebook-github-bot@users.noreply.github.com>
Sat, 7 Aug 2021 05:58:21 +0000 (22:58 -0700)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/62834

Test Plan: existing unit tests

Reviewed By: alanwaketan

Differential Revision: D30135939

fbshipit-source-id: e19c0ac1af6996e065a18318351265b5c4a01e70

torch/csrc/api/include/torch/imethod.h
torch/csrc/api/src/imethod.cpp

index c26812f..db6ca41 100644 (file)
@@ -32,13 +32,13 @@ class IMethod {
   // script and python methods.  This is a more portable dependency
   // than a ScriptMethod FunctionSchema, which has more information
   // than can be generally expected from a python method.
-  const std::vector<std::string>& getArgumentNames();
+  const std::vector<std::string>& getArgumentNames() const;
 
  protected:
   virtual void setArgumentNames(std::vector<std::string>& argumentNames) const = 0;
 
  private:
-  std::vector<std::string> argumentNames_;
+  mutable std::vector<std::string> argumentNames_;
 };
 
 } // namespace torch
index 20cdb35..e50101d 100644 (file)
@@ -2,7 +2,7 @@
 
 namespace torch {
 
-const std::vector<std::string>& IMethod::getArgumentNames()
+const std::vector<std::string>& IMethod::getArgumentNames() const
 {
   // TODO(jwtan): Deal with empty parameter list.
   if (!argumentNames_.empty()) {