Skip to content

Commit

Permalink
* Map instances of torch::OrderedDict using C++ templates from PyTo…
Browse files Browse the repository at this point in the history
…rch (issue #623)
  • Loading branch information
saudet committed Mar 30, 2022
1 parent 366d4f0 commit 78540be
Show file tree
Hide file tree
Showing 81 changed files with 1,451 additions and 293 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

* Map instances of `torch::OrderedDict` using C++ templates from PyTorch ([issue #623](https://github.com/bytedeco/javacpp-presets/issues/623))
* Add presets for Bullet Physics SDK 3.22 ([pull #1153](https://github.com/bytedeco/javacpp-presets/pull/1153))
* Add `long[] pytorch.Tensor.shape()` method for convenience ([pull #1161](https://github.com/bytedeco/javacpp-presets/pull/1161))
* Enable DNNL codegen as BYOC backend in presets for TVM
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ public class AliasInfoOptional extends Pointer {
private native void allocate();
public native @Name("operator =") @ByRef AliasInfoOptional put(@ByRef AliasInfoOptional x);


public native boolean has_value();
@Name("value") public native @ByRef AliasInfo get();
public native @Name("value") @ByRef AliasInfo get();
@ValueSetter public native AliasInfoOptional put(@ByRef AliasInfo value);
}

3 changes: 1 addition & 2 deletions pytorch/src/gen/java/org/bytedeco/pytorch/BoolOptional.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ public class BoolOptional extends Pointer {
private native void allocate();
public native @Name("operator =") @ByRef BoolOptional put(@ByRef BoolOptional x);


public native boolean has_value();
@Name("value") public native @Cast("bool") boolean get();
public native @Name("value") @Cast("bool") boolean get();
@ValueSetter public native BoolOptional put(@Cast("bool") boolean value);
}

3 changes: 1 addition & 2 deletions pytorch/src/gen/java/org/bytedeco/pytorch/ByteOptional.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ public class ByteOptional extends Pointer {
private native void allocate();
public native @Name("operator =") @ByRef ByteOptional put(@ByRef ByteOptional x);


public native boolean has_value();
@Name("value") public native byte get();
public native @Name("value") byte get();
@ValueSetter public native ByteOptional put(byte value);
}

Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ public class ClassTypePropertyOptional extends Pointer {
private native void allocate();
public native @Name("operator =") @ByRef ClassTypePropertyOptional put(@ByRef ClassTypePropertyOptional x);


public native boolean has_value();
@Name("value") public native @ByRef ClassType.Property get();
public native @Name("value") @ByRef ClassType.Property get();
@ValueSetter public native ClassTypePropertyOptional put(@ByRef ClassType.Property value);
}

Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ public class CppSignatureOptional extends Pointer {
private native void allocate();
public native @Name("operator =") @ByRef CppSignatureOptional put(@ByRef CppSignatureOptional x);


public native boolean has_value();
@Name("value") public native @ByRef CppSignature get();
public native @Name("value") @ByRef CppSignature get();
@ValueSetter public native CppSignatureOptional put(@ByRef CppSignature value);
}

Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ public class DeviceOptional extends Pointer {
private native void allocate();
public native @Name("operator =") @ByRef DeviceOptional put(@ByRef DeviceOptional x);


public native boolean has_value();
@Name("value") public native @ByRef Device get();
public native @Name("value") @ByRef Device get();
@ValueSetter public native DeviceOptional put(@ByRef Device value);
}

Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ public class DimVectorOptional extends Pointer {
private native void allocate();
public native @Name("operator =") @ByRef DimVectorOptional put(@ByRef DimVectorOptional x);


public native boolean has_value();
@Name("value") public native @ByRef DimVector get();
public native @Name("value") @ByRef DimVector get();
@ValueSetter public native DimVectorOptional put(@ByRef DimVector value);
}

Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ public class DimnameListOptional extends Pointer {
private native void allocate();
public native @Name("operator =") @ByRef DimnameListOptional put(@ByRef DimnameListOptional x);


public native boolean has_value();
@Name("value") public native @ByRef DimnameArrayRef get();
public native @Name("value") @ByRef DimnameArrayRef get();
@ValueSetter public native DimnameListOptional put(@ByRef DimnameArrayRef value);
}

Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ public class DimnameOptional extends Pointer {
private native void allocate();
public native @Name("operator =") @ByRef DimnameOptional put(@ByRef DimnameOptional x);


public native boolean has_value();
@Name("value") public native @ByRef Dimname get();
public native @Name("value") @ByRef Dimname get();
@ValueSetter public native DimnameOptional put(@ByRef Dimname value);
}

Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ public class DispatchKeyOptional extends Pointer {
private native void allocate();
public native @Name("operator =") @ByRef DispatchKeyOptional put(@ByRef DispatchKeyOptional x);


public native boolean has_value();
@Name("value") public native @ByRef DispatchKey get();
public native @Name("value") @ByRef DispatchKey get();
@ValueSetter public native DispatchKeyOptional put(@ByRef DispatchKey value);
}

Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ public class DoubleArrayRefOptional extends Pointer {
private native void allocate();
public native @Name("operator =") @ByRef DoubleArrayRefOptional put(@ByRef DoubleArrayRefOptional x);


public native boolean has_value();
@Name("value") public native @ByRef DoubleArrayRef get();
public native @Name("value") @ByRef DoubleArrayRef get();
@ValueSetter public native DoubleArrayRefOptional put(@ByRef DoubleArrayRef value);
}

Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ public class DoubleExpandingArrayOptional extends Pointer {
private native void allocate();
public native @Name("operator =") @ByRef DoubleExpandingArrayOptional put(@ByRef DoubleExpandingArrayOptional x);


public native boolean has_value();
@Name("value") public native @Cast("torch::ExpandingArray<1,double>*") @ByRef DoublePointer get();
public native @Name("value") @Cast("torch::ExpandingArray<1,double>*") @ByRef DoublePointer get();
@ValueSetter public native DoubleExpandingArrayOptional put(@Cast("torch::ExpandingArray<1,double>*") @ByRef DoublePointer value);
}

Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ public class DoubleOptional extends Pointer {
private native void allocate();
public native @Name("operator =") @ByRef DoubleOptional put(@ByRef DoubleOptional x);


public native boolean has_value();
@Name("value") public native double get();
public native @Name("value") double get();
@ValueSetter public native DoubleOptional put(double value);
}

Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ public class DoubleVectorOptional extends Pointer {
private native void allocate();
public native @Name("operator =") @ByRef DoubleVectorOptional put(@ByRef DoubleVectorOptional x);


public native boolean has_value();
@Name("value") public native @Cast("std::vector<double>*") @ByRef DoubleVector get();
public native @Name("value") @Cast("std::vector<double>*") @ByRef DoubleVector get();
@ValueSetter public native DoubleVectorOptional put(@Cast("std::vector<double>*") @ByRef DoubleVector value);
}

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()") IValueIValueMap kwargs);
@Cast("const torch::jit::Kwargs*") @ByRef(nullValue = "torch::jit::Kwargs()") HashAliasedIValueMap 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 @@ -25,9 +25,8 @@ public class GeneratorOptional extends Pointer {
private native void allocate();
public native @Name("operator =") @ByRef GeneratorOptional put(@ByRef GeneratorOptional x);


public native boolean has_value();
@Name("value") public native @ByRef Generator get();
public native @Name("value") @ByRef Generator get();
@ValueSetter public native GeneratorOptional put(@ByRef Generator value);
}

4 changes: 2 additions & 2 deletions pytorch/src/gen/java/org/bytedeco/pytorch/GenericDict.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
import static org.bytedeco.openblas.global.openblas.*;

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

@Namespace("c10::ivalue") @Opaque @Properties(inherit = org.bytedeco.pytorch.presets.torch.class)
// namespace torch
@Name("c10::Dict<c10::IValue,c10::IValue>") @Opaque @Properties(inherit = org.bytedeco.pytorch.presets.torch.class)
public class GenericDict extends Pointer {
/** Empty constructor. Calls {@code super((Pointer)null)}. */
public GenericDict() { super((Pointer)null); }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@
import static org.bytedeco.pytorch.global.torch.*;

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

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

@Index public native @ByRef IValue get(@ByRef IValue i);
public native IValueIValueMap put(@ByRef IValue i, IValue value);
public native HashAliasedIValueMap put(@ByRef IValue i, IValue value);

public native void erase(@ByVal Iterator pos);
public native @ByVal Iterator begin();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
import static org.bytedeco.pytorch.global.torch.*;

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

public boolean empty() { return size() == 0; }
public native long size();
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()") IValueIValueMap kwargs);
@Cast("const torch::IMethod::IValueMap*") @ByRef(nullValue = "torch::IMethod::IValueMap()") HashAliasedIValueMap kwargs);
public native @ByVal @Name("operator ()") IValue apply(
@ByVal IValueVector args);

Expand Down
10 changes: 5 additions & 5 deletions pytorch/src/gen/java/org/bytedeco/pytorch/IValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -265,11 +265,11 @@ public class IValue extends Pointer {
// This SNIFAEs the called constructor exists.

// GenericDict
public IValue(@ByVal IValueIValueDict v) { super((Pointer)null); allocate(v); }
private native void allocate(@ByVal IValueIValueDict v);
public IValue(@ByVal GenericDict v) { super((Pointer)null); allocate(v); }
private native void allocate(@ByVal GenericDict v);
public native @Cast("bool") boolean isGenericDict();

public native @ByVal IValueIValueDict toGenericDict();
public native @ByVal GenericDict toGenericDict();

// ClassType
public native @Cast("bool") boolean isObject();
Expand Down Expand Up @@ -449,12 +449,12 @@ public static class CompAliasedIValues extends Pointer {
public native @Cast("bool") boolean overlaps(@Const @ByRef IValue rhs);

// Inserts all subvalues of this in subValues.
public native void getSubValues(@Cast("c10::IValue::HashAliasedIValues*") @ByRef IValueSet subValues);
public native void getSubValues(@ByRef HashAliasedIValues subValues);

// Apply visitor to every subvalue.
// TODO: There are several places that recurse over IValue. This is fragile.
// This visitor should be used to recurse over ivalues.
public native void visit(@Const @ByRef IValueVisitor visitor);
public native @ByVal IValue deepcopy();
public native @ByVal IValue deepcopy(@Cast("c10::IValue::HashAliasedIValueMap*") @ByRef IValueIValueMap memo);
public native @ByVal IValue deepcopy(@ByRef HashAliasedIValueMap memo);
}
24 changes: 0 additions & 24 deletions pytorch/src/gen/java/org/bytedeco/pytorch/IValueIValueDict.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ public class IValueOptional extends Pointer {
private native void allocate();
public native @Name("operator =") @ByRef IValueOptional put(@ByRef IValueOptional x);


public native boolean has_value();
@Name("value") public native @ByRef IValue get();
public native @Name("value") @ByRef IValue get();
@ValueSetter public native IValueOptional put(@ByRef IValue value);
}

Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ public class InlinedCallStackOptional extends Pointer {
private native void allocate();
public native @Name("operator =") @ByRef InlinedCallStackOptional put(@ByRef InlinedCallStackOptional x);


public native boolean has_value();
@Name("value") public native @ByRef InlinedCallStack get();
public native @Name("value") @ByRef InlinedCallStack get();
@ValueSetter public native InlinedCallStackOptional put(@ByRef InlinedCallStack value);
}

3 changes: 1 addition & 2 deletions pytorch/src/gen/java/org/bytedeco/pytorch/IntOptional.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ public class IntOptional extends Pointer {
private native void allocate();
public native @Name("operator =") @ByRef IntOptional put(@ByRef IntOptional x);


public native boolean has_value();
@Name("value") public native int get();
public native @Name("value") int get();
@ValueSetter public native IntOptional put(int value);
}

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()") IValueIValueMap kwargs);
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);

// 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()") IValueIValueMap extra_files);
@Cast("const torch::jit::ExtraFilesMap*") @ByRef(nullValue = "torch::jit::ExtraFilesMap()") HashAliasedIValueMap 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()") IValueIValueMap extra_files);
@Cast("const torch::jit::ExtraFilesMap*") @ByRef(nullValue = "torch::jit::ExtraFilesMap()") HashAliasedIValueMap 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()") IValueIValueMap extra_files);
@Cast("const torch::jit::ExtraFilesMap*") @ByRef(nullValue = "torch::jit::ExtraFilesMap()") HashAliasedIValueMap 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()") IValueIValueMap extra_files,
@Cast("const torch::jit::ExtraFilesMap*") @ByRef(nullValue = "torch::jit::ExtraFilesMap()") HashAliasedIValueMap 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()") IValueIValueMap extra_files,
@Cast("const torch::jit::ExtraFilesMap*") @ByRef(nullValue = "torch::jit::ExtraFilesMap()") HashAliasedIValueMap 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()") IValueIValueMap extra_files,
@Cast("const torch::jit::ExtraFilesMap*") @ByRef(nullValue = "torch::jit::ExtraFilesMap()") HashAliasedIValueMap extra_files,
@Cast("bool") boolean save_mobile_debug_info/*=false*/);
public native void _save_for_mobile(
@StdString String filename);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ public class LayoutOptional extends Pointer {
private native void allocate();
public native @Name("operator =") @ByRef LayoutOptional put(@ByRef LayoutOptional x);


public native boolean has_value();
@Name("value") public native @ByRef Layout get();
public native @Name("value") @ByRef Layout get();
@ValueSetter public native LayoutOptional put(@ByRef Layout value);
}

Loading

0 comments on commit 78540be

Please sign in to comment.