Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1#!/usr/bin/env python3 

2 

3# NOTE: See bottom of this module for imported modules 

4 

5class FADiff: 

6 _fadscal_inputs = [] # Global input scalar vars list 

7 _fadvect_inputs = [] # Global input vector vars list 

8 _revscal_inputs = [] 

9 _mode = 'forward' # Default mode is forward mode 

10 

11 @staticmethod 

12 def set_mode(mode): 

13 # TODO: Input validation necessary here? 

14 FADiff._mode = mode.lower() 

15 

16 @staticmethod 

17 def new_scal(val, der=None, name=None): 

18 if not der: # No der arg? 

19 der = 1 # Init der to 1 

20 if FADiff._mode == 'forward': 

21 return _fadScal(val, der=der, name=name, new_input=True) 

22 elif FADiff._mode == 'reverse': 

23 return _revScal(val, der=der, name=name, new_input=True) 

24 

25 @staticmethod 

26 def new_vect(vect, der=None, name=None): 

27 if FADiff._mode == 'forward': 

28 if not der: # No der arg? 

29 der = 1 # Init der to identity matrix 

30 return _fadVect(vect, der=der, name=name, new_input=True) 

31 elif FADiff._mode == 'reverse': 

32 return _revVect() 

33 

34 @staticmethod 

35 def new_funcvect(func_list): 

36 return _funcVect(func_list) 

37 

38 

39# NOTE: Imports intentionally at bottom to prevent circular dependencies 

40from fad.Gradients import Scal as _fadScal 

41from fad.Matrices import Vect as _fadVect 

42from FuncVect import FuncVect as _funcVect 

43from rev.Gradients import Scal as _revScal 

44from rev.Matrices import Vect as _revVect 

45 

46 

47# References: 

48# - https://www.programiz.com/python-programming/docstrings