GithubHelp home page GithubHelp logo

Comments (10)

Speierers avatar Speierers commented on June 22, 2024

Hi @arpit15 ,

Regarding the test_scalar, you are right, the dot function will return a float for which the comparison op will yield a bool value. On the other hand, Vector1m is equivalent to mask_t<Array<float, 1>> in C++. Arrays with 1 dimension are pretty much the same as scalar values like float. Therefore you should be able to seamlessly do arithmetic between bool, Mask, and Vector1m in python, so no need for explicit cast.

The same applies to the test_cuda. However this time, the dot function return a CUDAArray<float> value (that lives on the GPU), to the operator< returns a Mask and not a bool.

Please let me know if this answered you questions.

from enoki.

arpit15 avatar arpit15 commented on June 22, 2024

I asked the difference in types because I am unable to perform operations between these types. For ex: I tried res = result1 & result2 in test_scalar and test_gpu both give me errors.
Error in scalar
TypeError: unsupported operand type(s) for &: 'bool' and 'enoki.scalar.Vector1m'
Error in gpu
TypeError: unsupported operand type(s) for &: 'enoki.cuda.Mask' and 'enoki.cuda.Vector1m

Please let me know the correct way to perform element-wise operations in enoki, if this is not the correct way.

from enoki.

Speierers avatar Speierers commented on June 22, 2024

Currently enoki.cuda.Mask can be implicitly casted to enoki.cuda.Vector1m but not the other way around. Somehow Python also tries to cast from right to left with the & operator, which causes your issue. I will try to fix this in the future.
In the meantime, you should be able to do res = result2 & result1.

Also, could you tell me why using cuda.Vector1f and not cuda.Float32? This should solve you issue as well.

from enoki.

arpit15 avatar arpit15 commented on June 22, 2024

Thanks! This issue is solved by using res = result2 & result1.
I am trying to write custom area emitter in python. My idea was to create a Vector1m for both scalar and cuda, to write logic like here. I presumed that comparing Vector1f in both variants would give me Vector1m which is the type I am observing on the python side when using arguments of sample_direction function.
Is there a reason to not have implicit converters from scalar.Vector1m to bool?

from enoki.

Speierers avatar Speierers commented on June 22, 2024

Is there a reason to not have implicit converters from scalar.Vector1m to bool?

No specific reason, we might add it in the future.

In this code

dot(ds.d, ds.n) < 0.f && neq(ds.pdf, 0.f)

both comparisons should return a Mask. I don't see where the Vector1f comes in?

from enoki.

arpit15 avatar arpit15 commented on June 22, 2024

I don't really care about using Vector1f. I am just using it to create Vector1m. Using neq in python yields Vector1m for neq(ds.pdf, 0). Therefore using
dot(ds.d, ds.n) < 0.f & neq(ds.pdf, 0.f) doesn't work. However,
neq(ds.pdf, 0.f) & dot(ds.d, ds.n) < 0.f works fine, as you suggested.
Is there a way to create Mask type var from Vector1m type var without explicitly knowing, if the variant is scalar or cuda?
The main source of my problems is friction between Vector1m and Mask types.

from enoki.

arpit15 avatar arpit15 commented on June 22, 2024

I see problems due to no implicit conversion from Vector1m to Mask when calling m_radiance->eval in scalar variant as the function requires Mask aka bool type. However, processing using neq(ds.pdf, 0.f) & dot(ds.d, ds.n) < 0.f & active gives me Vector1m

from enoki.

Speierers avatar Speierers commented on June 22, 2024

I see your problem now. There was indeed some missing bindings for the scalar mode causing the following issue:

ek.neq(0.0, 0.0) # -> return Vector1m instead of bool

This should be fixed now (486ddb0)

In the other modes (dynamic, cuda), I would be surprise if you ever encounter a Vector1m. This would indicate that there is another bug. Let me know in that case.

from enoki.

arpit15 avatar arpit15 commented on June 22, 2024

Thanks for resolving this error. I tripped over another bug. I don't know if I should make another issue for this.
ek.select(True, 0.1, 0.2) returns enoki.scalar.Vector1m with value [1] which is wrong type and value.

from enoki.

Speierers avatar Speierers commented on June 22, 2024

Another one, thanks!

Just fixed in 1cc24d0

from enoki.

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.