Skip to content
This repository has been archived by the owner on Jul 23, 2019. It is now read-only.

Lambdify support #12

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open

Lambdify support #12

wants to merge 23 commits into from

Conversation

cjayross
Copy link
Contributor

@cjayross cjayross commented Jul 7, 2019

Addresses #3

This is an important merge as it provides a convenient and efficient way to convert tensor expressions into numerical functions that can be used in algorithms like Runge-Kutta.

I defined a new class called NumericalArray which has two important attributes. The first is an attribute called _lambda which is the lambdified function for the entire array. The second is _generator which is an array where each individual component is a lambda function for that specific component. This is an important distinction since this allows for calculating single components without having to do calculations for every other component as well (which is what _lambda does).

These attributes are accessed very easily by defining the __call__ and __getitem__ attributes. Calling an instance of NumericalArray is equivalent to calling it's _lambda argument while accessing a component like an array returns a lambda for that component, which can be subsequently called just the same.

>>> t, r, th, ph = symbols('t r theta phi', real=True)
>>> schw = diag(1-1/r, -1/(1-1/r), -r**2, -r**2*sin(th)**2)
>>> g = Metric('g', (t, r, th, ph), schw)
>>> narr = lambdify_tensor((r, th), g(-mu,-nu))
>>> narr(2, 0)
array([[ 0.5,  0. ,  0. ,  0. ],
       [ 0. , -2. ,  0. ,  0. ],
       [ 0. ,  0. , -4. ,  0. ],
       [ 0. ,  0. ,  0. , -0. ]])
>>> narr[0,0]
<function _lambdifygenerated(r, theta)>
>>> narr[0,0](2, 0)
0.5

Note: The changes currently lack test cases unfortunately.

@pep8speaks
Copy link

pep8speaks commented Jul 7, 2019

Hello @cjayross! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

Line 15:81: E501 line too long (84 > 80 characters)
Line 17:81: E501 line too long (86 > 80 characters)
Line 18:81: E501 line too long (86 > 80 characters)
Line 21:81: E501 line too long (85 > 80 characters)
Line 33:81: E501 line too long (86 > 80 characters)
Line 64:81: E501 line too long (86 > 80 characters)
Line 75:81: E501 line too long (84 > 80 characters)
Line 85:81: E501 line too long (82 > 80 characters)
Line 88:81: E501 line too long (81 > 80 characters)
Line 91:81: E501 line too long (84 > 80 characters)

Line 9:1: E302 expected 2 blank lines, found 1
Line 17:1: E302 expected 2 blank lines, found 1
Line 21:29: E231 missing whitespace after ','
Line 23:29: E231 missing whitespace after ','
Line 24:18: E231 missing whitespace after ','
Line 24:23: E231 missing whitespace after ','
Line 26:1: E302 expected 2 blank lines, found 1
Line 28:42: E231 missing whitespace after ','

Comment last updated at 2019-07-09 07:07:47 UTC

@codecov-io
Copy link

codecov-io commented Jul 7, 2019

Codecov Report

Merging #12 into master will decrease coverage by 6.22%.
The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master     #12      +/-   ##
=========================================
- Coverage   94.72%   88.5%   -6.23%     
=========================================
  Files           9      10       +1     
  Lines         512     548      +36     
=========================================
  Hits          485     485              
- Misses         27      63      +36
Impacted Files Coverage Δ
src/riccipy/__init__.py 100% <ø> (ø) ⬆️
src/riccipy/numerical.py 0% <0%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f3c5413...0a1ca94. Read the comment docs.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants