From 337f6f957ad2e29ab8552e421ec355d8459b3618 Mon Sep 17 00:00:00 2001 From: ds5678 <49847914+ds5678@users.noreply.github.com> Date: Thu, 20 Nov 2025 21:46:23 -0800 Subject: [PATCH] Rename parameters in native code to be more standardized This aligns parameter naming for these functions with the rest of the project. See also: https://github.com/AssetRipper/AssetRipper.Bindings.LibTorchSharp/blob/a76753d26df195f667c003f8f10b3085882168a0/AssetRipper.Bindings.LibTorchSharp.SourceGenerator/ParameterNameChanges.cs#L7-L12 --- src/Native/LibTorchSharp/THSJIT.cpp | 20 ++++++++++---------- src/Native/LibTorchSharp/THSJIT.h | 10 +++++----- src/Native/LibTorchSharp/THSModule.cpp | 4 ++-- src/Native/LibTorchSharp/THSNN.h | 2 +- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/Native/LibTorchSharp/THSJIT.cpp b/src/Native/LibTorchSharp/THSJIT.cpp index a0a4a5d0c..740656667 100644 --- a/src/Native/LibTorchSharp/THSJIT.cpp +++ b/src/Native/LibTorchSharp/THSJIT.cpp @@ -113,11 +113,11 @@ void THSJIT_Module_modules(const JITModule module, JITModule* (*allocator)(size_ } void THSJIT_Module_named_modules(const JITModule module, - JITModule* (*allocator)(size_t length), + JITModule* (*allocator1)(size_t length), const char** (*allocator2)(size_t length)) { auto modules = (*module)->named_modules(); - JITModule* result = allocator(modules.size()); + JITModule* result = allocator1(modules.size()); const char** names = allocator2(modules.size()); int i = 0; for (const auto& child : modules) { @@ -129,11 +129,11 @@ void THSJIT_Module_named_modules(const JITModule module, } void THSJIT_Module_named_children(const JITModule module, - JITModule* (*allocator)(size_t length), + JITModule* (*allocator1)(size_t length), const char** (*allocator2)(size_t length)) { auto modules = (*module)->named_children(); - JITModule* result = allocator(modules.size()); + JITModule* result = allocator1(modules.size()); const char** names = allocator2(modules.size()); int i = 0; for (const auto& child : modules) { @@ -155,11 +155,11 @@ void THSJIT_Module_parameters(const JITModule module, Tensor* (*allocator)(size_ } void THSJIT_Module_named_parameters(const JITModule module, - Tensor* (*allocator)(size_t length), + Tensor* (*allocator1)(size_t length), const char** (*allocator2)(size_t length)) { auto parameters = (*module)->named_parameters(); - Tensor* result = allocator(parameters.size()); + Tensor* result = allocator1(parameters.size()); const char** names = allocator2(parameters.size()); int i = 0; for (const auto& child : parameters) { @@ -170,11 +170,11 @@ void THSJIT_Module_named_parameters(const JITModule module, } void THSJIT_Module_named_buffers(const JITModule module, - Tensor* (*allocator)(size_t length), + Tensor* (*allocator1)(size_t length), const char** (*allocator2)(size_t length)) { auto parameters = (*module)->named_buffers(); - Tensor* result = allocator(parameters.size()); + Tensor* result = allocator1(parameters.size()); const char** names = allocator2(parameters.size()); int i = 0; for (const auto& child : parameters) { @@ -185,11 +185,11 @@ void THSJIT_Module_named_buffers(const JITModule module, } void THSJIT_Module_named_attributes(const JITModule module, bool recurse, - Tensor* (*allocator)(size_t length), + Tensor* (*allocator1)(size_t length), const char** (*allocator2)(size_t length)) { auto attributes = (*module)->named_attributes(recurse); - Tensor* result = allocator(attributes.size()); + Tensor* result = allocator1(attributes.size()); const char** names = allocator2(attributes.size()); int i = 0; for (const auto& child : attributes) { diff --git a/src/Native/LibTorchSharp/THSJIT.h b/src/Native/LibTorchSharp/THSJIT.h index 81e6d51ad..065856cf7 100644 --- a/src/Native/LibTorchSharp/THSJIT.h +++ b/src/Native/LibTorchSharp/THSJIT.h @@ -64,26 +64,26 @@ EXPORT_API(void) THSJIT_TensorType_dispose(const JITTensorType type); EXPORT_API(void) THSJIT_Module_modules(const JITModule module, JITModule* (*allocator)(size_t length)); EXPORT_API(void) THSJIT_Module_named_modules(const JITModule module, - JITModule* (*allocator)(size_t length), + JITModule* (*allocator1)(size_t length), const char** (*allocator2)(size_t length)); EXPORT_API(void) THSJIT_Module_named_children(const JITModule module, - JITModule* (*allocator)(size_t length), + JITModule* (*allocator1)(size_t length), const char** (*allocator2)(size_t length)); EXPORT_API(JITMethod) THSJIT_Module_get_method(const JITModule module, const char* name); EXPORT_API(void) THSJIT_Module_parameters(const JITModule module, Tensor* (*allocator)(size_t length)); EXPORT_API(void) THSJIT_Module_named_parameters(const JITModule module, - Tensor* (*allocator)(size_t length), + Tensor* (*allocator1)(size_t length), const char** (*allocator2)(size_t length)); EXPORT_API(void) THSJIT_Module_named_buffers(const JITModule module, - Tensor* (*allocator)(size_t length), + Tensor* (*allocator1)(size_t length), const char** (*allocator2)(size_t length)); EXPORT_API(void) THSJIT_Module_named_attributes(const JITModule module, bool recurse, - Tensor* (*allocator)(size_t length), + Tensor* (*allocator1)(size_t length), const char** (*allocator2)(size_t length)); EXPORT_API(void) THSJIT_Module_set_attribute(const JITModule module, const char* name, Tensor tensor); diff --git a/src/Native/LibTorchSharp/THSModule.cpp b/src/Native/LibTorchSharp/THSModule.cpp index 00c00efaf..3878bb83c 100644 --- a/src/Native/LibTorchSharp/THSModule.cpp +++ b/src/Native/LibTorchSharp/THSModule.cpp @@ -98,10 +98,10 @@ Tensor THSNN_Module_get_parameter(const NNModule module, const char* name) CATCH_TENSOR(*(*module)->named_parameters().find(name)); } -void THSNN_Module_get_parameters(const NNModule module, Tensor* (*allocator1)(size_t length), bool recurse) +void THSNN_Module_get_parameters(const NNModule module, Tensor* (*allocator)(size_t length), bool recurse) { auto parameters = (*module)->parameters(recurse); - Tensor* result1 = allocator1(parameters.size()); + Tensor* result1 = allocator(parameters.size()); for (size_t i = 0; i < parameters.size(); i++) { diff --git a/src/Native/LibTorchSharp/THSNN.h b/src/Native/LibTorchSharp/THSNN.h index 3dab43f90..0e13d92e3 100644 --- a/src/Native/LibTorchSharp/THSNN.h +++ b/src/Native/LibTorchSharp/THSNN.h @@ -15,7 +15,7 @@ EXPORT_API(void) THSNN_Module_get_named_parameters(const NNModule module, EXPORT_API(void) THSNN_Module_get_named_buffers(const NNModule module, Tensor* (*allocator1)(size_t length), const char** (*allocator2)(size_t length)); EXPORT_API(void) THSNN_Module_get_named_children(const NNModule module, NNModule* (*allocator1)(size_t length), const char** (*allocator2)(size_t length)); EXPORT_API(void) THSNN_Module_get_named_modules(const NNModule module, NNModule* (*allocator1)(size_t length), const char** (*allocator2)(size_t length)); -EXPORT_API(void) THSNN_Module_get_parameters(const NNModule module, Tensor* (*allocator1)(size_t length), bool recurse); +EXPORT_API(void) THSNN_Module_get_parameters(const NNModule module, Tensor* (*allocator)(size_t length), bool recurse); EXPORT_API(int) THSNN_Module_is_training(NNModule module); EXPORT_API(void) THSNN_Module_train(NNModule module, bool on); EXPORT_API(long) THSNN_Module_children_size(const NNModule module);