codegen/generate_functions.rb in torch-rb-0.11.0 vs codegen/generate_functions.rb in torch-rb-0.11.1
- old
+ new
@@ -126,12 +126,15 @@
}
write_file("#{type}_functions.cpp", contents)
end
def write_file(name, contents)
- path = File.expand_path("../ext/torch", __dir__)
- File.write(File.join(path, name), contents)
+ path = File.join(File.expand_path("../ext/torch", __dir__), name)
+ # only write if changed to improve compile times in development
+ if !File.exist?(path) || File.read(path) != contents
+ File.write(path, contents)
+ end
end
def generate_attach_def(name, type, def_method)
ruby_name =
if name.end_with?("_")
@@ -140,17 +143,17 @@
"#{name[3..-1]}?"
else
name
end
- ruby_name = "_#{ruby_name}" if ["size", "stride", "random!", "stft"].include?(ruby_name)
+ ruby_name = "_#{ruby_name}" if ["size", "stride", "random!"].include?(ruby_name)
ruby_name = ruby_name.sub(/\Afft_/, "") if type == "fft"
ruby_name = ruby_name.sub(/\Alinalg_/, "") if type == "linalg"
ruby_name = ruby_name.sub(/\Aspecial_/, "") if type == "special"
ruby_name = ruby_name.sub(/\Asparse_/, "") if type == "sparse"
ruby_name = name if name.start_with?("__")
- # cast for Ruby < 2.7 https://github.com/thisMagpie/fftw/issues/22#issuecomment-49508900
+ # cast for Ruby < 3.0 https://github.com/thisMagpie/fftw/issues/22#issuecomment-49508900
cast = RUBY_VERSION.to_f > 2.7 ? "" : "(VALUE (*)(...)) "
"rb_#{def_method}(m, \"#{ruby_name}\", #{cast}#{full_name(name, type)}, -1);"
end