├── tensorflow-idris.ipkg ├── .gitignore ├── Midlevel.idr ├── Elabs.idr ├── Ffi.idr ├── UserApi.idr ├── README.md └── LICENSE /tensorflow-idris.ipkg: -------------------------------------------------------------------------------- 1 | package tensorflow-idris 2 | 3 | modules = UserApi,Ffi,Midlevel 4 | 5 | opts = "-p idris-free -p derive -p contrib" 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.ibc 2 | *.o 3 | 4 | # -*- mode: gitignore; -*- 5 | *~ 6 | \#*\# 7 | /.emacs.desktop 8 | /.emacs.desktop.lock 9 | *.elc 10 | auto-save-list 11 | tramp 12 | .\#* -------------------------------------------------------------------------------- /Midlevel.idr: -------------------------------------------------------------------------------- 1 | module Midlevel 2 | import UserApi 3 | import Control.Monad.Freer 4 | 5 | %access public export 6 | 7 | 8 | data TFops : Type where 9 | Placeholder : String->TFops 10 | 11 | str2tfops : String -> TFops 12 | str2tfops x = Placeholder "" 13 | 14 | runFreeGraph : FreeGraph -> IO () 15 | runFreeGraph (Pure x) = pure () 16 | runFreeGraph (Bind _ _) = pure () 17 | 18 | -------------------------------------------------------------------------------- /Elabs.idr: -------------------------------------------------------------------------------- 1 | module Elabs 2 | import Language.Reflection.Elab 3 | import Derive.Show 4 | 5 | %language ElabReflection 6 | -- https://github.com/idris-lang/Idris-dev/blob/master/libs/prelude/Language/Reflection/Elab.idr 7 | 8 | addDecls : Elab () 9 | addDecls = do 10 | -- declareType (Declare (UN "Tpe") [] (RType) ) 11 | -- intro `{{x}} 12 | -- declareType $ Declare `{{FF}} [] RType 13 | declareDatatype $ Declare `{{FF}} [] RType 14 | defineDatatype $ DefineDatatype `{{FF}} [] 15 | -- let xs = map (\x=>declareType (Declare (UN x) [] (RType) )) [""] 16 | pure () 17 | 18 | -- data FF 19 | %runElab addDecls 20 | 21 | xx : FF -> () 22 | xx x = () 23 | 24 | %runElab (deriveShow `{{FF}}) 25 | -- %runElab defineFunction (DefineFun (UN "myf") [MkFunClause (Var `{{x}}) (Var `{{x}}) ]) 26 | -- %runElab `{{}}` 27 | {- 28 | xxx : Tpe -> IO () 29 | xxx _ = do 30 | print "" 31 | -} 32 | 33 | idNat : Nat -> Nat 34 | idNat = %runElab (do intro `{{x}} 35 | fill (Var `{{x}}) 36 | solve) 37 | -------------------------------------------------------------------------------- /Ffi.idr: -------------------------------------------------------------------------------- 1 | module Main 2 | import CFFI 3 | 4 | %lib C "tensorflow" 5 | %include C "tensorflow/c/c_api.h" 6 | -- %include C "/usr/include/tensorflow/c/c_api.h" 7 | -- %link C "testlib.o" 8 | 9 | -- data TF_Tensor 10 | -- IO (Raw TF_Tensor) works,but c warns assignment from incompatible pointer type 11 | -- data TF_Status2:(a:Type)->Type where --safer way 12 | -- TF_Status22:TF_Status2 Ptr 13 | 14 | TF_Status : Type 15 | TF_Status = Ptr -- attention! 16 | 17 | -- Tfs : Raw TF_Status 18 | -- Tfs = MkRaw TF_Status 19 | {- 20 | typedef enum TF_Code { 21 | TF_OK = 0, 22 | TF_CANCELLED = 1, 23 | TF_UNKNOWN = 2, 24 | TF_INVALID_ARGUMENT = 3, 25 | TF_DEADLINE_EXCEEDED = 4, 26 | TF_NOT_FOUND = 5, 27 | TF_ALREADY_EXISTS = 6, 28 | TF_PERMISSION_DENIED = 7, 29 | TF_UNAUTHENTICATED = 16, 30 | TF_RESOURCE_EXHAUSTED = 8, 31 | TF_FAILED_PRECONDITION = 9, 32 | TF_ABORTED = 10, 33 | TF_OUT_OF_RANGE = 11, 34 | TF_UNIMPLEMENTED = 12, 35 | TF_INTERNAL = 13, 36 | TF_UNAVAILABLE = 14, 37 | TF_DATA_LOSS = 15, 38 | } TF_Code; 39 | 40 | 17 fields ! 41 | -} 42 | TF_Code_struct : Composite 43 | TF_Code_struct = STRUCT $ replicate 17 I32 44 | 45 | tfNewStatus : IO TF_Status 46 | tfNewStatus = foreign FFI_C "TF_NewStatus" (IO TF_Status) 47 | 48 | tfGetCode : TF_Status ->IO Int 49 | tfGetCode = foreign FFI_C "TF_Code" (TF_Status ->IO Int) 50 | 51 | tfVersion : IO String 52 | tfVersion = foreign FFI_C "TF_Version" (IO String) 53 | 54 | |||Always returns an empty string if TF_GetCode(s) is TF_OK. 55 | tfMessage : TF_Status -> IO String 56 | tfMessage = foreign FFI_C "TF_Message" (TF_Status -> IO String) 57 | 58 | TF_Buffer : Type 59 | TF_Buffer = Ptr 60 | 61 | TF_Library : Type 62 | TF_Library = Ptr 63 | 64 | ||| Get the OpList of OpDefs defined in the library pointed by lib_handle,like matmul,placeholder,etc 65 | tfGetOpList : TF_Library->IO TF_Buffer 66 | tfGetOpList = foreign FFI_C "TF_GetOpList" (TF_Library->IO TF_Buffer ) 67 | 68 | main : IO () 69 | main = do 70 | ver<-tfVersion 71 | s<-tfNewStatus 72 | msg<-tfMessage s 73 | putStrLn $ "tfMessage is : " ++ msg 74 | putStrLn $ "tfVersion is : " ++ ver 75 | -------------------------------------------------------------------------------- /UserApi.idr: -------------------------------------------------------------------------------- 1 | module UserApi 2 | 3 | import Control.Monad.Freer 4 | import Debug.Trace 5 | import Control.Monad.Id 6 | import Data.Fin 7 | import Control.Monad.State 8 | 9 | %access public export 10 | %default total 11 | ||| currently,some explorations on building computational graphs. 12 | -- non dependent version,for testing only.see below for dependent version 13 | data Tensor : Type where 14 | DoubleT : Double -> Tensor 15 | 16 | implementation Show Tensor where 17 | show (DoubleT x) = show x 18 | 19 | data GraphData : Type -> Type where 20 | Mul : Tensor -> Tensor -> GraphData Tensor 21 | Placeholder : GraphData Tensor 22 | Constant : Double -> GraphData Tensor 23 | 24 | FreeGraph : Type --type of computation graph ,freer graph 25 | FreeGraph = Freer GraphData Tensor 26 | 27 | implicit gt2fg : GraphData Tensor -> FreeGraph 28 | gt2fg = liftF 29 | 30 | --check this at repl! 31 | exampleGraph : FreeGraph 32 | exampleGraph = do 33 | t<-liftF Placeholder 34 | a<-liftF Placeholder 35 | b<-Placeholder -- same,with implicits 36 | liftF (Mul t a) 37 | 38 | --another example 39 | mulG : FreeGraph 40 | mulG = do 41 | x<-liftF $ Constant 1 42 | y<-liftF $ Constant 3 43 | liftF $ Mul x y 44 | 45 | 46 | numericGradId : {x : Type}-> GraphData Tensor->GraphData x -> Id x 47 | numericGradId Placeholder (Mul x y) = pure $ DoubleT 2.0 48 | numericGradId (Constant z) (Mul (DoubleT x) (DoubleT y)) = 49 | let res : Double =(x*y + 0.1)/(z+0.1) in 50 | pure $ trace (show z ++ "," ++show x) $ DoubleT res 51 | numericGradId (Mul x y) (Mul (DoubleT z) (DoubleT w)) = pure $ DoubleT 3.0 52 | numericGradId _ (Constant x) = pure $ DoubleT 3.0 53 | numericGradId _ Placeholder = pure $ DoubleT 4.0 54 | 55 | --try do some gradients,not ok yet 56 | const1 : GraphData Tensor 57 | const1 = Constant 1 58 | 59 | mainGradId : Id String 60 | mainGradId = do 61 | x <- (foldFreer ((trace "xxx" numericGradId) const1) mulG) 62 | --print x 63 | pure $ show x 64 | 65 | 66 | ||| dependent version 67 | data TensorD : List Nat -> Type where 68 | MkTensorD : TensorD xs 69 | 70 | data GraphDataD : Type -> Type where 71 | InD : (s : List Nat) -> GraphDataD $ TensorD s -- graph input,like Placeholder 72 | OutD : (s : List Nat) -> GraphDataD $ TensorD s -- graph output 73 | TrainableD : (s : List Nat) -> GraphDataD $ TensorD s -- variable in tf 74 | MulD : TensorD s -> TensorD s -> GraphDataD $ TensorD s 75 | VecMulD : TensorD [v] -> TensorD [v,_] -> GraphDataD $ TensorD [v] -- vec `mul` matrix ,safely 76 | MapD : TensorD x -> (TensorD x->TensorD x)->GraphDataD $ TensorD x -- for efficiency,pass map to tf c lib 77 | 78 | tensorRank : TensorD x -> Nat 79 | tensorRank {x=s} _ = length s 80 | 81 | tensor1 : TensorD [1,2,3] 82 | tensor1 = MkTensorD 83 | 84 | tensorShape1 : TensorD a -> List Nat 85 | tensorShape1 {a=zz} MkTensorD = zz 86 | 87 | depGraph1 : GraphDataD $ TensorD [1,2,3] 88 | depGraph1 = MulD tensor1 MkTensorD 89 | 90 | FreeGraphD : Type->Type --type of computation graph ,freer graph 91 | FreeGraphD a = Freer GraphDataD a 92 | 93 | implicit liftd : GraphDataD a -> Freer GraphDataD a 94 | liftd = liftF 95 | 96 | depGraph2 : FreeGraphD $ (TensorD [1],TensorD [1]) 97 | depGraph2 = do 98 | in1<-liftF $ InD [1] 99 | out1<-liftF $ InD [1] 100 | out2<-InD [2] -- using implicits 101 | pure (in1,out1) 102 | 103 | compGraphD : FreeGraphD $ TensorD [1] 104 | compGraphD = do 105 | (in1,out1)<-depGraph2 106 | MulD in1 in1 107 | 108 | interp1 : {x : Type}-> GraphDataD x -> State String x 109 | interp1 (InD s) = ST (\x => Id (MkTensorD, x++" in "++ (show s)++" ")) 110 | interp1 (OutD s) = ST (\s => Id (MkTensorD, s++" out ")) 111 | interp1 (TrainableD s) = ST (\s => Id (MkTensorD, s++" train ")) 112 | interp1 (MulD x y) = ST (\s => Id (MkTensorD, s++" mul ")) 113 | interp1 (VecMulD y z) = ST (\s => Id (MkTensorD, s++" vec ")) 114 | interp1 (MapD y f) = ST (\s => Id (MkTensorD, s++" map ")) 115 | -- FreeGraph : Type --type of computation graph ,freer graph 116 | -- FreeGraph = Freer GraphData Tensor 117 | 118 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Join the chat at https://gitter.im/idris-gitter/Lobby](https://badges.gitter.im/idris-gitter/Lobby.svg)](https://gitter.im/idris-gitter/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) 2 | 3 | # differentiable programming on idris,why? (WIP!) 4 | Due to the extreme flexibility of pytorch,I am going to bind to pytorch cpp instead of tensorflow 5 | 6 | Learn & Research dependent types with deep learning 7 | 8 | Elaborator reflection,maybe the most advanced macro system ,will make our great statically typed functional code terse and beautiful 9 | 10 | Utilize existing efforts on optimizations for deep learning,rather than a whole new framework 11 | 12 | syntax,api : 13 | 14 | ```idris 15 | depGraph2 : FreeGraphD $ (TensorD [1],TensorD [2]) 16 | depGraph2 = do 17 | in1<-liftF $ PlaceholderD [1] 18 | out1<-liftF $ PlaceholderD [2] 19 | out2<-PlaceholderD [2] -- using implicits 20 | pure (in1,out1) 21 | 22 | compGraphD : FreeGraphD $ TensorD [1] 23 | compGraphD = do 24 | (in1,out1)<-depGraph2 25 | pure in1 26 | ``` 27 | 28 | # Prepare 29 | 1.verify tf c lib is installed 30 | ``` 31 | ls /usr/lib | grep tensor 32 | 33 | should give sth like: 34 | 35 | libtensorflow_framework.so 36 | libtensorflow.so 37 | 38 | ``` 39 | 40 | 2.install idris-free package with freer 41 | 42 | https://github.com/idris-industry/idris-free (not merged yet) 43 | 44 | and https://github.com/idris-industry/derive 45 | 46 | then idris-emacs mode will load fine (you can take a look at .ipkg file) 47 | 48 | warning! idris-free is also under active development,please check dependencies are the newest! 49 | 50 | # Run 51 | ``` 52 | idris Ffi.idr -o idr 53 | ./idr 54 | ``` 55 | 56 | which should output your installed tf version 57 | 58 | # Overview 59 | Construct idris computation graph with free monad approach,transform it and send to tf c api 60 | 61 | c_api.h is the tf low level api,we can get `operations` or `op` , for exmaple,matmul,placeholders,variables,etc,with TF_newOperation . Unfortunately,there is not a type-safe list for such operations. 62 | 63 | At high level, User defined computation graph would be optimised and then transformed to tf graph. 64 | 65 | project files: 66 | 67 | ``` 68 | Elabs.idr : macros 69 | UserApi : user level graph construction and ops ,with freer monad 70 | Ffi : tf ffi bindings , link to /usr/include/tensorflow/c/c_api.h 71 | Midlevel : anything else between userapi and FFi 72 | ``` 73 | 74 | # Info 75 | Free monad: 76 | https://github.com/idris-hackers/idris-free 77 | 78 | https://towardsdatascience.com/gradient-descend-with-free-monads-ebf9a23bece5 79 | 80 | https://typelevel.org/cats/datatypes/freemonad.html 81 | 82 | haskell and scala example: 83 | 84 | https://github.com/tensorflow/haskell/blob/master/tensorflow/src/TensorFlow/Internal/Raw.chs 85 | 86 | https://github.com/tensorflow/haskell 87 | 88 | https://github.com/helq/tensorflow-haskell-deptyped 89 | 90 | https://github.com/eaplatanios/tensorflow_scala 91 | 92 | idris ffi: 93 | 94 | bind to c struct ! : https://github.com/idris-lang/Idris-dev/tree/master/libs/contrib/CFFI 95 | 96 | http://docs.idris-lang.org/en/latest/tutorial/miscellany.html 97 | 98 | http://docs.idris-lang.org/en/latest/reference/ffi.html 99 | 100 | https://github.com/idris-lang/Idris-dev/blob/8b6f86e4291b8978c5e01a2dfd387ce695c5ff85/libs/base/Data/IORef.idr 101 | 102 | https://github.com/idris-lang/Idris-dev/blob/24f580d45455b3fee35d0e96e48415612e58aaed/libs/prelude/IO.idr 103 | 104 | idris elab refl: 105 | 106 | http://www.davidchristiansen.dk/david-christiansen-phd.pdf 107 | 108 | http://www.davidchristiansen.dk/pubs/type-directed-elaboration-of-quasiquotations.pdf 109 | 110 | http://cattheory.com/editTimeTacticsDraft.pdf 111 | 112 | tf c api usage: 113 | 114 | https://stackoverflow.com/questions/44378764/hello-tensorflow-using-the-c-api 115 | 116 | https://www.tensorflow.org/install/install_c 117 | 118 | https://www.tensorflow.org/extend/language_bindings 119 | 120 | `TensorFlow has many ops, and the list is not static, so we recommend generating the functions for adding ops to a graph instead of writing them by individually by hand (though writing a few by hand is a good way to figure out what the generator should generate)` 121 | 122 | https://github.com/tensorflow/tensorflow/blob/r1.8/tensorflow/core/ops/ops.pbtxt 123 | 124 | https://www.tensorflow.org/api_docs/python/tf/Operation 125 | 126 | `An Operation is a node in a TensorFlow Graph that takes zero or more Tensor objects as input, and produces zero or more Tensor objects as output. Objects of type Operation are created by calling a Python op constructor (such as tf.matmul) or tf.Graph.create_op.` 127 | 128 | # Road map 129 | 130 | 1.get idris tf ffi to work (ok) 131 | 132 | 2.implement tf ops api with free monad 133 | 134 | 3.write your own computational graph 135 | 136 | 4.train and predict 137 | 138 | # Looking forward for your to join! 139 | 140 | more about idris ffi 141 | 142 | tf c api usage 143 | 144 | a free/freer/algebraic effects computation graph api 145 | 146 | tf architecture 147 | 148 | elaborator reflection 149 | 150 | any ideas! 151 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------