Skip to content
This repository was archived by the owner on Apr 28, 2023. It is now read-only.

Initial version of reverse mode autodiff #227

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions include/tc/core/autodiff.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* Copyright (c) 2017-present, Facebook, Inc.
*
* 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.
*/
#pragma once

#include "tc/lang/tree.h"

#include <ostream>

namespace tc {

std::string differentiate(const std::string& source);

} // namespace tc
2 changes: 2 additions & 0 deletions include/tc/lang/sema.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ static inline TreeRef match_types(TreeRef a, TreeRef b) {
/// - replace TK_APPLY with TK_BUILT_IN for built in functions
/// - checks that all variables are defined, and creates index/reduction
/// variable objects.
// - replaces augumented assignments that have no reduction variables
// with regular assignents
struct Sema {
std::unordered_map<TreeRef, TreeRef> expr_to_type;

Expand Down
9 changes: 7 additions & 2 deletions include/tc/lang/tree_views.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,19 @@ struct ListViewIterator {
bool operator!=(const ListViewIterator& rhs) const {
return it != rhs.it;
}
bool operator==(const ListViewIterator& rhs) const {
return it == rhs.it;
}
T operator*() const {
return T(*it);
}
void operator++() {
ListViewIterator& operator++() {
++it;
return *this;
}
void operator--() {
ListViewIterator& operator--() {
--it;
return *this;
}

private:
Expand Down
1 change: 1 addition & 0 deletions src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ add_library(

SHARED

autodiff.cc
flags.cc
mapping_options.cc
mapping_options_cpp_printer.cc
Expand Down
Loading