Skip to content

Commit

Permalink
* Fix mapping of torch::ExpandingArrayWithOptionalElem in presets …
Browse files Browse the repository at this point in the history
…for PyTorch (issue #1250)
  • Loading branch information
saudet committed Oct 29, 2022
1 parent a8c515c commit 94268bb
Show file tree
Hide file tree
Showing 18 changed files with 132 additions and 41 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

* Fix mapping of `torch::ExpandingArrayWithOptionalElem` in presets for PyTorch ([issue #1250](https://github.com/bytedeco/javacpp-presets/issues/1250))
* Disable OpenMP for Tesseract to work around performance issues ([pull #1201](https://github.com/bytedeco/javacpp-presets/pull/1201))
* Enable NVIDIA GPU acceleration for FFmpeg on ARM and POWER as well ([issue bytedeco/javacv#1894](https://github.com/bytedeco/javacv/issues/1894))
* Add support for HEVC and Opus to FLV format in presets for FFmpeg ([pull #1228](https://github.com/bytedeco/javacpp-presets/pull/1228))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public class AdaptiveAvgPool2dImpl extends AdaptiveAvgPool2dImplBase {
static { Loader.load(); }


public AdaptiveAvgPool2dImpl(@ByVal @Cast("torch::ExpandingArrayWithOptionalElem<2>*") LongPointer output_size) { super((Pointer)null); allocate(output_size); }
private native void allocate(@ByVal @Cast("torch::ExpandingArrayWithOptionalElem<2>*") LongPointer output_size);
public AdaptiveAvgPool2dImpl(@ByVal @Cast("torch::ExpandingArrayWithOptionalElem<2>*") LongOptional output_size) { super((Pointer)null); allocate(output_size); }
private native void allocate(@ByVal @Cast("torch::ExpandingArrayWithOptionalElem<2>*") LongOptional output_size);
public AdaptiveAvgPool2dImpl(
@Const @ByRef AdaptiveAvgPool2dOptions options_) { super((Pointer)null); allocate(options_); }
private native void allocate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public class AdaptiveAvgPool2dImplBase extends AdaptiveAvgPool2dImplCloneable {
/** Pointer cast constructor. Invokes {@link Pointer#Pointer(Pointer)}. */
public AdaptiveAvgPool2dImplBase(Pointer p) { super(p); }

public AdaptiveAvgPool2dImplBase(@ByVal @Cast("torch::ExpandingArrayWithOptionalElem<2>*") LongPointer output_size) { super((Pointer)null); allocate(output_size); }
private native void allocate(@ByVal @Cast("torch::ExpandingArrayWithOptionalElem<2>*") LongPointer output_size);
public AdaptiveAvgPool2dImplBase(@ByVal @Cast("torch::ExpandingArrayWithOptionalElem<2>*") LongOptional output_size) { super((Pointer)null); allocate(output_size); }
private native void allocate(@ByVal @Cast("torch::ExpandingArrayWithOptionalElem<2>*") LongOptional output_size);
public AdaptiveAvgPool2dImplBase(
@Const @ByRef AdaptiveAvgPool2dOptions options_) { super((Pointer)null); allocate(options_); }
private native void allocate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class AdaptiveAvgPool2dOptions extends Pointer {
/** Pointer cast constructor. Invokes {@link Pointer#Pointer(Pointer)}. */
public AdaptiveAvgPool2dOptions(Pointer p) { super(p); }

public AdaptiveAvgPool2dOptions(@ByVal @Cast("torch::ExpandingArrayWithOptionalElem<2>*") LongPointer output_size) { super((Pointer)null); allocate(output_size); }
private native void allocate(@ByVal @Cast("torch::ExpandingArrayWithOptionalElem<2>*") LongPointer output_size);
public native @Cast("torch::ExpandingArrayWithOptionalElem<2>*") @ByRef @NoException(true) LongPointer output_size();
public AdaptiveAvgPool2dOptions(@ByVal @Cast("torch::ExpandingArrayWithOptionalElem<2>*") LongOptional output_size) { super((Pointer)null); allocate(output_size); }
private native void allocate(@ByVal @Cast("torch::ExpandingArrayWithOptionalElem<2>*") LongOptional output_size);
public native @Cast("torch::ExpandingArrayWithOptionalElem<2>*") @ByRef @NoException(true) LongOptional output_size();
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public class AdaptiveAvgPool3dImpl extends AdaptiveAvgPool3dImplBase {
static { Loader.load(); }


public AdaptiveAvgPool3dImpl(@ByVal @Cast("torch::ExpandingArrayWithOptionalElem<3>*") LongPointer output_size) { super((Pointer)null); allocate(output_size); }
private native void allocate(@ByVal @Cast("torch::ExpandingArrayWithOptionalElem<3>*") LongPointer output_size);
public AdaptiveAvgPool3dImpl(@ByVal @Cast("torch::ExpandingArrayWithOptionalElem<3>*") LongOptional output_size) { super((Pointer)null); allocate(output_size); }
private native void allocate(@ByVal @Cast("torch::ExpandingArrayWithOptionalElem<3>*") LongOptional output_size);
public AdaptiveAvgPool3dImpl(
@Const @ByRef AdaptiveAvgPool3dOptions options_) { super((Pointer)null); allocate(options_); }
private native void allocate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public class AdaptiveAvgPool3dImplBase extends AdaptiveAvgPool3dImplCloneable {
/** Pointer cast constructor. Invokes {@link Pointer#Pointer(Pointer)}. */
public AdaptiveAvgPool3dImplBase(Pointer p) { super(p); }

public AdaptiveAvgPool3dImplBase(@ByVal @Cast("torch::ExpandingArrayWithOptionalElem<3>*") LongPointer output_size) { super((Pointer)null); allocate(output_size); }
private native void allocate(@ByVal @Cast("torch::ExpandingArrayWithOptionalElem<3>*") LongPointer output_size);
public AdaptiveAvgPool3dImplBase(@ByVal @Cast("torch::ExpandingArrayWithOptionalElem<3>*") LongOptional output_size) { super((Pointer)null); allocate(output_size); }
private native void allocate(@ByVal @Cast("torch::ExpandingArrayWithOptionalElem<3>*") LongOptional output_size);
public AdaptiveAvgPool3dImplBase(
@Const @ByRef AdaptiveAvgPool3dOptions options_) { super((Pointer)null); allocate(options_); }
private native void allocate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class AdaptiveAvgPool3dOptions extends Pointer {
/** Pointer cast constructor. Invokes {@link Pointer#Pointer(Pointer)}. */
public AdaptiveAvgPool3dOptions(Pointer p) { super(p); }

public AdaptiveAvgPool3dOptions(@ByVal @Cast("torch::ExpandingArrayWithOptionalElem<3>*") LongPointer output_size) { super((Pointer)null); allocate(output_size); }
private native void allocate(@ByVal @Cast("torch::ExpandingArrayWithOptionalElem<3>*") LongPointer output_size);
public native @Cast("torch::ExpandingArrayWithOptionalElem<3>*") @ByRef @NoException(true) LongPointer output_size();
public AdaptiveAvgPool3dOptions(@ByVal @Cast("torch::ExpandingArrayWithOptionalElem<3>*") LongOptional output_size) { super((Pointer)null); allocate(output_size); }
private native void allocate(@ByVal @Cast("torch::ExpandingArrayWithOptionalElem<3>*") LongOptional output_size);
public native @Cast("torch::ExpandingArrayWithOptionalElem<3>*") @ByRef @NoException(true) LongOptional output_size();
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public class AdaptiveMaxPool2dImpl extends AdaptiveMaxPool2dImplBase {
static { Loader.load(); }


public AdaptiveMaxPool2dImpl(@ByVal @Cast("torch::ExpandingArrayWithOptionalElem<2>*") LongPointer output_size) { super((Pointer)null); allocate(output_size); }
private native void allocate(@ByVal @Cast("torch::ExpandingArrayWithOptionalElem<2>*") LongPointer output_size);
public AdaptiveMaxPool2dImpl(@ByVal @Cast("torch::ExpandingArrayWithOptionalElem<2>*") LongOptional output_size) { super((Pointer)null); allocate(output_size); }
private native void allocate(@ByVal @Cast("torch::ExpandingArrayWithOptionalElem<2>*") LongOptional output_size);
public AdaptiveMaxPool2dImpl(
@Const @ByRef AdaptiveMaxPool2dOptions options_) { super((Pointer)null); allocate(options_); }
private native void allocate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public class AdaptiveMaxPool2dImplBase extends AdaptiveMaxPool2dImplCloneable {
/** Pointer cast constructor. Invokes {@link Pointer#Pointer(Pointer)}. */
public AdaptiveMaxPool2dImplBase(Pointer p) { super(p); }

public AdaptiveMaxPool2dImplBase(@ByVal @Cast("torch::ExpandingArrayWithOptionalElem<2>*") LongPointer output_size) { super((Pointer)null); allocate(output_size); }
private native void allocate(@ByVal @Cast("torch::ExpandingArrayWithOptionalElem<2>*") LongPointer output_size);
public AdaptiveMaxPool2dImplBase(@ByVal @Cast("torch::ExpandingArrayWithOptionalElem<2>*") LongOptional output_size) { super((Pointer)null); allocate(output_size); }
private native void allocate(@ByVal @Cast("torch::ExpandingArrayWithOptionalElem<2>*") LongOptional output_size);
public AdaptiveMaxPool2dImplBase(
@Const @ByRef AdaptiveMaxPool2dOptions options_) { super((Pointer)null); allocate(options_); }
private native void allocate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class AdaptiveMaxPool2dOptions extends Pointer {
/** Pointer cast constructor. Invokes {@link Pointer#Pointer(Pointer)}. */
public AdaptiveMaxPool2dOptions(Pointer p) { super(p); }

public AdaptiveMaxPool2dOptions(@ByVal @Cast("torch::ExpandingArrayWithOptionalElem<2>*") LongPointer output_size) { super((Pointer)null); allocate(output_size); }
private native void allocate(@ByVal @Cast("torch::ExpandingArrayWithOptionalElem<2>*") LongPointer output_size);
public native @Cast("torch::ExpandingArrayWithOptionalElem<2>*") @ByRef @NoException(true) LongPointer output_size();
public AdaptiveMaxPool2dOptions(@ByVal @Cast("torch::ExpandingArrayWithOptionalElem<2>*") LongOptional output_size) { super((Pointer)null); allocate(output_size); }
private native void allocate(@ByVal @Cast("torch::ExpandingArrayWithOptionalElem<2>*") LongOptional output_size);
public native @Cast("torch::ExpandingArrayWithOptionalElem<2>*") @ByRef @NoException(true) LongOptional output_size();
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public class AdaptiveMaxPool3dImpl extends AdaptiveMaxPool3dImplBase {
static { Loader.load(); }


public AdaptiveMaxPool3dImpl(@ByVal @Cast("torch::ExpandingArrayWithOptionalElem<3>*") LongPointer output_size) { super((Pointer)null); allocate(output_size); }
private native void allocate(@ByVal @Cast("torch::ExpandingArrayWithOptionalElem<3>*") LongPointer output_size);
public AdaptiveMaxPool3dImpl(@ByVal @Cast("torch::ExpandingArrayWithOptionalElem<3>*") LongOptional output_size) { super((Pointer)null); allocate(output_size); }
private native void allocate(@ByVal @Cast("torch::ExpandingArrayWithOptionalElem<3>*") LongOptional output_size);
public AdaptiveMaxPool3dImpl(
@Const @ByRef AdaptiveMaxPool3dOptions options_) { super((Pointer)null); allocate(options_); }
private native void allocate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public class AdaptiveMaxPool3dImplBase extends AdaptiveMaxPool3dImplCloneable {
/** Pointer cast constructor. Invokes {@link Pointer#Pointer(Pointer)}. */
public AdaptiveMaxPool3dImplBase(Pointer p) { super(p); }

public AdaptiveMaxPool3dImplBase(@ByVal @Cast("torch::ExpandingArrayWithOptionalElem<3>*") LongPointer output_size) { super((Pointer)null); allocate(output_size); }
private native void allocate(@ByVal @Cast("torch::ExpandingArrayWithOptionalElem<3>*") LongPointer output_size);
public AdaptiveMaxPool3dImplBase(@ByVal @Cast("torch::ExpandingArrayWithOptionalElem<3>*") LongOptional output_size) { super((Pointer)null); allocate(output_size); }
private native void allocate(@ByVal @Cast("torch::ExpandingArrayWithOptionalElem<3>*") LongOptional output_size);
public AdaptiveMaxPool3dImplBase(
@Const @ByRef AdaptiveMaxPool3dOptions options_) { super((Pointer)null); allocate(options_); }
private native void allocate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class AdaptiveMaxPool3dOptions extends Pointer {
/** Pointer cast constructor. Invokes {@link Pointer#Pointer(Pointer)}. */
public AdaptiveMaxPool3dOptions(Pointer p) { super(p); }

public AdaptiveMaxPool3dOptions(@ByVal @Cast("torch::ExpandingArrayWithOptionalElem<3>*") LongPointer output_size) { super((Pointer)null); allocate(output_size); }
private native void allocate(@ByVal @Cast("torch::ExpandingArrayWithOptionalElem<3>*") LongPointer output_size);
public native @Cast("torch::ExpandingArrayWithOptionalElem<3>*") @ByRef @NoException(true) LongPointer output_size();
public AdaptiveMaxPool3dOptions(@ByVal @Cast("torch::ExpandingArrayWithOptionalElem<3>*") LongOptional output_size) { super((Pointer)null); allocate(output_size); }
private native void allocate(@ByVal @Cast("torch::ExpandingArrayWithOptionalElem<3>*") LongOptional output_size);
public native @Cast("torch::ExpandingArrayWithOptionalElem<3>*") @ByRef @NoException(true) LongOptional output_size();
}
86 changes: 86 additions & 0 deletions pytorch/src/gen/java/org/bytedeco/pytorch/LongOptionalVector.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// 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::vector<c10::optional<int64_t> >") @Properties(inherit = org.bytedeco.pytorch.presets.torch.class)
public class LongOptionalVector extends Pointer {
static { Loader.load(); }
/** Pointer cast constructor. Invokes {@link Pointer#Pointer(Pointer)}. */
public LongOptionalVector(Pointer p) { super(p); }
public LongOptionalVector(LongOptional value) { this(1); put(0, value); }
public LongOptionalVector(LongOptional ... array) { this(array.length); put(array); }
public LongOptionalVector() { allocate(); }
public LongOptionalVector(long n) { allocate(n); }
private native void allocate();
private native void allocate(@Cast("size_t") long n);
public native @Name("operator =") @ByRef LongOptionalVector put(@ByRef LongOptionalVector x);

public boolean empty() { return size() == 0; }
public native long size();
public void clear() { resize(0); }
public native void resize(@Cast("size_t") long n);

@Index(function = "at") public native @ByRef LongOptional get(@Cast("size_t") long i);
public native LongOptionalVector put(@Cast("size_t") long i, LongOptional value);

public native @ByVal Iterator insert(@ByVal Iterator pos, @ByRef LongOptional value);
public native @ByVal Iterator 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 *") @ByRef @Const LongOptional get();
}

public LongOptional[] get() {
LongOptional[] array = new LongOptional[size() < Integer.MAX_VALUE ? (int)size() : Integer.MAX_VALUE];
for (int i = 0; i < array.length; i++) {
array[i] = get(i);
}
return array;
}
@Override public String toString() {
return java.util.Arrays.toString(get());
}

public LongOptional pop_back() {
long size = size();
LongOptional value = get(size - 1);
resize(size - 1);
return value;
}
public LongOptionalVector push_back(LongOptional value) {
long size = size();
resize(size + 1);
return put(size, value);
}
public LongOptionalVector put(LongOptional value) {
if (size() != 1) { resize(1); }
return put(0, value);
}
public LongOptionalVector put(LongOptional ... array) {
if (size() != array.length) { resize(array.length); }
for (int i = 0; i < array.length; i++) {
put(i, array[i]);
}
return this;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public class LongVaryingShape extends Pointer {
public LongVaryingShape() { super((Pointer)null); allocate(); }
private native void allocate();

public LongVaryingShape(@StdVector LongOptional dims) { super((Pointer)null); allocate(dims); }
private native void allocate(@StdVector LongOptional dims);
public LongVaryingShape(@ByVal @Cast("c10::VaryingShape<int64_t>::ListOfOptionalElements*") LongOptionalVector dims) { super((Pointer)null); allocate(dims); }
private native void allocate(@ByVal @Cast("c10::VaryingShape<int64_t>::ListOfOptionalElements*") LongOptionalVector dims);

public LongVaryingShape(@Cast("size_t") long size) { super((Pointer)null); allocate(size); }
private native void allocate(@Cast("size_t") long size);
Expand Down
4 changes: 2 additions & 2 deletions pytorch/src/gen/java/org/bytedeco/pytorch/SymbolicShape.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ public class SymbolicShape extends Pointer {
private native void allocate(@ByVal SizeTOptional rank);

// Mix of known and unknown ranks
public SymbolicShape(@StdVector LongOptional dims) { super((Pointer)null); allocate(dims); }
private native void allocate(@StdVector LongOptional dims);
public SymbolicShape(@Const @ByRef LongOptionalVector dims) { super((Pointer)null); allocate(dims); }
private native void allocate(@Const @ByRef LongOptionalVector dims);

public native void dump();

Expand Down
Loading

0 comments on commit 94268bb

Please sign in to comment.