markups_subexpr;
- markups_subexpr.push_back("\n+\\*\\s+"); // lists
- markups_subexpr.push_back("\n{2,}"); // paragraphs
- markups_subexpr.push_back("`{3,}\\s*[^\\s\n]*\\s*\n"); // code blocks
- markups_subexpr.push_back("`+"); // inlined code and code blocks
- markups_subexpr.push_back("\\*{1,2}\\b"); // text emphasis
- markups_subexpr.push_back("\\["); // hyperlinks
- const RE2 markup_expr("(" + absl::StrJoin(markups_subexpr, "|") + ")");
-
- bool in_list = false;
- string input = inp;
- while (true) {
- string text, markup;
- if (!FindAndCut(&input, markup_expr, &text, &markup)) {
- javadoc_text << input;
- break; // end of loop
- }
- javadoc_text << text;
- if (absl::StartsWith(markup, "\n")) {
- javadoc_text << "\n";
- if (absl::StrContains(markup, "*")) {
- // new list item
- javadoc_text << (in_list ? "\n" : "\n") << "- \n";
- in_list = true;
- } else if (in_list) {
- // end of list
- javadoc_text << "
\n
\n";
- in_list = false;
- } else if (!absl::StartsWith(input, "```")) {
- // new paragraph (not required if a block follows)
- javadoc_text << "\n";
- }
- } else if (absl::StartsWith(markup, "```")) {
- // code blocks
- if (FindAndCut(&input, "(```\\s*\n*)", &text)) {
- javadoc_text << "
{@code\n" << text << "}\n";
- } else {
- javadoc_text << markup;
- }
- } else if (absl::StartsWith("(" + markup + ")", "`")) {
- // inlined code
- if (FindAndCut(&input, markup, &text)) {
- javadoc_text << "{@code " << text << "}";
- } else {
- javadoc_text << markup;
- }
- } else if (markup == "**") {
- // text emphasis (strong)
- if (FindAndCut(&input, "(\\b\\*{2})", &text)) {
- javadoc_text << "" << ParseDocumentation(text) << "";
- } else {
- javadoc_text << markup;
- }
- } else if (markup == "*") {
- // text emphasis (normal)
- if (FindAndCut(&input, "(\\b\\*{1})", &text)) {
- javadoc_text << "" << ParseDocumentation(text) << "";
- } else {
- javadoc_text << markup;
- }
- } else if (absl::StartsWith(markup, "[")) {
- // hyperlinks
- string label;
- string link;
- if (RE2::PartialMatch(input, "([^\\[]+)\\]\\((http.+)\\)", &label,
- &link) &&
- absl::StartsWith(input, label + link)) {
- input = input.substr(label.size() + link.size());
- javadoc_text << ""
- << ParseDocumentation(label) << "";
- } else {
- javadoc_text << markup;
- }
- } else {
- // safe fallback
- javadoc_text << markup;
- }
- }
- return javadoc_text.str();
-}
-
-ArgumentSpec CreateInput(const OpDef_ArgDef& input_def,
- const ApiDef::Arg& input_api_def,
- TypeResolver* type_resolver) {
- bool iterable = false;
- Type type = type_resolver->TypeOf(input_def, &iterable);
- Type var_type =
- Type::Interface("Operand", "org.tensorflow").add_parameter(type);
- if (iterable) {
- var_type = Type::IterableOf(var_type);
- }
- return ArgumentSpec(
- input_api_def.name(),
- Variable::Create(SnakeToCamelCase(input_api_def.rename_to()), var_type),
- type, ParseDocumentation(input_api_def.description()), iterable);
-}
-
-AttributeSpec CreateAttribute(const OpDef_AttrDef& attr_def,
- const ApiDef::Attr& attr_api_def,
- TypeResolver* type_resolver) {
- bool iterable = false;
- std::pair types = type_resolver->TypesOf(attr_def, &iterable);
- Type var_type = types.first.kind() == Type::GENERIC
- ? Type::DataTypeOf(types.first)
- : types.first;
- if (iterable) {
- var_type = Type::ListOf(var_type);
- }
- return AttributeSpec(
- attr_api_def.name(),
- Variable::Create(SnakeToCamelCase(attr_api_def.rename_to()), var_type),
- types.first, types.second, ParseDocumentation(attr_api_def.description()),
- iterable,
- attr_def.has_default_value() ? &attr_def.default_value() : nullptr);
-}
-
-ArgumentSpec CreateOutput(const OpDef_ArgDef& output_def,
- const ApiDef::Arg& output_api,
- TypeResolver* type_resolver) {
- bool iterable = false;
- Type type = type_resolver->TypeOf(output_def, &iterable);
- Type var_type = Type::Class("Output", "org.tensorflow").add_parameter(type);
- if (iterable) {
- var_type = Type::ListOf(var_type);
- }
- return ArgumentSpec(
- output_api.name(),
- Variable::Create(SnakeToCamelCase(output_api.rename_to()), var_type),
- type, ParseDocumentation(output_api.description()), iterable);
-}
-
-EndpointSpec CreateEndpoint(const OpDef& op_def, const ApiDef& api_def,
- const ApiDef_Endpoint& endpoint_def) {
- const string& endpoint_name = endpoint_def.name();
- string package;
- string name;
- size_t name_pos = endpoint_name.find_last_of('.');
- if (name_pos != string::npos) {
- package = endpoint_name.substr(0, name_pos);
- name = endpoint_name.substr(name_pos + 1);
- } else {
- package = "core"; // generate unclassified ops in the 'core' package
- name = endpoint_def.name();
- }
- return EndpointSpec(package, name,
- Javadoc::Create(ParseDocumentation(api_def.summary()))
- .details(ParseDocumentation(api_def.description())));
-}
-
-} // namespace
-
-OpSpec OpSpec::Create(const OpDef& op_def, const ApiDef& api_def) {
- OpSpec op(api_def.graph_op_name(), api_def.visibility() == ApiDef::HIDDEN,
- op_def.deprecation().explanation());
- TypeResolver type_resolver(op_def);
- for (const string& next_input_name : api_def.arg_order()) {
- for (int i = 0; i < op_def.input_arg().size(); ++i) {
- if (op_def.input_arg(i).name() == next_input_name) {
- op.inputs_.push_back(CreateInput(op_def.input_arg(i), api_def.in_arg(i),
- &type_resolver));
- break;
- }
- }
- }
- for (int i = 0; i < op_def.attr().size(); ++i) {
- // do not parse attributes already visited, they have probably been inferred
- // before as an input argument type
- if (!type_resolver.IsAttributeVisited(op_def.attr(i).name())) {
- AttributeSpec attr =
- CreateAttribute(op_def.attr(i), api_def.attr(i), &type_resolver);
- // attributes with a default value are optional
- if (attr.has_default_value() && attr.type().kind() != Type::GENERIC) {
- op.optional_attributes_.push_back(attr);
- } else {
- op.attributes_.push_back(attr);
- }
- }
- }
- for (int i = 0; i < op_def.output_arg().size(); ++i) {
- op.outputs_.push_back(
- CreateOutput(op_def.output_arg(i), api_def.out_arg(i), &type_resolver));
- }
- for (const auto& endpoint_def : api_def.endpoint()) {
- op.endpoints_.push_back(CreateEndpoint(op_def, api_def, endpoint_def));
- }
- return op;
-}
-
-} // namespace java
-} // namespace tensorflow
diff --git a/tensorflow-core/tensorflow-core-api/src/bazel/op_generator/op_specs.h b/tensorflow-core/tensorflow-core-api/src/bazel/op_generator/op_specs.h
deleted file mode 100644
index 40d72656561..00000000000
--- a/tensorflow-core/tensorflow-core-api/src/bazel/op_generator/op_specs.h
+++ /dev/null
@@ -1,180 +0,0 @@
-/* Copyright 2018 The TensorFlow Authors. All Rights Reserved.
-
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-==============================================================================*/
-
-#ifndef TENSORFLOW_JAVA_OP_GENERATOR_OP_SPECS_H_
-#define TENSORFLOW_JAVA_OP_GENERATOR_OP_SPECS_H_
-
-#include
-#include
-
-#include "tensorflow/core/framework/api_def.pb.h"
-#include "tensorflow/core/framework/attr_value.pb.h"
-#include "tensorflow/core/framework/op_def.pb.h"
-
-#include "java_defs.h"
-
-namespace tensorflow {
-namespace java {
-
-constexpr const char kDefaultEndpointPackage[] = "core";
-
-class EndpointSpec {
- public:
- // A specification for an operation endpoint
- //
- // package: package of this endpoint (from which also derives its package)
- // name: name of this endpoint class
- // javadoc: the endpoint class documentation
- // TODO(annarev): hardcode depcreated to false until deprecated is possible
- EndpointSpec(const string& package, const string& name,
- const Javadoc& javadoc)
- : package_(package), name_(name), javadoc_(javadoc), deprecated_(false) {}
-
- const string& package() const { return package_; }
- const string& name() const { return name_; }
- const Javadoc& javadoc() const { return javadoc_; }
- bool deprecated() const { return deprecated_; }
-
- private:
- const string package_;
- const string name_;
- const Javadoc javadoc_;
- const bool deprecated_;
-};
-
-class ArgumentSpec {
- public:
- // A specification for an operation argument
- //
- // op_def_name: argument name, as known by TensorFlow core
- // var: a variable to represent this argument in Java
- // type: the tensor type of this argument
- // description: a description of this argument, in javadoc
- // iterable: true if this argument is a list
- ArgumentSpec(const string& op_def_name, const Variable& var, const Type& type,
- const string& description, bool iterable)
- : op_def_name_(op_def_name),
- var_(var),
- type_(type),
- description_(description),
- iterable_(iterable) {}
-
- const string& op_def_name() const { return op_def_name_; }
- const Variable& var() const { return var_; }
- const Type& type() const { return type_; }
- const string& description() const { return description_; }
- bool iterable() const { return iterable_; }
-
- private:
- const string op_def_name_;
- const Variable var_;
- const Type type_;
- const string description_;
- const bool iterable_;
-};
-
-class AttributeSpec {
- public:
- // A specification for an operation attribute
- //
- // op_def_name: attribute name, as known by TensorFlow core
- // var: a variable to represent this attribute in Java
- // type: the type of this attribute
- // jni_type: the type of this attribute in JNI layer (see OperationBuilder)
- // description: a description of this attribute, in javadoc
- // iterable: true if this attribute is a list
- // default_value: default value for this attribute or nullptr if none. Any
- // value referenced by this pointer must outlive the lifetime
- // of the AttributeSpec. This is guaranteed if the value is
- // issued by an OpDef of the global OpRegistry.
- AttributeSpec(const string& op_def_name, const Variable& var,
- const Type& type, const Type& jni_type,
- const string& description, bool iterable,
- const AttrValue* default_value)
- : op_def_name_(op_def_name),
- var_(var),
- type_(type),
- description_(description),
- iterable_(iterable),
- jni_type_(jni_type),
- default_value_(default_value) {}
-
- const string& op_def_name() const { return op_def_name_; }
- const Variable& var() const { return var_; }
- const Type& type() const { return type_; }
- const string& description() const { return description_; }
- bool iterable() const { return iterable_; }
- const Type& jni_type() const { return jni_type_; }
- bool has_default_value() const { return default_value_ != nullptr; }
- const AttrValue* default_value() const { return default_value_; }
-
- private:
- const string op_def_name_;
- const Variable var_;
- const Type type_;
- const string description_;
- const bool iterable_;
- const Type jni_type_;
- const AttrValue* default_value_;
-};
-
-class OpSpec {
- public:
- // Parses an op definition and its API to produce a specification used for
- // rendering its Java wrapper
- //
- // op_def: Op definition
- // api_def: Op API definition
- static OpSpec Create(const OpDef& op_def, const ApiDef& api_def);
-
- const string& graph_op_name() const { return graph_op_name_; }
- bool hidden() const { return hidden_; }
- const string& deprecation_explanation() const {
- return deprecation_explanation_;
- }
- const std::vector endpoints() const { return endpoints_; }
- const std::vector& inputs() const { return inputs_; }
- const std::vector& outputs() const { return outputs_; }
- const std::vector& attributes() const { return attributes_; }
- const std::vector& optional_attributes() const {
- return optional_attributes_;
- }
-
- private:
- // A specification for an operation
- //
- // graph_op_name: name of this op, as known by TensorFlow core engine
- // hidden: true if this op should not be visible through the Graph Ops API
- // deprecation_explanation: message to show if all endpoints are deprecated
- explicit OpSpec(const string& graph_op_name, bool hidden,
- const string& deprecation_explanation)
- : graph_op_name_(graph_op_name),
- hidden_(hidden),
- deprecation_explanation_(deprecation_explanation) {}
-
- const string graph_op_name_;
- const bool hidden_;
- const string deprecation_explanation_;
- std::vector endpoints_;
- std::vector inputs_;
- std::vector outputs_;
- std::vector attributes_;
- std::vector optional_attributes_;
-};
-
-} // namespace java
-} // namespace tensorflow
-
-#endif // TENSORFLOW_JAVA_OP_GENERATOR_OP_SPECS_H_
diff --git a/tensorflow-core/tensorflow-core-api/src/bazel/op_generator/source_writer.cc b/tensorflow-core/tensorflow-core-api/src/bazel/op_generator/source_writer.cc
deleted file mode 100644
index 63191c080ac..00000000000
--- a/tensorflow-core/tensorflow-core-api/src/bazel/op_generator/source_writer.cc
+++ /dev/null
@@ -1,363 +0,0 @@
-/* Copyright 2017 The TensorFlow Authors. All Rights Reserved.
-
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-==============================================================================*/
-
-#include
-#include
-#include
-
-#include "source_writer.h"
-
-namespace tensorflow {
-namespace java {
-
-SourceWriter::SourceWriter() {
- // Push an empty generic namespace at start, for simplification.
- generic_namespaces_.push(new GenericNamespace());
-}
-
-SourceWriter::~SourceWriter() {
- // Remove empty generic namespace added at start as well as any other
- // namespace objects that haven't been removed.
- while (!generic_namespaces_.empty()) {
- GenericNamespace* generic_namespace = generic_namespaces_.top();
- generic_namespaces_.pop();
- delete generic_namespace;
- }
-}
-
-SourceWriter& SourceWriter::Indent(int tab) {
- left_margin_.resize(
- std::max(static_cast(left_margin_.size() + tab), 0), ' ');
- return *this;
-}
-
-SourceWriter& SourceWriter::Prefix(const char* line_prefix) {
- line_prefix_ = line_prefix;
- return *this;
-}
-
-SourceWriter& SourceWriter::Write(const StringPiece& str) {
- size_t line_pos = 0;
- do {
- size_t start_pos = line_pos;
- line_pos = str.find('\n', start_pos);
- if (line_pos != string::npos) {
- ++line_pos;
- Append(str.substr(start_pos, line_pos - start_pos));
- newline_ = true;
- } else {
- Append(str.substr(start_pos, str.size() - start_pos));
- }
- } while (line_pos != string::npos && line_pos < str.size());
-
- return *this;
-}
-
-SourceWriter& SourceWriter::WriteFromFile(const string& fname, Env* env) {
- string data_;
- TF_CHECK_OK(ReadFileToString(env, fname, &data_));
- return Write(data_);
-}
-
-SourceWriter& SourceWriter::Append(const StringPiece& str) {
- if (!str.empty()) {
- if (newline_) {
- DoAppend(left_margin_ + line_prefix_);
- newline_ = false;
- }
- DoAppend(str);
- }
- return *this;
-}
-
-SourceWriter& SourceWriter::AppendType(const Type& type) {
- if (type.wildcard()) {
- Append("?");
- } else {
- Append(type.name());
- if (!type.parameters().empty()) {
- Append("<");
- bool first = true;
- for (const Type& t : type.parameters()) {
- if (!first) {
- Append(", ");
- }
- AppendType(t);
- first = false;
- }
- Append(">");
- }
- }
- return *this;
-}
-
-SourceWriter& SourceWriter::EndLine() {
- Append("\n");
- newline_ = true;
- return *this;
-}
-
-SourceWriter& SourceWriter::BeginBlock(const string& expression) {
- if (!expression.empty()) {
- Append(expression + " {");
- } else {
- Append(newline_ ? "{" : " {");
- }
- return EndLine().Indent(2);
-}
-
-SourceWriter& SourceWriter::EndBlock() {
- return Indent(-2).Append("}").EndLine();
-}
-
-SourceWriter& SourceWriter::BeginMethod(const Method& method, int modifiers,
- const Javadoc* javadoc) {
- GenericNamespace* generic_namespace = PushGenericNamespace(modifiers);
- if (!method.constructor()) {
- generic_namespace->Visit(method.return_type());
- }
- for (const Variable& v : method.arguments()) {
- generic_namespace->Visit(v.type());
- }
- EndLine();
- if (javadoc != nullptr) {
- WriteJavadoc(*javadoc);
- }
- if (!method.annotations().empty()) {
- WriteAnnotations(method.annotations());
- }
- WriteModifiers(modifiers);
- if (!generic_namespace->declared_types().empty()) {
- WriteGenerics(generic_namespace->declared_types());
- Append(" ");
- }
- if (!method.constructor()) {
- AppendType(method.return_type()).Append(" ");
- }
- Append(method.name()).Append("(");
- bool first = true;
- for (const Variable& v : method.arguments()) {
- if (!first) {
- Append(", ");
- }
- AppendType(v.type()).Append(v.variadic() ? "... " : " ").Append(v.name());
- first = false;
- }
- return Append(")").BeginBlock();
-}
-
-SourceWriter& SourceWriter::EndMethod() {
- EndBlock();
- PopGenericNamespace();
- return *this;
-}
-
-SourceWriter& SourceWriter::BeginType(const Type& type, int modifiers,
- const std::list* extra_dependencies,
- const Javadoc* javadoc) {
- if (!type.package().empty()) {
- Append("package ").Append(type.package()).Append(";").EndLine();
- }
- TypeImporter type_importer(type.package());
- type_importer.Visit(type);
- if (extra_dependencies != nullptr) {
- for (const Type& t : *extra_dependencies) {
- type_importer.Visit(t);
- }
- }
- if (!type_importer.imports().empty()) {
- EndLine();
- for (const string& s : type_importer.imports()) {
- Append("import ").Append(s).Append(";").EndLine();
- }
- }
- return BeginInnerType(type, modifiers, javadoc);
-}
-
-SourceWriter& SourceWriter::BeginInnerType(const Type& type, int modifiers,
- const Javadoc* javadoc) {
- GenericNamespace* generic_namespace = PushGenericNamespace(modifiers);
- generic_namespace->Visit(type);
- EndLine();
- if (javadoc != nullptr) {
- WriteJavadoc(*javadoc);
- }
- if (!type.annotations().empty()) {
- WriteAnnotations(type.annotations());
- }
- WriteModifiers(modifiers);
- CHECK_EQ(Type::Kind::CLASS, type.kind()) << ": Not supported yet";
- Append("class ").Append(type.name());
- if (!generic_namespace->declared_types().empty()) {
- WriteGenerics(generic_namespace->declared_types());
- }
- if (!type.supertypes().empty()) {
- bool first_interface = true;
- for (const Type& t : type.supertypes()) {
- if (t.kind() == Type::CLASS) { // superclass is always first in list
- Append(" extends ");
- } else if (first_interface) {
- Append(" implements ");
- first_interface = false;
- } else {
- Append(", ");
- }
- AppendType(t);
- }
- }
- return BeginBlock();
-}
-
-SourceWriter& SourceWriter::EndType() {
- EndBlock();
- PopGenericNamespace();
- return *this;
-}
-
-SourceWriter& SourceWriter::WriteField(const Variable& field, int modifiers,
- const Javadoc* javadoc) {
- // If present, write field javadoc only as one brief line
- if (javadoc != nullptr && !javadoc->brief().empty()) {
- Append("/** ").Append(javadoc->brief()).Append(" */").EndLine();
- }
- WriteModifiers(modifiers);
- AppendType(field.type()).Append(" ").Append(field.name()).Append(";");
- EndLine();
- return *this;
-}
-
-SourceWriter& SourceWriter::WriteModifiers(int modifiers) {
- if (modifiers & PUBLIC) {
- Append("public ");
- } else if (modifiers & PROTECTED) {
- Append("protected ");
- } else if (modifiers & PRIVATE) {
- Append("private ");
- }
- if (modifiers & STATIC) {
- Append("static ");
- }
- if (modifiers & FINAL) {
- Append("final ");
- }
- return *this;
-}
-
-SourceWriter& SourceWriter::WriteJavadoc(const Javadoc& javadoc) {
- Append("/**").Prefix(" * ").EndLine();
- bool do_line_break = false;
- if (!javadoc.brief().empty()) {
- Write(javadoc.brief()).EndLine();
- do_line_break = true;
- }
- if (!javadoc.details().empty()) {
- if (do_line_break) {
- Append("").EndLine();
- }
- Write(javadoc.details()).EndLine();
- do_line_break = true;
- }
- if (!javadoc.tags().empty()) {
- if (do_line_break) {
- EndLine();
- }
- for (const auto& p : javadoc.tags()) {
- Append("@" + p.first);
- if (!p.second.empty()) {
- Append(" ").Write(p.second);
- }
- EndLine();
- }
- }
- return Prefix("").Append(" */").EndLine();
-}
-
-SourceWriter& SourceWriter::WriteAnnotations(
- const std::list& annotations) {
- for (const Annotation& a : annotations) {
- Append("@" + a.name());
- if (!a.attributes().empty()) {
- Append("(").Append(a.attributes()).Append(")");
- }
- EndLine();
- }
- return *this;
-}
-
-SourceWriter& SourceWriter::WriteGenerics(
- const std::list& generics) {
- Append("<");
- bool first = true;
- for (const Type* pt : generics) {
- if (!first) {
- Append(", ");
- }
- Append(pt->name());
- if (!pt->supertypes().empty()) {
- Append(" extends ").AppendType(pt->supertypes().front());
- }
- first = false;
- }
- return Append(">");
-}
-
-SourceWriter::GenericNamespace* SourceWriter::PushGenericNamespace(
- int modifiers) {
- GenericNamespace* generic_namespace;
- if (modifiers & STATIC) {
- generic_namespace = new GenericNamespace();
- } else {
- generic_namespace = new GenericNamespace(generic_namespaces_.top());
- }
- generic_namespaces_.push(generic_namespace);
- return generic_namespace;
-}
-
-void SourceWriter::PopGenericNamespace() {
- GenericNamespace* generic_namespace = generic_namespaces_.top();
- generic_namespaces_.pop();
- delete generic_namespace;
-}
-
-void SourceWriter::TypeVisitor::Visit(const Type& type) {
- DoVisit(type);
- for (const Type& t : type.parameters()) {
- Visit(t);
- }
- for (const Annotation& t : type.annotations()) {
- DoVisit(t);
- }
- for (const Type& t : type.supertypes()) {
- Visit(t);
- }
-}
-
-void SourceWriter::GenericNamespace::DoVisit(const Type& type) {
- // ignore non-generic parameters, wildcards and generics already declared
- if (type.kind() == Type::GENERIC && !type.wildcard() &&
- generic_names_.find(type.name()) == generic_names_.end()) {
- declared_types_.push_back(&type);
- generic_names_.insert(type.name());
- }
-}
-
-void SourceWriter::TypeImporter::DoVisit(const Type& type) {
- if (!type.package().empty() && type.package() != current_package_) {
- imports_.insert(type.canonical_name());
- }
-}
-
-} // namespace java
-} // namespace tensorflow
diff --git a/tensorflow-core/tensorflow-core-api/src/bazel/op_generator/source_writer.h b/tensorflow-core/tensorflow-core-api/src/bazel/op_generator/source_writer.h
deleted file mode 100644
index 73f487bb46c..00000000000
--- a/tensorflow-core/tensorflow-core-api/src/bazel/op_generator/source_writer.h
+++ /dev/null
@@ -1,259 +0,0 @@
-/* Copyright 2017 The TensorFlow Authors. All Rights Reserved.
-
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-==============================================================================*/
-
-#ifndef TENSORFLOW_JAVA_OP_GENERATOR_SOURCE_WRITER_H_
-#define TENSORFLOW_JAVA_OP_GENERATOR_SOURCE_WRITER_H_
-
-#include
-#include
-#include
-#include
-
-#include "tensorflow/core/lib/core/stringpiece.h"
-#include "tensorflow/core/platform/env.h"
-
-#include "java_defs.h"
-
-namespace tensorflow {
-namespace java {
-
-// A class for writing Java source code.
-class SourceWriter {
- public:
- SourceWriter();
-
- virtual ~SourceWriter();
-
- // Indents following lines with white spaces.
- //
- // Indentation is cumulative, i.e. the provided tabulation is added to the
- // current indentation value. If the tabulation is negative, the operation
- // will outdent the source code, until the indentation reaches 0 again.
- //
- // For example, calling Indent(2) twice will indent code with 4 white
- // spaces. Then calling Indent(-2) will outdent the code back to 2 white
- // spaces.
- SourceWriter& Indent(int tab);
-
- // Prefixes following lines with provided character(s).
- //
- // A common use case of a prefix is for commenting or documenting the code.
- //
- // The prefix is written after the indentation, For example, invoking
- // Indent(2)->Prefix("//") will result in prefixing lines with " //".
- //
- // An empty value ("") will remove any line prefix that was previously set.
- SourceWriter& Prefix(const char* line_prefix);
-
- // Writes a source code snippet.
- //
- // The data might potentially contain newline characters, therefore it will
- // be scanned to ensure that each line is indented and prefixed properly,
- // making it a bit slower than Append().
- SourceWriter& Write(const StringPiece& str);
-
- // Writes a source code snippet read from a file.
- //
- // All lines of the file at the provided path will be read and written back
- // to the output of this writer in regard of its current attributes (e.g.
- // the indentation, prefix, etc.)
- SourceWriter& WriteFromFile(const string& fname, Env* env = Env::Default());
-
- // Appends a piece of source code.
- //
- // It is expected that no newline character is present in the data provided,
- // otherwise Write() must be used.
- SourceWriter& Append(const StringPiece& str);
-
- // Appends a type to the current line.
- //
- // The type is written in its simple form (i.e. not prefixed by its package)
- // and followed by any parameter types it has enclosed in brackets (<>).
- SourceWriter& AppendType(const Type& type);
-
- // Appends a newline character.
- //
- // Data written after calling this method will start on a new line, in respect
- // of the current indentation.
- SourceWriter& EndLine();
-
- // Begins a block of source code.
- //
- // This method appends a new opening brace to the current data and indent the
- // next lines according to Google Java Style Guide. The block can optionally
- // be preceded by an expression (e.g. Append("if(true)").BeginBlock();)
- SourceWriter& BeginBlock(const string& expression = "");
-
- // Ends the current block of source code.
- //
- // This method appends a new closing brace to the current data and outdent the
- // next lines back to the margin used before BeginBlock() was invoked.
- SourceWriter& EndBlock();
-
- // Begins to write a method.
- //
- // This method outputs the signature of the Java method from the data passed
- // in the 'method' parameter and starts a new block. Modifiers are also passed
- // in parameter to define the access scope of this method and, optionally,
- // a Javadoc.
- SourceWriter& BeginMethod(const Method& method, int modifiers,
- const Javadoc* javadoc = nullptr);
-
- // Ends the current method.
- //
- // This method ends the block of code that has begun when invoking
- // BeginMethod() prior to this.
- SourceWriter& EndMethod();
-
- // Begins to write the main type of a source file.
- //
- // This method outputs the declaration of the Java type from the data passed
- // in the 'type' parameter and starts a new block. Modifiers are also passed
- // in parameter to define the access scope of this type and, optionally,
- // a Javadoc.
- //
- // If not null, all types found in the 'extra_dependencies' list will be
- // imported before declaring the new type.
- SourceWriter& BeginType(const Type& type, int modifiers,
- const std::list* extra_dependencies = nullptr,
- const Javadoc* javadoc = nullptr);
-
- // Begins to write a new inner type.
- //
- // This method outputs the declaration of the Java type from the data passed
- // in the 'type' parameter and starts a new block. Modifiers are also passed
- // in parameter to define the accesses and the scope of this type and,
- // optionally, a Javadoc.
- SourceWriter& BeginInnerType(const Type& type, int modifiers,
- const Javadoc* javadoc = nullptr);
-
- // Ends the current type.
- //
- // This method ends the block of code that has begun when invoking
- // BeginType() or BeginInnerType() prior to this.
- SourceWriter& EndType();
-
- // Writes a variable as fields of a type.
- //
- // This method must be called within the definition of a type (see BeginType()
- // or BeginInnerType()). Modifiers are also be passed in parameter to define
- // the accesses and the scope of this field and, optionally, a Javadoc.
- SourceWriter& WriteField(const Variable& field, int modifiers,
- const Javadoc* javadoc = nullptr);
-
- protected:
- virtual void DoAppend(const StringPiece& str) = 0;
-
- private:
- // A utility base class for visiting elements of a type.
- class TypeVisitor {
- public:
- virtual ~TypeVisitor() = default;
- void Visit(const Type& type);
-
- protected:
- virtual void DoVisit(const Type& type) = 0;
- };
-
- // A utility class for keeping track of declared generics in a given scope.
- class GenericNamespace : public TypeVisitor {
- public:
- GenericNamespace() = default;
- explicit GenericNamespace(const GenericNamespace* parent)
- : generic_names_(parent->generic_names_) {}
- std::list declared_types() {
- return declared_types_;
- }
- protected:
- virtual void DoVisit(const Type& type);
-
- private:
- std::list declared_types_;
- std::set generic_names_;
- };
-
- // A utility class for collecting a list of import statements to declare.
- class TypeImporter : public TypeVisitor {
- public:
- explicit TypeImporter(const string& current_package)
- : current_package_(current_package) {}
- virtual ~TypeImporter() = default;
- const std::set imports() {
- return imports_;
- }
- protected:
- virtual void DoVisit(const Type& type);
-
- private:
- string current_package_;
- std::set imports_;
- };
-
- string left_margin_;
- string line_prefix_;
- bool newline_ = true;
- std::stack generic_namespaces_;
-
- SourceWriter& WriteModifiers(int modifiers);
- SourceWriter& WriteJavadoc(const Javadoc& javadoc);
- SourceWriter& WriteAnnotations(const std::list& annotations);
- SourceWriter& WriteGenerics(const std::list& generics);
- GenericNamespace* PushGenericNamespace(int modifiers);
- void PopGenericNamespace();
-};
-
-// A writer that outputs source code into a file.
-//
-// Note: the writer does not acquire the ownership of the file being passed in
-// parameter.
-class SourceFileWriter : public SourceWriter {
- public:
- explicit SourceFileWriter(WritableFile* file) : file_(file) {}
- virtual ~SourceFileWriter() = default;
-
- protected:
- void DoAppend(const StringPiece& str) override {
- TF_CHECK_OK(file_->Append(str));
- }
-
- private:
- WritableFile* file_;
-};
-
-// A writer that outputs source code into a string buffer.
-class SourceBufferWriter : public SourceWriter {
- public:
- SourceBufferWriter() : owns_buffer_(true), buffer_(new string()) {}
- explicit SourceBufferWriter(string* buffer)
- : owns_buffer_(false), buffer_(buffer) {}
- virtual ~SourceBufferWriter() {
- if (owns_buffer_) delete buffer_;
- }
- const string& str() { return *buffer_; }
-
- protected:
- void DoAppend(const StringPiece& str) override {
- buffer_->append(str.begin(), str.end());
- }
-
- private:
- bool owns_buffer_;
- string* buffer_;
-};
-
-} // namespace java
-} // namespace tensorflow
-
-#endif // TENSORFLOW_JAVA_OP_GENERATOR_SOURCE_WRITER_H_
diff --git a/tensorflow-core/tensorflow-core-api/src/gen/annotations/org/tensorflow/op/AudioOps.java b/tensorflow-core/tensorflow-core-api/src/gen/annotations/org/tensorflow/op/AudioOps.java
index 16770394378..d6bcfc10c45 100644
--- a/tensorflow-core/tensorflow-core-api/src/gen/annotations/org/tensorflow/op/AudioOps.java
+++ b/tensorflow-core/tensorflow-core-api/src/gen/annotations/org/tensorflow/op/AudioOps.java
@@ -1,4 +1,4 @@
-// Copyright 2020 The TensorFlow Authors. All Rights Reserved.
+// Copyright 2020-2022 The TensorFlow Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -29,41 +29,39 @@
/**
* An API for building {@code audio} operations as {@link Op Op}s
*
- * @see {@link Ops}
+ * @see Ops
*/
public final class AudioOps {
private final Scope scope;
- AudioOps(Scope scope) {
- this.scope = scope;
+ private final Ops ops;
+
+ AudioOps(Ops ops) {
+ this.scope = ops.scope();
+ this.ops = ops;
}
/**
* Produces a visualization of audio data over time.
- *
* Spectrograms are a standard way of representing audio information as a series of
* slices of frequency information, one slice for each window of time. By joining
* these together into a sequence, they form a distinctive fingerprint of the sound
* over time.
- *
- * This op expects to receive audio data as an input, stored as floats in the range
+ *
This op expects to receive audio data as an input, stored as floats in the range
* -1 to 1, together with a window width in samples, and a stride specifying how
* far to move the window between slices. From this it generates a three
* dimensional output. The first dimension is for the channels in the input, so a
* stereo audio input would have two here for example. The second dimension is time,
* with successive frequency slices. The third dimension has an amplitude value for
* each frequency during that time slice.
- *
- * This means the layout when converted and saved as an image is rotated 90 degrees
+ *
This means the layout when converted and saved as an image is rotated 90 degrees
* clockwise from a typical spectrogram. Time is descending down the Y axis, and
* the frequency decreases from left to right.
- *
- * Each value in the result represents the square root of the sum of the real and
+ *
Each value in the result represents the square root of the sum of the real and
* imaginary parts of an FFT on the current window of samples. In this way, the
* lowest dimension represents the power of each frequency in the current window,
* and adjacent windows are concatenated in the next dimension.
- *
- * To get a more intuitive and visual look at what this operation does, you can run
+ *
To get a more intuitive and visual look at what this operation does, you can run
* tensorflow/examples/wav_to_spectrogram to read in an audio file and save out the
* resulting spectrogram as a PNG image.
*
@@ -71,7 +69,7 @@ public final class AudioOps {
* @param windowSize How wide the input window is in samples. For the highest efficiency
* this should be a power of two, but other values are accepted.
* @param stride How widely apart the center of adjacent sample windows should be.
- * @param options carries optional attributes values
+ * @param options carries optional attribute values
* @return a new instance of AudioSpectrogram
*/
public AudioSpectrogram audioSpectrogram(Operand input, Long windowSize, Long stride,
@@ -81,24 +79,20 @@ public AudioSpectrogram audioSpectrogram(Operand input, Long windowSiz
/**
* Decode a 16-bit PCM WAV file to a float tensor.
- *
* The -32768 to 32767 signed 16-bit values will be scaled to -1.0 to 1.0 in float.
- *
- * When desired_channels is set, if the input contains fewer channels than this
+ *
When desired_channels is set, if the input contains fewer channels than this
* then the last channel will be duplicated to give the requested number, else if
* the input has more channels than requested then the additional channels will be
* ignored.
- *
- * If desired_samples is set, then the audio will be cropped or padded with zeroes
+ *
If desired_samples is set, then the audio will be cropped or padded with zeroes
* to the requested length.
- *
- * The first output contains a Tensor with the content of the audio samples. The
+ *
The first output contains a Tensor with the content of the audio samples. The
* lowest dimension will be the number of channels, and the second will be the
* number of samples. For example, a ten-sample-long stereo WAV file should give an
* output shape of [10, 2].
*
* @param contents The WAV-encoded audio, usually from a file.
- * @param options carries optional attributes values
+ * @param options carries optional attribute values
* @return a new instance of DecodeWav
*/
public DecodeWav decodeWav(Operand contents, DecodeWav.Options... options) {
@@ -107,16 +101,14 @@ public DecodeWav decodeWav(Operand contents, DecodeWav.Options... optio
/**
* Encode audio data using the WAV file format.
- *
* This operation will generate a string suitable to be saved out to create a .wav
* audio file. It will be encoded in the 16-bit PCM format. It takes in float
* values in the range -1.0f to 1.0f, and any outside that value will be clamped to
* that range.
- *
- * `audio` is a 2-D float Tensor of shape `[length, channels]`.
- * `sample_rate` is a scalar Tensor holding the rate to use (e.g. 44100).
+ *
{@code audio} is a 2-D float Tensor of shape {@code [length, channels]}.
+ * {@code sample_rate} is a scalar Tensor holding the rate to use (e.g. 44100).
*
- * @param audio 2-D with shape `[length, channels]`.
+ * @param audio 2-D with shape {@code [length, channels]}.
* @param sampleRate Scalar containing the sample frequency.
* @return a new instance of EncodeWav
*/
@@ -126,7 +118,6 @@ public EncodeWav encodeWav(Operand audio, Operand sampleRate)
/**
* Transforms a spectrogram into a form that's useful for speech recognition.
- *
* Mel Frequency Cepstral Coefficients are a way of representing audio data that's
* been effective as an input feature for machine learning. They are created by
* taking the spectrum of a spectrogram (a 'cepstrum'), and discarding some of the
@@ -137,11 +128,18 @@ public EncodeWav encodeWav(Operand audio, Operand sampleRate)
* @param spectrogram Typically produced by the Spectrogram op, with magnitude_squared
* set to true.
* @param sampleRate How many samples per second the source audio used.
- * @param options carries optional attributes values
+ * @param options carries optional attribute values
* @return a new instance of Mfcc
*/
public Mfcc mfcc(Operand spectrogram, Operand sampleRate,
Mfcc.Options... options) {
return Mfcc.create(scope, spectrogram, sampleRate, options);
}
+
+ /**
+ * Get the parent {@link Ops} object.
+ */
+ public final Ops ops() {
+ return ops;
+ }
}
diff --git a/tensorflow-core/tensorflow-core-api/src/gen/annotations/org/tensorflow/op/BitwiseOps.java b/tensorflow-core/tensorflow-core-api/src/gen/annotations/org/tensorflow/op/BitwiseOps.java
index 8ac6d565e51..5cf8e620d72 100644
--- a/tensorflow-core/tensorflow-core-api/src/gen/annotations/org/tensorflow/op/BitwiseOps.java
+++ b/tensorflow-core/tensorflow-core-api/src/gen/annotations/org/tensorflow/op/BitwiseOps.java
@@ -1,4 +1,4 @@
-// Copyright 2020 The TensorFlow Authors. All Rights Reserved.
+// Copyright 2020-2022 The TensorFlow Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -29,23 +29,24 @@
/**
* An API for building {@code bitwise} operations as {@link Op Op}s
*
- * @see {@link Ops}
+ * @see Ops
*/
public final class BitwiseOps {
private final Scope scope;
- BitwiseOps(Scope scope) {
- this.scope = scope;
+ private final Ops ops;
+
+ BitwiseOps(Ops ops) {
+ this.scope = ops.scope();
+ this.ops = ops;
}
/**
- * Elementwise computes the bitwise AND of `x` and `y`.
- *
- * The result will have those bits set, that are set in both `x` and `y`. The
- * computation is performed on the underlying representations of `x` and `y`.
- *
- * For example:
- *
{@code
+ * Elementwise computes the bitwise AND of {@code x} and {@code y}.
+ * The result will have those bits set, that are set in both {@code x} and {@code y}. The
+ * computation is performed on the underlying representations of {@code x} and {@code y}.
+ * For example:
+ *
* import tensorflow as tf
* from tensorflow.python.ops import bitwise_ops
* dtype_list = [tf.int8, tf.int16, tf.int32, tf.int64,
@@ -58,11 +59,11 @@ public final class BitwiseOps {
*
* res = bitwise_ops.bitwise_and(lhs, rhs)
* tf.assert_equal(tf.cast(res, tf.float32), exp) # TRUE
- * }
+ *
*
- * @param data type for {@code z()} output
- * @param x
- * @param y
+ * @param x The x value
+ * @param y The y value
+ * @param data type for {@code BitwiseAnd} output and operands
* @return a new instance of BitwiseAnd
*/
public BitwiseAnd bitwiseAnd(Operand x, Operand y) {
@@ -70,13 +71,11 @@ public BitwiseAnd bitwiseAnd(Operand x, Operand y)
}
/**
- * Elementwise computes the bitwise OR of `x` and `y`.
- *
- * The result will have those bits set, that are set in `x`, `y` or both. The
- * computation is performed on the underlying representations of `x` and `y`.
- *
- * For example:
- *
{@code
+ * Elementwise computes the bitwise OR of {@code x} and {@code y}.
+ * The result will have those bits set, that are set in {@code x}, {@code y} or both. The
+ * computation is performed on the underlying representations of {@code x} and {@code y}.
+ * For example:
+ *
* import tensorflow as tf
* from tensorflow.python.ops import bitwise_ops
* dtype_list = [tf.int8, tf.int16, tf.int32, tf.int64,
@@ -89,11 +88,11 @@ public BitwiseAnd bitwiseAnd(Operand x, Operand y)
*
* res = bitwise_ops.bitwise_or(lhs, rhs)
* tf.assert_equal(tf.cast(res, tf.float32), exp) # TRUE
- * }
+ *
*
- * @param data type for {@code z()} output
- * @param x
- * @param y
+ * @param x The x value
+ * @param y The y value
+ * @param data type for {@code BitwiseOr} output and operands
* @return a new instance of BitwiseOr
*/
public BitwiseOr bitwiseOr(Operand x, Operand y) {
@@ -101,13 +100,11 @@ public BitwiseOr bitwiseOr(Operand x, Operand y) {
}
/**
- * Elementwise computes the bitwise XOR of `x` and `y`.
- *
- * The result will have those bits set, that are different in `x` and `y`. The
- * computation is performed on the underlying representations of `x` and `y`.
- *
- * For example:
- *
{@code
+ * Elementwise computes the bitwise XOR of {@code x} and {@code y}.
+ * The result will have those bits set, that are different in {@code x} and {@code y}. The
+ * computation is performed on the underlying representations of {@code x} and {@code y}.
+ * For example:
+ *
* import tensorflow as tf
* from tensorflow.python.ops import bitwise_ops
* dtype_list = [tf.int8, tf.int16, tf.int32, tf.int64,
@@ -120,11 +117,11 @@ public BitwiseOr bitwiseOr(Operand x, Operand y) {
*
* res = bitwise_ops.bitwise_xor(lhs, rhs)
* tf.assert_equal(tf.cast(res, tf.float32), exp) # TRUE
- * }
+ *
*
- * @param data type for {@code z()} output
- * @param x
- * @param y
+ * @param x The x value
+ * @param y The y value
+ * @param data type for {@code BitwiseXor} output and operands
* @return a new instance of BitwiseXor
*/
public BitwiseXor bitwiseXor(Operand x, Operand y) {
@@ -132,13 +129,11 @@ public BitwiseXor bitwiseXor(Operand x, Operand y)
}
/**
- * Invert (flip) each bit of supported types; for example, type `uint8` value 01010101 becomes 10101010.
- *
- * Flip each bit of supported types. For example, type `int8` (decimal 2) binary 00000010 becomes (decimal -3) binary 11111101.
- * This operation is performed on each element of the tensor argument `x`.
- *
- * Example:
- *
{@code
+ * Invert (flip) each bit of supported types; for example, type {@code uint8} value 01010101 becomes 10101010.
+ * Flip each bit of supported types. For example, type {@code int8} (decimal 2) binary 00000010 becomes (decimal -3) binary 11111101.
+ * This operation is performed on each element of the tensor argument {@code x}.
+ * Example:
+ *
* import tensorflow as tf
* from tensorflow.python.ops import bitwise_ops
*
@@ -172,10 +167,10 @@ public BitwiseXor bitwiseXor(Operand x, Operand y)
* inverted = bitwise_ops.invert(input_tensor)
* expected = tf.constant([dtype.max - x for x in inputs], dtype=tf.float32)
* tf.assert_equal(tf.cast(inverted, tf.float32), tf.cast(expected, tf.float32))
- * }
+ *
*
- * @param data type for {@code y()} output
- * @param x
+ * @param x The x value
+ * @param data type for {@code Invert} output and operands
* @return a new instance of Invert
*/
public Invert invert(Operand x) {
@@ -183,13 +178,11 @@ public Invert invert(Operand x) {
}
/**
- * Elementwise computes the bitwise left-shift of `x` and `y`.
- *
- * If `y` is negative, or greater than or equal to the width of `x` in bits the
+ * Elementwise computes the bitwise left-shift of {@code x} and {@code y}.
+ * If {@code y} is negative, or greater than or equal to the width of {@code x} in bits the
* result is implementation defined.
- *
- * Example:
- *
{@code
+ * Example:
+ *
* import tensorflow as tf
* from tensorflow.python.ops import bitwise_ops
* import numpy as np
@@ -212,12 +205,12 @@ public Invert invert(Operand x) {
* lhs = np.array([-2, 64, 101, 32], dtype=np.int8)
* rhs = np.array([-1, -5, -3, -14], dtype=np.int8)
* bitwise_ops.left_shift(lhs, rhs)
- * #
- * }
+ * # <tf.Tensor: shape=(4,), dtype=int8, numpy=array([ -2, 64, 101, 32], dtype=int8)>
+ *
*
- * @param data type for {@code z()} output
- * @param x
- * @param y
+ * @param x The x value
+ * @param y The y value
+ * @param data type for {@code LeftShift} output and operands
* @return a new instance of LeftShift
*/
public LeftShift leftShift(Operand x, Operand y) {
@@ -225,16 +218,13 @@ public LeftShift leftShift(Operand x, Operand y) {
}
/**
- * Elementwise computes the bitwise right-shift of `x` and `y`.
- *
+ * Elementwise computes the bitwise right-shift of {@code x} and {@code y}.
* Performs a logical shift for unsigned integer types, and an arithmetic shift
* for signed integer types.
- *
- * If `y` is negative, or greater than or equal to than the width of `x` in bits
+ *
If {@code y} is negative, or greater than or equal to than the width of {@code x} in bits
* the result is implementation defined.
- *
- * Example:
- *
{@code
+ * Example:
+ *
* import tensorflow as tf
* from tensorflow.python.ops import bitwise_ops
* import numpy as np
@@ -257,15 +247,22 @@ public LeftShift leftShift(Operand x, Operand y) {
* lhs = np.array([-2, 64, 101, 32], dtype=np.int8)
* rhs = np.array([-1, -5, -3, -14], dtype=np.int8)
* bitwise_ops.right_shift(lhs, rhs)
- * #
- * }
+ * # <tf.Tensor: shape=(4,), dtype=int8, numpy=array([ -2, 64, 101, 32], dtype=int8)>
+ *
*
- * @param data type for {@code z()} output
- * @param x
- * @param y
+ * @param x The x value
+ * @param y The y value
+ * @param data type for {@code RightShift} output and operands
* @return a new instance of RightShift
*/
public RightShift rightShift(Operand x, Operand y) {
return RightShift.create(scope, x, y);
}
+
+ /**
+ * Get the parent {@link Ops} object.
+ */
+ public final Ops ops() {
+ return ops;
+ }
}
diff --git a/tensorflow-core/tensorflow-core-api/src/gen/annotations/org/tensorflow/op/ClusterOps.java b/tensorflow-core/tensorflow-core-api/src/gen/annotations/org/tensorflow/op/ClusterOps.java
new file mode 100644
index 00000000000..e59e86f23ed
--- /dev/null
+++ b/tensorflow-core/tensorflow-core-api/src/gen/annotations/org/tensorflow/op/ClusterOps.java
@@ -0,0 +1,85 @@
+// Copyright 2020-2022 The TensorFlow Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+// ==============================================================================
+//
+// This class has been generated, DO NOT EDIT!
+//
+package org.tensorflow.op;
+
+import org.tensorflow.Operand;
+import org.tensorflow.op.cluster.KMC2ChainInitialization;
+import org.tensorflow.op.cluster.KmeansPlusPlusInitialization;
+import org.tensorflow.types.TFloat32;
+import org.tensorflow.types.TInt64;
+
+/**
+ * An API for building {@code cluster} operations as {@link Op Op}s
+ *
+ * @see Ops
+ */
+public final class ClusterOps {
+ private final Scope scope;
+
+ private final Ops ops;
+
+ ClusterOps(Ops ops) {
+ this.scope = ops.scope();
+ this.ops = ops;
+ }
+
+ /**
+ * Returns the index of a data point that should be added to the seed set.
+ * Entries in distances are assumed to be squared distances of candidate points to
+ * the already sampled centers in the seed set. The op constructs one Markov chain
+ * of the k-MC^2 algorithm and returns the index of one candidate point to be added
+ * as an additional cluster center.
+ *
+ * @param distances Vector with squared distances to the closest previously sampled cluster center
+ * for each candidate point.
+ * @param seed Scalar. Seed for initializing the random number generator.
+ * @return a new instance of KMC2ChainInitialization
+ */
+ public KMC2ChainInitialization kMC2ChainInitialization(Operand distances,
+ Operand seed) {
+ return KMC2ChainInitialization.create(scope, distances, seed);
+ }
+
+ /**
+ * Selects num_to_sample rows of input using the KMeans++ criterion.
+ * Rows of points are assumed to be input points. One row is selected at random.
+ * Subsequent rows are sampled with probability proportional to the squared L2
+ * distance from the nearest row selected thus far till num_to_sample rows have
+ * been sampled.
+ *
+ * @param points Matrix of shape (n, d). Rows are assumed to be input points.
+ * @param numToSample Scalar. The number of rows to sample. This value must not be larger than n.
+ * @param seed Scalar. Seed for initializing the random number generator.
+ * @param numRetriesPerSample Scalar. For each row that is sampled, this parameter
+ * specifies the number of additional points to draw from the current
+ * distribution before selecting the best. If a negative value is specified, a
+ * heuristic is used to sample O(log(num_to_sample)) additional points.
+ * @return a new instance of KmeansPlusPlusInitialization
+ */
+ public KmeansPlusPlusInitialization kmeansPlusPlusInitialization(Operand points,
+ Operand numToSample, Operand seed, Operand numRetriesPerSample) {
+ return KmeansPlusPlusInitialization.create(scope, points, numToSample, seed, numRetriesPerSample);
+ }
+
+ /**
+ * Get the parent {@link Ops} object.
+ */
+ public final Ops ops() {
+ return ops;
+ }
+}
diff --git a/tensorflow-core/tensorflow-core-api/src/gen/annotations/org/tensorflow/op/CollectiveOps.java b/tensorflow-core/tensorflow-core-api/src/gen/annotations/org/tensorflow/op/CollectiveOps.java
new file mode 100644
index 00000000000..de786dc95fe
--- /dev/null
+++ b/tensorflow-core/tensorflow-core-api/src/gen/annotations/org/tensorflow/op/CollectiveOps.java
@@ -0,0 +1,214 @@
+// Copyright 2020-2022 The TensorFlow Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+// ==============================================================================
+//
+// This class has been generated, DO NOT EDIT!
+//
+package org.tensorflow.op;
+
+import org.tensorflow.Operand;
+import org.tensorflow.op.collective.CollectiveAllToAll;
+import org.tensorflow.op.collective.CollectiveAssignGroup;
+import org.tensorflow.op.collective.CollectiveBcastRecv;
+import org.tensorflow.op.collective.CollectiveBcastSend;
+import org.tensorflow.op.collective.CollectiveGather;
+import org.tensorflow.op.collective.CollectiveInitializeCommunicator;
+import org.tensorflow.op.collective.CollectivePermute;
+import org.tensorflow.op.collective.CollectiveReduce;
+import org.tensorflow.op.collective.CollectiveReduceScatter;
+import org.tensorflow.types.TInt32;
+import org.tensorflow.types.family.TNumber;
+import org.tensorflow.types.family.TType;
+
+/**
+ * An API for building {@code collective} operations as {@link Op Op}s
+ *
+ * @see Ops
+ */
+public final class CollectiveOps {
+ private final Scope scope;
+
+ private final Ops ops;
+
+ CollectiveOps(Ops ops) {
+ this.scope = ops.scope();
+ this.ops = ops;
+ }
+
+ /**
+ * Mutually exchanges multiple tensors of identical type and shape.
+ *
+ * @param input The input value
+ * @param communicator The communicator value
+ * @param groupAssignment The groupAssignment value
+ * @param options carries optional attribute values
+ * @param data type for {@code CollectiveAllToAllV3} output and operands
+ * @return a new instance of CollectiveAllToAll
+ */
+ public CollectiveAllToAll collectiveAllToAll(Operand input,
+ Operand extends TType> communicator, Operand groupAssignment,
+ CollectiveAllToAll.Options... options) {
+ return CollectiveAllToAll.create(scope, input, communicator, groupAssignment, options);
+ }
+
+ /**
+ * Assign group keys based on group assignment.
+ *
+ * @param groupAssignment The groupAssignment value
+ * @param deviceIndex The deviceIndex value
+ * @param baseKey The baseKey value
+ * @return a new instance of CollectiveAssignGroup
+ */
+ public CollectiveAssignGroup collectiveAssignGroup(Operand groupAssignment,
+ Operand deviceIndex, Operand baseKey) {
+ return CollectiveAssignGroup.create(scope, groupAssignment, deviceIndex, baseKey);
+ }
+
+ /**
+ * Receives a tensor value broadcast from another device.
+ *
+ * @param groupSize The groupSize value
+ * @param groupKey The groupKey value
+ * @param instanceKey The instanceKey value
+ * @param shape The shape value
+ * @param T The value of the T attribute
+ * @param options carries optional attribute values
+ * @param data type for {@code CollectiveBcastRecvV2} output and operands
+ * @return a new instance of CollectiveBcastRecv
+ */
+ public CollectiveBcastRecv collectiveBcastRecv(Operand groupSize,
+ Operand groupKey, Operand instanceKey, Operand extends TNumber> shape,
+ Class T, CollectiveBcastRecv.Options... options) {
+ return CollectiveBcastRecv.create(scope, groupSize, groupKey, instanceKey, shape, T, options);
+ }
+
+ /**
+ * Broadcasts a tensor value to one or more other devices.
+ *
+ * @param input The input value
+ * @param groupSize The groupSize value
+ * @param groupKey The groupKey value
+ * @param instanceKey The instanceKey value
+ * @param options carries optional attribute values
+ * @param data type for {@code CollectiveBcastSendV2} output and operands
+ * @return a new instance of CollectiveBcastSend
+ */
+ public CollectiveBcastSend collectiveBcastSend(Operand input,
+ Operand groupSize, Operand groupKey, Operand instanceKey,
+ CollectiveBcastSend.Options... options) {
+ return CollectiveBcastSend.create(scope, input, groupSize, groupKey, instanceKey, options);
+ }
+
+ /**
+ * Mutually accumulates multiple tensors of identical type and shape.
+ * {@code is_stateless} means each op does not need control dependencies to other
+ * collective ops. In this case, keys that are unique at runtime
+ * (e.g. {@code instance_key}) should be used to distinguish collective groups.
+ *
+ * @param input The input value
+ * @param groupSize The groupSize value
+ * @param groupKey The groupKey value
+ * @param instanceKey The instanceKey value
+ * @param orderingToken The orderingToken value
+ * @param options carries optional attribute values
+ * @param data type for {@code CollectiveGatherV2} output and operands
+ * @return a new instance of CollectiveGather
+ */
+ public CollectiveGather collectiveGather(Operand input,
+ Operand groupSize, Operand groupKey, Operand instanceKey,
+ Iterable> orderingToken, CollectiveGather.Options... options) {
+ return CollectiveGather.create(scope, input, groupSize, groupKey, instanceKey, orderingToken, options);
+ }
+
+ /**
+ * Initializes a group for collective operations.
+ *
+ * @param groupKey The groupKey value
+ * @param rank The rank value
+ * @param groupSize The groupSize value
+ * @param options carries optional attribute values
+ * @return a new instance of CollectiveInitializeCommunicator
+ */
+ public CollectiveInitializeCommunicator collectiveInitializeCommunicator(Operand groupKey,
+ Operand rank, Operand groupSize,
+ CollectiveInitializeCommunicator.Options... options) {
+ return CollectiveInitializeCommunicator.create(scope, groupKey, rank, groupSize, options);
+ }
+
+ /**
+ * An Op to permute tensors across replicated TPU instances.
+ * Each instance supplies its own input.
+ * For example, suppose there are 4 TPU instances: {@code [A, B, C, D]}. Passing
+ * source_target_pairs={@code [[0,1],[1,2],[2,3],[3,0]]} gets the outputs:
+ * {@code [D, A, B, C]}.
+ *
+ * @param input The local input to be permuted. Currently only supports float and
+ * bfloat16.
+ * @param sourceTargetPairs A tensor with shape [num_pairs, 2].
+ * @param data type for {@code CollectivePermute} output and operands
+ * @return a new instance of CollectivePermute
+ */
+ public CollectivePermute collectivePermute(Operand input,
+ Operand sourceTargetPairs) {
+ return CollectivePermute.create(scope, input, sourceTargetPairs);
+ }
+
+ /**
+ * Mutually reduces multiple tensors of identical type and shape.
+ *
+ * @param input The input value
+ * @param communicator The communicator value
+ * @param groupAssignment The groupAssignment value
+ * @param reduction The value of the reduction attribute
+ * @param options carries optional attribute values
+ * @param data type for {@code CollectiveReduceV3} output and operands
+ * @return a new instance of CollectiveReduce
+ */
+ public CollectiveReduce collectiveReduce(Operand input,
+ Operand extends TType> communicator, Operand groupAssignment, String reduction,
+ CollectiveReduce.Options... options) {
+ return CollectiveReduce.create(scope, input, communicator, groupAssignment, reduction, options);
+ }
+
+ /**
+ * Mutually reduces multiple tensors of identical type and shape and scatters the result.
+ * {@code is_stateless} means each op does not need control dependencies to other
+ * collective ops. In this case, keys that are unique at runtime
+ * (e.g. {@code instance_key}) should be used to distinguish collective groups.
+ *
+ * @param input The input value
+ * @param groupSize The groupSize value
+ * @param groupKey The groupKey value
+ * @param instanceKey The instanceKey value
+ * @param orderingToken The orderingToken value
+ * @param mergeOp The value of the mergeOp attribute
+ * @param finalOp The value of the finalOp attribute
+ * @param options carries optional attribute values
+ * @param data type for {@code CollectiveReduceScatterV2} output and operands
+ * @return a new instance of CollectiveReduceScatter
+ */
+ public CollectiveReduceScatter collectiveReduceScatter(Operand input,
+ Operand groupSize, Operand groupKey, Operand instanceKey,
+ Iterable> orderingToken, String mergeOp, String finalOp,
+ CollectiveReduceScatter.Options... options) {
+ return CollectiveReduceScatter.create(scope, input, groupSize, groupKey, instanceKey, orderingToken, mergeOp, finalOp, options);
+ }
+
+ /**
+ * Get the parent {@link Ops} object.
+ */
+ public final Ops ops() {
+ return ops;
+ }
+}
diff --git a/tensorflow-core/tensorflow-core-api/src/gen/annotations/org/tensorflow/op/DataExperimentalOps.java b/tensorflow-core/tensorflow-core-api/src/gen/annotations/org/tensorflow/op/DataExperimentalOps.java
new file mode 100644
index 00000000000..b5b1ee3750f
--- /dev/null
+++ b/tensorflow-core/tensorflow-core-api/src/gen/annotations/org/tensorflow/op/DataExperimentalOps.java
@@ -0,0 +1,737 @@
+// Copyright 2020-2022 The TensorFlow Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+// ==============================================================================
+//
+// This class has been generated, DO NOT EDIT!
+//
+package org.tensorflow.op;
+
+import java.util.List;
+import org.tensorflow.ConcreteFunction;
+import org.tensorflow.Operand;
+import org.tensorflow.ndarray.Shape;
+import org.tensorflow.op.data.experimental.AssertNextDataset;
+import org.tensorflow.op.data.experimental.AutoShardDataset;
+import org.tensorflow.op.data.experimental.BytesProducedStatsDataset;
+import org.tensorflow.op.data.experimental.CSVDataset;
+import org.tensorflow.op.data.experimental.ChooseFastestDataset;
+import org.tensorflow.op.data.experimental.DatasetCardinality;
+import org.tensorflow.op.data.experimental.DatasetToTFRecord;
+import org.tensorflow.op.data.experimental.DenseToSparseBatchDataset;
+import org.tensorflow.op.data.experimental.DirectedInterleaveDataset;
+import org.tensorflow.op.data.experimental.GroupByReducerDataset;
+import org.tensorflow.op.data.experimental.GroupByWindowDataset;
+import org.tensorflow.op.data.experimental.IgnoreErrorsDataset;
+import org.tensorflow.op.data.experimental.IteratorGetDevice;
+import org.tensorflow.op.data.experimental.LatencyStatsDataset;
+import org.tensorflow.op.data.experimental.LmdbDataset;
+import org.tensorflow.op.data.experimental.MapAndBatchDataset;
+import org.tensorflow.op.data.experimental.MapDataset;
+import org.tensorflow.op.data.experimental.MatchingFilesDataset;
+import org.tensorflow.op.data.experimental.MaxIntraOpParallelismDataset;
+import org.tensorflow.op.data.experimental.NonSerializableDataset;
+import org.tensorflow.op.data.experimental.ParallelInterleaveDataset;
+import org.tensorflow.op.data.experimental.ParseExampleDataset;
+import org.tensorflow.op.data.experimental.PrivateThreadPoolDataset;
+import org.tensorflow.op.data.experimental.RandomDataset;
+import org.tensorflow.op.data.experimental.RebatchDataset;
+import org.tensorflow.op.data.experimental.ScanDataset;
+import org.tensorflow.op.data.experimental.SetStatsAggregatorDataset;
+import org.tensorflow.op.data.experimental.SleepDataset;
+import org.tensorflow.op.data.experimental.SlidingWindowDataset;
+import org.tensorflow.op.data.experimental.SqlDataset;
+import org.tensorflow.op.data.experimental.StatsAggregatorHandle;
+import org.tensorflow.op.data.experimental.StatsAggregatorSummary;
+import org.tensorflow.op.data.experimental.TakeWhileDataset;
+import org.tensorflow.op.data.experimental.ThreadPoolDataset;
+import org.tensorflow.op.data.experimental.ThreadPoolHandle;
+import org.tensorflow.op.data.experimental.UnbatchDataset;
+import org.tensorflow.op.data.experimental.UniqueDataset;
+import org.tensorflow.types.TBool;
+import org.tensorflow.types.TInt64;
+import org.tensorflow.types.TString;
+import org.tensorflow.types.family.TType;
+
+/**
+ * An API for building {@code data.experimental} operations as {@link Op Op}s
+ *
+ * @see Ops
+ */
+public final class DataExperimentalOps {
+ private final Scope scope;
+
+ private final Ops ops;
+
+ DataExperimentalOps(Ops ops) {
+ this.scope = ops.scope();
+ this.ops = ops;
+ }
+
+ /**
+ * The ExperimentalAssertNextDataset operation
+ *
+ * @param inputDataset The inputDataset value
+ * @param transformations The transformations value
+ * @param outputTypes The value of the outputTypes attribute
+ * @param outputShapes The value of the outputShapes attribute
+ * @return a new instance of AssertNextDataset
+ */
+ public AssertNextDataset assertNextDataset(Operand extends TType> inputDataset,
+ Operand transformations, List> outputTypes,
+ List outputShapes) {
+ return AssertNextDataset.create(scope, inputDataset, transformations, outputTypes, outputShapes);
+ }
+
+ /**
+ * Creates a dataset that shards the input dataset.
+ * Creates a dataset that shards the input dataset by num_workers, returning a
+ * sharded dataset for the index-th worker. This attempts to automatically shard
+ * a dataset by examining the Dataset graph and inserting a shard op before the
+ * inputs to a reader Dataset (e.g. CSVDataset, TFRecordDataset).
+ * This dataset will throw a NotFound error if we cannot shard the dataset
+ * automatically.
+ *
+ * @param inputDataset A variant tensor representing the input dataset.
+ * @param numWorkers A scalar representing the number of workers to distribute this dataset across.
+ * @param index A scalar representing the index of the current worker out of num_workers.
+ * @param outputTypes The value of the outputTypes attribute
+ * @param outputShapes The value of the outputShapes attribute
+ * @param options carries optional attribute values
+ * @return a new instance of AutoShardDataset
+ */
+ public AutoShardDataset autoShardDataset(Operand extends TType> inputDataset,
+ Operand numWorkers, Operand index, List> outputTypes,
+ List outputShapes, AutoShardDataset.Options... options) {
+ return AutoShardDataset.create(scope, inputDataset, numWorkers, index, outputTypes, outputShapes, options);
+ }
+
+ /**
+ * Records the bytes size of each element of {@code input_dataset} in a StatsAggregator.
+ *
+ * @param inputDataset The inputDataset value
+ * @param tag The tag value
+ * @param outputTypes The value of the outputTypes attribute
+ * @param outputShapes The value of the outputShapes attribute
+ * @return a new instance of BytesProducedStatsDataset
+ */
+ public BytesProducedStatsDataset bytesProducedStatsDataset(Operand extends TType> inputDataset,
+ Operand tag, List> outputTypes, List outputShapes) {
+ return BytesProducedStatsDataset.create(scope, inputDataset, tag, outputTypes, outputShapes);
+ }
+
+ /**
+ * The ExperimentalCSVDataset operation
+ *
+ * @param filenames The filenames value
+ * @param compressionType The compressionType value
+ * @param bufferSize The bufferSize value
+ * @param header The header value
+ * @param fieldDelim The fieldDelim value
+ * @param useQuoteDelim The useQuoteDelim value
+ * @param naValue The naValue value
+ * @param selectCols The selectCols value
+ * @param recordDefaults The recordDefaults value
+ * @param outputShapes The value of the outputShapes attribute
+ * @return a new instance of CSVDataset
+ */
+ public CSVDataset cSVDataset(Operand filenames, Operand