Skip to content

Commit

Permalink
* Fix a few incorrectly mapped instances of std::unordered_map for…
Browse files Browse the repository at this point in the history
… PyTorch (issue #1164)
  • Loading branch information
saudet committed Apr 2, 2022
1 parent 3d76247 commit 87b01a0
Show file tree
Hide file tree
Showing 10 changed files with 128 additions and 26 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

* Fix a few incorrectly mapped instances of `std::unordered_map` for PyTorch ([issue #1164](https://github.com/bytedeco/javacpp-presets/issues/1164))
* Migrate builds for Leptonica and Tesseract to CMake ([issue #1163](https://github.com/bytedeco/javacpp-presets/issues/1163))
* Introduce `macosx-arm64` builds for Leptonica and Tesseract ([issue #814](https://github.com/bytedeco/javacpp-presets/issues/814))
* Map instances of `torch::OrderedDict` using C++ templates from PyTorch ([issue #623](https://github.com/bytedeco/javacpp-presets/issues/623))
Expand Down
47 changes: 47 additions & 0 deletions pytorch/src/gen/java/org/bytedeco/pytorch/ExtraFilesMap.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Targeted by JavaCPP version 1.5.8-SNAPSHOT: DO NOT EDIT THIS FILE

package org.bytedeco.pytorch;

import org.bytedeco.pytorch.Allocator;
import org.bytedeco.pytorch.Function;
import org.bytedeco.pytorch.Module;
import java.nio.*;
import org.bytedeco.javacpp.*;
import org.bytedeco.javacpp.annotation.*;

import static org.bytedeco.javacpp.presets.javacpp.*;
import static org.bytedeco.openblas.global.openblas_nolapack.*;
import static org.bytedeco.openblas.global.openblas.*;

import static org.bytedeco.pytorch.global.torch.*;

@Name("std::unordered_map<std::string,std::string>") @Properties(inherit = org.bytedeco.pytorch.presets.torch.class)
public class ExtraFilesMap extends Pointer {
static { Loader.load(); }
/** Pointer cast constructor. Invokes {@link Pointer#Pointer(Pointer)}. */
public ExtraFilesMap(Pointer p) { super(p); }
public ExtraFilesMap() { allocate(); }
private native void allocate();
public native @Name("operator =") @ByRef ExtraFilesMap put(@ByRef ExtraFilesMap x);

public boolean empty() { return size() == 0; }
public native long size();

@Index public native @StdString BytePointer get(@StdString BytePointer i);
public native ExtraFilesMap put(@StdString BytePointer i, BytePointer value);
@ValueSetter @Index public native ExtraFilesMap put(@StdString BytePointer i, @StdString String value);

public native void erase(@ByVal Iterator pos);
public native @ByVal Iterator begin();
public native @ByVal Iterator end();
@NoOffset @Name("iterator") public static class Iterator extends Pointer {
public Iterator(Pointer p) { super(p); }
public Iterator() { }

public native @Name("operator ++") @ByRef Iterator increment();
public native @Name("operator ==") boolean equals(@ByRef Iterator it);
public native @Name("operator *().first") @MemberGetter @StdString BytePointer first();
public native @Name("operator *().second") @MemberGetter @StdString BytePointer second();
}
}

2 changes: 1 addition & 1 deletion pytorch/src/gen/java/org/bytedeco/pytorch/Function.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class Function extends Pointer {

public native @ByVal @Name("operator ()") IValue apply(
@ByVal IValueVector stack,
@Cast("const torch::jit::Kwargs*") @ByRef(nullValue = "torch::jit::Kwargs()") HashAliasedIValueMap kwargs);
@Cast("const torch::jit::Kwargs*") @ByRef(nullValue = "torch::jit::Kwargs()") StringIValueMap kwargs);
public native @ByVal @Name("operator ()") IValue apply(
@ByVal IValueVector stack);

Expand Down
2 changes: 1 addition & 1 deletion pytorch/src/gen/java/org/bytedeco/pytorch/IMethod.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class IMethod extends Pointer {

public native @ByVal @Name("operator ()") IValue apply(
@ByVal IValueVector args,
@Cast("const torch::IMethod::IValueMap*") @ByRef(nullValue = "torch::IMethod::IValueMap()") HashAliasedIValueMap kwargs);
@Cast("const torch::IMethod::IValueMap*") @ByRef(nullValue = "torch::IMethod::IValueMap()") StringIValueMap kwargs);
public native @ByVal @Name("operator ()") IValue apply(
@ByVal IValueVector args);

Expand Down
14 changes: 7 additions & 7 deletions pytorch/src/gen/java/org/bytedeco/pytorch/JitModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private native void allocate(

public native @Cast("bool") boolean is_optimized();

public native @ByVal IValue forward(@ByVal IValueVector inputs, @Cast("const torch::jit::Kwargs*") @ByRef(nullValue = "torch::jit::Kwargs()") HashAliasedIValueMap kwargs);
public native @ByVal IValue forward(@ByVal IValueVector inputs, @Cast("const torch::jit::Kwargs*") @ByRef(nullValue = "torch::jit::Kwargs()") StringIValueMap kwargs);
public native @ByVal IValue forward(@ByVal IValueVector inputs);

// In script modules, buffers are Tensors attribute that are _not_ registered
Expand Down Expand Up @@ -177,37 +177,37 @@ public native void dump(

public native void save(
@Cast("std::ostream*") @ByRef Pointer out,
@Cast("const torch::jit::ExtraFilesMap*") @ByRef(nullValue = "torch::jit::ExtraFilesMap()") HashAliasedIValueMap extra_files);
@Const @ByRef(nullValue = "torch::jit::ExtraFilesMap()") ExtraFilesMap extra_files);
public native void save(
@Cast("std::ostream*") @ByRef Pointer out);

public native void save(
@StdString BytePointer filename,
@Cast("const torch::jit::ExtraFilesMap*") @ByRef(nullValue = "torch::jit::ExtraFilesMap()") HashAliasedIValueMap extra_files);
@Const @ByRef(nullValue = "torch::jit::ExtraFilesMap()") ExtraFilesMap extra_files);
public native void save(
@StdString BytePointer filename);
public native void save(
@StdString String filename,
@Cast("const torch::jit::ExtraFilesMap*") @ByRef(nullValue = "torch::jit::ExtraFilesMap()") HashAliasedIValueMap extra_files);
@Const @ByRef(nullValue = "torch::jit::ExtraFilesMap()") ExtraFilesMap extra_files);
public native void save(
@StdString String filename);

public native void _save_for_mobile(
@Cast("std::ostream*") @ByRef Pointer out,
@Cast("const torch::jit::ExtraFilesMap*") @ByRef(nullValue = "torch::jit::ExtraFilesMap()") HashAliasedIValueMap extra_files,
@Const @ByRef(nullValue = "torch::jit::ExtraFilesMap()") ExtraFilesMap extra_files,
@Cast("bool") boolean save_mobile_debug_info/*=false*/);
public native void _save_for_mobile(
@Cast("std::ostream*") @ByRef Pointer out);

public native void _save_for_mobile(
@StdString BytePointer filename,
@Cast("const torch::jit::ExtraFilesMap*") @ByRef(nullValue = "torch::jit::ExtraFilesMap()") HashAliasedIValueMap extra_files,
@Const @ByRef(nullValue = "torch::jit::ExtraFilesMap()") ExtraFilesMap extra_files,
@Cast("bool") boolean save_mobile_debug_info/*=false*/);
public native void _save_for_mobile(
@StdString BytePointer filename);
public native void _save_for_mobile(
@StdString String filename,
@Cast("const torch::jit::ExtraFilesMap*") @ByRef(nullValue = "torch::jit::ExtraFilesMap()") HashAliasedIValueMap extra_files,
@Const @ByRef(nullValue = "torch::jit::ExtraFilesMap()") ExtraFilesMap extra_files,
@Cast("bool") boolean save_mobile_debug_info/*=false*/);
public native void _save_for_mobile(
@StdString String filename);
Expand Down
2 changes: 1 addition & 1 deletion pytorch/src/gen/java/org/bytedeco/pytorch/Method.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class Method extends IMethod {

public native @ByVal @Name("operator ()") IValue apply(
@ByVal IValueVector stack,
@Cast("const torch::jit::Kwargs*") @ByRef(nullValue = "torch::jit::Kwargs()") HashAliasedIValueMap kwargs);
@Cast("const torch::jit::Kwargs*") @ByRef(nullValue = "torch::jit::Kwargs()") StringIValueMap kwargs);
public native @ByVal @Name("operator ()") IValue apply(
@ByVal IValueVector stack);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ private native void allocate(
public native void writeFiles(@StdString String code_dir);
public native void serialize(
@Const @ByRef JitModule module,
@Cast("const torch::jit::ExtraFilesMap*") @ByRef HashAliasedIValueMap extra_files,
@Const @ByRef ExtraFilesMap extra_files,
@Cast("bool") boolean bytecode_format,
@Cast("bool") boolean save_mobile_debug_info);
public native void serialize_unified_format(@ByRef JitModule module, @Cast("uint64_t") long script_module_id);
Expand Down
46 changes: 46 additions & 0 deletions pytorch/src/gen/java/org/bytedeco/pytorch/TypeEnv.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Targeted by JavaCPP version 1.5.8-SNAPSHOT: DO NOT EDIT THIS FILE

package org.bytedeco.pytorch;

import org.bytedeco.pytorch.Allocator;
import org.bytedeco.pytorch.Function;
import org.bytedeco.pytorch.Module;
import java.nio.*;
import org.bytedeco.javacpp.*;
import org.bytedeco.javacpp.annotation.*;

import static org.bytedeco.javacpp.presets.javacpp.*;
import static org.bytedeco.openblas.global.openblas_nolapack.*;
import static org.bytedeco.openblas.global.openblas.*;

import static org.bytedeco.pytorch.global.torch.*;

@Name("std::unordered_map<std::string,c10::TypePtr>") @Properties(inherit = org.bytedeco.pytorch.presets.torch.class)
public class TypeEnv extends Pointer {
static { Loader.load(); }
/** Pointer cast constructor. Invokes {@link Pointer#Pointer(Pointer)}. */
public TypeEnv(Pointer p) { super(p); }
public TypeEnv() { allocate(); }
private native void allocate();
public native @Name("operator =") @ByRef TypeEnv put(@ByRef TypeEnv x);

public boolean empty() { return size() == 0; }
public native long size();

@Index public native @ByRef Type.TypePtr get(@StdString BytePointer i);
public native TypeEnv put(@StdString BytePointer i, Type.TypePtr value);

public native void erase(@ByVal Iterator pos);
public native @ByVal Iterator begin();
public native @ByVal Iterator end();
@NoOffset @Name("iterator") public static class Iterator extends Pointer {
public Iterator(Pointer p) { super(p); }
public Iterator() { }

public native @Name("operator ++") @ByRef Iterator increment();
public native @Name("operator ==") boolean equals(@ByRef Iterator it);
public native @Name("operator *().first") @MemberGetter @StdString BytePointer first();
public native @Name("operator *().second") @MemberGetter @ByRef @Const Type.TypePtr second();
}
}

34 changes: 20 additions & 14 deletions pytorch/src/gen/java/org/bytedeco/pytorch/global/torch.java
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,12 @@ public class torch extends org.bytedeco.pytorch.presets.torch {
// Targeting ../StringSizeTMap.java


// Targeting ../ExtraFilesMap.java


// Targeting ../TypeEnv.java


// Targeting ../StringIValueMap.java


Expand Down Expand Up @@ -15713,12 +15719,12 @@ public class torch extends org.bytedeco.pytorch.presets.torch {
// note: It is possible to successfully match a formal, but for type variables
// in the formal to still not be defined. In particular, None matches Optional[T]
// but does not define the value of T.
@Namespace("c10") public static native @ByVal MatchTypeReturn matchTypeVariables(@Const @ByRef Type.TypePtr formal, @Const @ByRef Type.TypePtr actual, @Cast("c10::TypeEnv*") @ByRef HashAliasedIValueMap type_env);
@Namespace("c10") public static native @ByVal MatchTypeReturn matchTypeVariables(@Const @ByRef Type.TypePtr formal, @Const @ByRef Type.TypePtr actual, @ByRef TypeEnv type_env);

// replace type variables appearing in `type` with the values in
// `type_env`. Returns nullptr if a variable used in `type`
// does not appear in `type_env`
@Namespace("c10") public static native @ByVal Type.TypePtr tryEvalTypeVariables(@Const @ByRef Type.TypePtr type, @Cast("c10::TypeEnv*") @ByRef HashAliasedIValueMap type_env);
@Namespace("c10") public static native @ByVal Type.TypePtr tryEvalTypeVariables(@Const @ByRef Type.TypePtr type, @ByRef TypeEnv type_env);

@Namespace("c10") public static native @Cast("bool") boolean elementTypeCanBeInferredFromMembers(@Const @ByRef Type.TypePtr elem_type);
// Targeting ../InterfaceType.java
Expand Down Expand Up @@ -62924,12 +62930,12 @@ The list of (type, depth) pairs controls the type of specializations and the num
@SharedPtr CompilationUnit cu,
@StdString BytePointer filename,
@ByVal DeviceOptional device,
@Cast("torch::jit::ExtraFilesMap*") @ByRef HashAliasedIValueMap extra_files);
@ByRef ExtraFilesMap extra_files);
@Namespace("torch::jit") public static native @ByVal JitModule import_ir_module(
@SharedPtr CompilationUnit cu,
@StdString String filename,
@ByVal DeviceOptional device,
@Cast("torch::jit::ExtraFilesMap*") @ByRef HashAliasedIValueMap extra_files);
@ByRef ExtraFilesMap extra_files);

// For reading unified serialization format from torch.Package
@Namespace("torch::jit") public static native @ByVal JitModule import_ir_module(
Expand All @@ -62949,15 +62955,15 @@ The list of (type, depth) pairs controls the type of specializations and the num
@SharedPtr CompilationUnit cu,
@Cast("std::istream*") @ByRef Pointer in,
@ByVal DeviceOptional device,
@Cast("torch::jit::ExtraFilesMap*") @ByRef HashAliasedIValueMap extra_files);
@ByRef ExtraFilesMap extra_files);


///
@Namespace("torch::jit") public static native @ByVal JitModule import_ir_module(
@SharedPtr CompilationUnit cu,
@UniquePtr ReadAdapterInterface rai,
@ByVal DeviceOptional device,
@Cast("torch::jit::ExtraFilesMap*") @ByRef HashAliasedIValueMap extra_files);
@ByRef ExtraFilesMap extra_files);

/** Loads a serialized {@code Module} from the given {@code istream}.
*
Expand All @@ -62971,7 +62977,7 @@ The list of (type, depth) pairs controls the type of specializations and the num
@Namespace("torch::jit") public static native @ByVal JitModule load(
@Cast("std::istream*") @ByRef Pointer in,
@ByVal DeviceOptional device,
@Cast("torch::jit::ExtraFilesMap*") @ByRef HashAliasedIValueMap extra_files);
@ByRef ExtraFilesMap extra_files);

/** Loads a serialized {@code Module} from the given {@code filename}.
*
Expand All @@ -62994,11 +63000,11 @@ The list of (type, depth) pairs controls the type of specializations and the num
@Namespace("torch::jit") public static native @ByVal JitModule load(
@StdString BytePointer filename,
@ByVal DeviceOptional device,
@Cast("torch::jit::ExtraFilesMap*") @ByRef HashAliasedIValueMap extra_files);
@ByRef ExtraFilesMap extra_files);
@Namespace("torch::jit") public static native @ByVal JitModule load(
@StdString String filename,
@ByVal DeviceOptional device,
@Cast("torch::jit::ExtraFilesMap*") @ByRef HashAliasedIValueMap extra_files);
@ByRef ExtraFilesMap extra_files);

/** Loads a serialized {@code Module} from the given shared_ptr {@code rai}.
*
Expand All @@ -63014,7 +63020,7 @@ The list of (type, depth) pairs controls the type of specializations and the num
@Namespace("torch::jit") public static native @ByVal JitModule load(
@SharedPtr ReadAdapterInterface rai,
@ByVal DeviceOptional device,
@Cast("torch::jit::ExtraFilesMap*") @ByRef HashAliasedIValueMap extra_files);
@ByRef ExtraFilesMap extra_files);

// namespace jit
// namespace torch
Expand Down Expand Up @@ -63260,7 +63266,7 @@ The list of (type, depth) pairs controls the type of specializations and the num
@Namespace("torch::jit") public static native void ExportModule(
@Const @ByRef JitModule module,
@Cast("std::ostream*") @ByRef Pointer out,
@Cast("const torch::jit::ExtraFilesMap*") @ByRef(nullValue = "torch::jit::ExtraFilesMap()") HashAliasedIValueMap metadata,
@Const @ByRef(nullValue = "torch::jit::ExtraFilesMap()") ExtraFilesMap metadata,
@Cast("bool") boolean bytecode_format/*=false*/,
@Cast("bool") boolean save_mobile_debug_info/*=false*/);
@Namespace("torch::jit") public static native void ExportModule(
Expand All @@ -63270,7 +63276,7 @@ The list of (type, depth) pairs controls the type of specializations and the num
@Namespace("torch::jit") public static native void ExportModule(
@Const @ByRef JitModule module,
@StdString BytePointer filename,
@Cast("const torch::jit::ExtraFilesMap*") @ByRef(nullValue = "torch::jit::ExtraFilesMap()") HashAliasedIValueMap metadata,
@Const @ByRef(nullValue = "torch::jit::ExtraFilesMap()") ExtraFilesMap metadata,
@Cast("bool") boolean bytecode_format/*=false*/,
@Cast("bool") boolean save_mobile_debug_info/*=false*/);
@Namespace("torch::jit") public static native void ExportModule(
Expand All @@ -63279,7 +63285,7 @@ The list of (type, depth) pairs controls the type of specializations and the num
@Namespace("torch::jit") public static native void ExportModule(
@Const @ByRef JitModule module,
@StdString String filename,
@Cast("const torch::jit::ExtraFilesMap*") @ByRef(nullValue = "torch::jit::ExtraFilesMap()") HashAliasedIValueMap metadata,
@Const @ByRef(nullValue = "torch::jit::ExtraFilesMap()") ExtraFilesMap metadata,
@Cast("bool") boolean bytecode_format/*=false*/,
@Cast("bool") boolean save_mobile_debug_info/*=false*/);
@Namespace("torch::jit") public static native void ExportModule(
Expand All @@ -63289,7 +63295,7 @@ The list of (type, depth) pairs controls the type of specializations and the num
@Namespace("torch::jit") public static native void ExportModule(
@Const @ByRef JitModule module,
@Const @ByRef WriteFunction writer_func,
@Cast("const torch::jit::ExtraFilesMap*") @ByRef(nullValue = "torch::jit::ExtraFilesMap()") HashAliasedIValueMap metadata,
@Const @ByRef(nullValue = "torch::jit::ExtraFilesMap()") ExtraFilesMap metadata,
@Cast("bool") boolean bytecode_format/*=false*/,
@Cast("bool") boolean save_mobile_debug_info/*=false*/);
@Namespace("torch::jit") public static native void ExportModule(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1857,7 +1857,9 @@ public void map(InfoMap infoMap) {
.put(new Info("std::unordered_map<c10::IValue,c10::IValue,c10::IValue::HashAliasedIValue,c10::IValue::CompAliasedIValues>").pointerTypes("HashAliasedIValueMap").define())
.put(new Info("std::unordered_map<int64_t,std::string>").pointerTypes("LongStringMap").define())
.put(new Info("std::unordered_map<std::string,size_t>").pointerTypes("StringSizeTMap").define())
.put(new Info("std::unordered_map<std::string,c10::IValue>").pointerTypes("StringIValueMap").define())
.put(new Info("std::unordered_map<std::string,std::string>").pointerTypes("ExtraFilesMap").define())
.put(new Info("std::unordered_map<std::string,c10::TypePtr>").pointerTypes("TypeEnv").define())
.put(new Info("std::unordered_map<std::string,c10::IValue>", "std::unordered_map<std::string,at::IValue>").pointerTypes("StringIValueMap").define())
.put(new Info("std::unordered_map<std::string,std::function<PyObject*(void*)> >").pointerTypes("StringFunctionMap").define())
.put(new Info("std::unordered_map<std::string,torch::jit::Value*>").pointerTypes("StringValueMap").define())
.put(new Info("std::unordered_map<std::string,std::unordered_map<int64_t,std::string> >").pointerTypes("StringLongStringMapMap").define())
Expand Down

0 comments on commit 87b01a0

Please sign in to comment.