Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tensorflow C++: NodeDef.mutable_attr() cannot add new attribute #595

Closed
wumo opened this issue Aug 2, 2018 · 4 comments
Closed

Tensorflow C++: NodeDef.mutable_attr() cannot add new attribute #595

wumo opened this issue Aug 2, 2018 · 4 comments
Labels

Comments

@wumo
Copy link
Contributor

wumo commented Aug 2, 2018

I was trying to use Node.def().mutable_attr() to add new attribute after Operation has been built.

The code is:

val attr = c_op.node().def().mutable_attr() //StringAttrValueMap
attr.put(BytePointer("_class"),attr_value) 

It throws java.lang.RuntimeException: CHECK failed: it != end():
I checked the protobuf map.h and found it != end() only appears in at methods. Is it because StringAttrValueMap.put doesn't equal to T& operator[](const key_type& key)? In operator[] method, new map entry will be created while at method only returns existed value.

// Element access
  T& operator[](const key_type& key) {
    value_type** value =  &(*elements_)[key];
    if (*value == NULL) {
      *value = CreateValueTypeInternal(key);
      internal::MapValueInitializer<google::protobuf::is_proto_enum<T>::value,
                                    T>::Initialize((*value)->second,
                                                   default_enum_value_);
    }
    return (*value)->second;
  }
  const T& at(const key_type& key) const {
    const_iterator it = find(key);
    GOOGLE_CHECK(it != end()); //here checks
    return it->second;
  }
  T& at(const key_type& key) {
    iterator it = find(key);
    GOOGLE_CHECK(it != end());//here checks
    return it->second;
  }
@saudet
Copy link
Member

saudet commented Aug 2, 2018 via email

@wumo
Copy link
Contributor Author

wumo commented Aug 2, 2018

@saudet StringAttrValueMap doesn't have resize() or push_back() methods:

@Name({"google::protobuf::Map<std::string,tensorflow::AttrValue>"})
    public static class StringAttrValueMap extends Pointer {
        public StringAttrValueMap(Pointer p) {
            super(p);
        }

        public StringAttrValueMap() {
            this.allocate();
        }

        private native void allocate();

        @Name({"operator="})
        @ByRef
        public native tensorflow.StringAttrValueMap put(@ByRef tensorflow.StringAttrValueMap var1);

        public boolean empty() {
            return this.size() == 0L;
        }

        public native long size();

        @Index(
            function = "at"
        )
        @ByRef
        public native tensorflow.AttrValue get(@StdString BytePointer var1);

        public native tensorflow.StringAttrValueMap put(@StdString BytePointer var1, tensorflow.AttrValue var2);

        @ByVal
        public native tensorflow.StringAttrValueMap.Iterator begin();

        @ByVal
        public native tensorflow.StringAttrValueMap.Iterator end();

        static {
            Loader.load();
        }

        @NoOffset
        @Name({"iterator"})
        public static class Iterator extends Pointer {
            public Iterator(Pointer p) {
                super(p);
            }

            public Iterator() {
            }

            @Name({"operator++"})
            @ByRef
            public native tensorflow.StringAttrValueMap.Iterator increment();

            @Name({"operator=="})
            public native boolean equals(@ByRef tensorflow.StringAttrValueMap.Iterator var1);

            @Name({"operator*().first"})
            @MemberGetter
            @StdString
            public native BytePointer first();

            @Name({"operator*().second"})
            @MemberGetter
            @ByRef
            @Const
            public native tensorflow.AttrValue second();
        }
    }

@saudet
Copy link
Member

saudet commented Aug 2, 2018 via email

@saudet saudet added the bug label Aug 2, 2018
saudet added a commit to bytedeco/javacpp that referenced this issue Aug 3, 2018
…onst ` prefix (issue bytedeco/javacpp-presets#595)

 * Fix `Parser` sometimes ignoring `define` of `const ` containers (pull bytedeco/javacpp-presets#547)
@saudet
Copy link
Member

saudet commented Aug 3, 2018

Ok, I've fixed that in the commit above. Thanks for reporting!

@wumo wumo closed this as completed Aug 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants