-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using a constant rhs in @tensor #111
Comments
No that is not supported. TensorOperations is rather restricted. It was motivated by physics applications and only handles expressions which can be thought of as being basis independent. I guess alternatives like Tullio.jl are more flexible and probably more useful for general data science / ML applications. |
I would like to share some insights on this issue. In my field, specifically in the areas of strong gravity and numerical relativity, constants play a role. To illustrate, consider the following example equation used in numerical relativity: Regrettably, I have found that Tullio.jl and other similar alternatives are not suitable for physics applications. The main reason is their non-standard implementation of einsum, as discussed in this thread: ahwillia/Einsum.jl#39. |
I am not sure I understand how the example equation is related to this question. In any case, for your question, can't you just do |
I apologize for any confusion. I used a random equation from a book to avoid presenting overly complex ones. My intention was to highlight the importance of scalar fields in physics, as they appear everywhere in my field. I would greatly appreciate it if TensorOperations.jl could support constants (scalar fields) in the expression. |
You could maybe have a look at |
This fills all 27 elements with 6, which is not what I wanted to achieve. |
It's a possible method, but it also requires simplifying the equation to factor out the constant (scalar field) part, which is inconvenient when dealing with a large number of equations. In relativity, the equations are typically very complex. I want to emphasize that a scalar field is a zeroth-order tensor field. There's no reason for me to exclude it from tensor operations. |
Oh yes, I misread / was too quick. Is there any reason not to simply write the loop? for i = 1:n
C[i,i,i] = 6
end It doesn't really fit into TensorOperations to handle anything with an index appearing more than two times. TensorOperations.jl should be well suited for anything that adheres strictly to Einstein's summation convention and that thus represents a basis-independent expression. Scalar fields are fine, either as rank-zero array or as constant, e.g. |
Is it possible to write this using Kronecker deltas? This could be useful for describing some "symmetric" tensors. Here is a 2D Example, but this can get up to 4D in mechanics. # does not work
using TensorOperations
struct δ end
import Base.getindex
Base.getindex(::Type{δ},inds...) = allequal(inds)
C = zeros(2,2)
@tensor begin
C[i,j] = 6*δ[i,j]+2*δ[i+j,1]
end |
Is it possible to assign a constant using the @tensor macro?
Example:
The text was updated successfully, but these errors were encountered: