Code Monkey home page Code Monkey logo

Comments (3)

CalebBell avatar CalebBell commented on June 22, 2024

Hi Jeff,
This one I believe is a limitation of numba's vectorize function. The scalar form works fine:

from chemicals import numba
import numpy as np
numba.Lindsay_Bromley(333.0, np.array([0.2, 0.8]),  np.array([1.0, 1.0]), np.array([1.0, 1.0]),  np.array([351.0, 370.0]), np.array([18.0, 33.0]))

The broadcasting rules aren't quite all implemented in Numba. I have known about this issue for a while but haven't ran into it before. I will need to look into this one. It may be possible to implement some sort of a wrapper.
Sincerely.
Caleb

from chemicals.

jgostick avatar jgostick commented on June 22, 2024

Am I misunderstanding how a mixing rule is meant to work? I have two components and want want the mixture value for a range of compositions, so I would need to pass ys = [ [x1, x2, ...], [y1, y2, ...]]. Since I'm passing in a range of compositions, I should also be able to pass in a range for the other props too, correct? The way you've written it above, I can only use this function for a single composition ([x1, y1] = [0.2, 0.2]).

from chemicals.

CalebBell avatar CalebBell commented on June 22, 2024

Hi Jeff,
Numba is very magic but it isn't smart enough to know how to pass in the compositions, thermal conductivities, and viscositires to the inner loop. Should it vectorize by passing in ys=[x1, x2] or ys=[x1, y1]? It can't tell and there isn't a set of hard-coded assumptions for this case. In a case like this, there is a mechanism to manually specify how to do this calculation:

import chemicals.numba
import numpy as np
from numba import guvectorize
from numba.types import int64, float64

@guvectorize([(float64[:], float64[:, :], float64[:, :],
               float64[:, :], float64[:], float64[:], float64[:])], '(n),(n,n),(n,n),(n,n),(n),(n)->(n)')
def better_Lindsay_Bromley(T, ys, ks, mus, Tbs, MWs, res):
    for i in range(T.shape[0]):
        res[i] = chemicals.numba.Lindsay_Bromley(T[i], ys[:, i], ks[:, i], mus[:, i], Tbs, MWs)
    
better_Lindsay_Bromley(np.array([333.0, 334.0]), np.array([[0.2, 0.2], [0.8, 0.8]]),  np.array([[1, 1], [1,1]]), 
                      np.array([[1, 1], [1, 1]]), np.array([351.0, 370.0]), np.array([18.0, 33.0]))

array([0.9969455 , 0.99694497])

I don't have a clear idea how to implement this in the library as a whole at this time, but it is a topic I am interested in for sure.
In the future numba may have better support for doing this automatically. For example the error you received originally is clearly not applicable in this case.

from chemicals.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.