Skip to content

Commit

Permalink
Correctly map ListElementReference::swap
Browse files Browse the repository at this point in the history
  • Loading branch information
HGuillemet committed Jan 3, 2024
1 parent aa25c87 commit 1297f01
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ public class BooleanElementReference extends Pointer {

public native @Const @ByRef IValue get();


private static native @Namespace @Name("swap") void swap(@ByRef(true) BooleanElementReference lhs, @ByRef(true) BooleanElementReference rhs);
public void swap(BooleanElementReference rhs) { swap(this, rhs); }



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ public class DoubleComplexElementReference extends Pointer {

public native @Const @ByRef IValue get();


private static native @Namespace @Name("swap") void swap(@ByRef(true) DoubleComplexElementReference lhs, @ByRef(true) DoubleComplexElementReference rhs);
public void swap(DoubleComplexElementReference rhs) { swap(this, rhs); }



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ public class DoubleElementReference extends Pointer {

public native @Const @ByRef IValue get();


private static native @Namespace @Name("swap") void swap(@ByRef(true) DoubleElementReference lhs, @ByRef(true) DoubleElementReference rhs);
public void swap(DoubleElementReference rhs) { swap(this, rhs); }



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ public class FuturePtrElementReference extends Pointer {

public native @Const @ByRef IValue get();


private static native @Namespace @Name("swap") void swap(@ByRef(true) FuturePtrElementReference lhs, @ByRef(true) FuturePtrElementReference rhs);
public void swap(FuturePtrElementReference rhs) { swap(this, rhs); }



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ public class GenericElementReference extends Pointer {

public native @Const @ByRef IValue get();


private static native @Namespace @Name("swap") void swap(@ByRef(true) GenericElementReference lhs, @ByRef(true) GenericElementReference rhs);
public void swap(GenericElementReference rhs) { swap(this, rhs); }



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ public class LongElementReference extends Pointer {

public native @Const @ByRef IValue get();


private static native @Namespace @Name("swap") void swap(@ByRef(true) LongElementReference lhs, @ByRef(true) LongElementReference rhs);
public void swap(LongElementReference rhs) { swap(this, rhs); }



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ public class TensorElementReference extends Pointer {

public native @Const @ByRef IValue get();


private static native @Namespace @Name("swap") void swap(@ByRef(true) TensorElementReference lhs, @ByRef(true) TensorElementReference rhs);
public void swap(TensorElementReference rhs) { swap(this, rhs); }



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ public class TensorOptionalElementReference extends Pointer {

public native @Const @ByRef IValue get();


private static native @Namespace @Name("swap") void swap(@ByRef(true) TensorOptionalElementReference lhs, @ByRef(true) TensorOptionalElementReference rhs);
public void swap(TensorOptionalElementReference rhs) { swap(this, rhs); }



Expand Down
13 changes: 5 additions & 8 deletions pytorch/src/main/java/org/bytedeco/pytorch/presets/torch.java
Original file line number Diff line number Diff line change
Expand Up @@ -761,8 +761,6 @@ public void map(InfoMap infoMap) {
}) {
ai.mapList(infoMap);
}
// swap is a friend templated function. Parser fails to perform template substitution in this case.
infoMap.put(new Info("c10::impl::ListElementReference::swap<T,Iterator>").skip());
// friendly global setting lost + full qualification not resolved by parser
infoMap.put(new Info("impl::ptr_to_first_element(const c10::List<c10::IValue>&)").javaNames("ptr_to_first_element").annotations("@Name(\"c10::impl::ptr_to_first_element\")").friendly());

Expand Down Expand Up @@ -2614,11 +2612,9 @@ void mapList(InfoMap infoMap) {
.put(new Info(template("operator std::conditional_t", template("std::is_reference", template("c10::detail::ivalue_to_const_ref_overload_return", t) + "::type") + "::value", "const " + t + "&", t) + "()")
.javaNames("get" + baseJavaName))
.put(new Info(template("c10::List", t) + "::size_type").valueTypes("long"))
.put(new Info(
template("c10::impl::ListElementReference", t, "typename c10::detail::ListImpl::list_type::iterator") + "::swap<T,Iterator>",
template("c10::impl::ListElementReference", t, "c10::detail::ListImpl::list_type::iterator") + "::swap<T,Iterator>",
template("c10::impl::ListElementReference", t, template("std::vector", t) + "::iterator") + "::swap<T,Iterator>")
.skip());
.put(new Info(template("c10::impl::ListElementReference", t, "c10::detail::ListImpl::list_type::iterator") + "::" + template("swap", t, "c10::detail::ListImpl::list_type::iterator"))
.javaNames("swap").friendly())
;
infoMap.put(new Info(template("c10::List", t) + "::operator []").skip()) // Returns an internal_reference_type by value, which is a ListElementReference, whose copy constructor is disabled.
.put(new Info(
template("c10::impl::ListIterator", t, "c10::detail::ListImpl::list_type::iterator") + "::operator []",
Expand All @@ -2627,7 +2623,8 @@ void mapList(InfoMap infoMap) {
.put(new Info(template("std::conditional_t", template("std::is_reference", template("c10::detail::ivalue_to_const_ref_overload_return", t) + "::type") + "::value", "const " + t + "&", t))
.pointerTypes(itPointerType).valueTypes(elementValueType))

.put(new Info(template("c10::impl::swap", t, "typename c10::detail::ListImpl::list_type::iterator")).javaNames("swap").friendly());
.put(new Info(template("c10::impl::swap", t, "typename c10::detail::ListImpl::list_type::iterator")).javaNames("swap"))
;

// Some List constructors are only for specific instances
if (baseJavaName.equals("Generic"))
Expand Down

0 comments on commit 1297f01

Please sign in to comment.