You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/usage.md
+52-5Lines changed: 52 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -110,13 +110,13 @@ x₃x³A¹₆ + 2A¹₅x⁵x₆
110
110
111
111
See [Derivatives in Standard Notation](@ref) for more examples.
112
112
113
-
## Converting Tensor Expression to Standard Notation
113
+
## Converting Tensor Expressions to Standard Notation
114
114
115
115
An expression in Ricci-notation can be converted back to standard notation using [`to_std`](@ref). `DiffMatic` can output a standard expression in string format or as a Julia function.
116
116
117
117
### String Output
118
118
119
-
An expression can be converted to standard matrix notation and retrieved as a string by passing [`StdStr`](@ref) as a keyword argument to [`to_std`](@ref):
119
+
An expression can be converted to standard matrix notation and retrieved as a string by passing a [`StdStr`](@ref)instance as a keyword argument`format` to [`to_std`](@ref):
120
120
121
121
```jldoctest usage
122
122
to_std(J; format = StdStr())
@@ -128,6 +128,7 @@ to_std(J; format = StdStr())
128
128
129
129
Special notation used in the output:
130
130
- "⊙": Element-wise multiplication.
131
+
- "⊘": Element-wise division.
131
132
- "diag(x)": Diagonal matrix with "x" on the diagonal.
132
133
- "vec(1)": Vector consisting of 1:s.
133
134
- "sgn(x)": The signum function applied element-wise.
@@ -136,7 +137,7 @@ Special notation used in the output:
136
137
137
138
### Julia Function
138
139
139
-
A Julia function is generated by passing [`JuliaFunc`](@ref) as a keyword argument to [`to_std`](@ref). The function is returned in the form of an [expression](https://docs.julialang.org/en/v1/manual/metaprogramming/#Expressions-and-evaluation):
140
+
A Julia function is generated by passing a [`JuliaFunc`](@ref)instance as a keyword argument`format` to [`to_std`](@ref). The function is returned in the form of an [expression](https://docs.julialang.org/en/v1/manual/metaprogramming/#Expressions-and-evaluation):
140
141
141
142
```julia
142
143
to_std(g; format =JuliaFunc())
@@ -145,10 +146,10 @@ to_std(g; format = JuliaFunc())
return2* ((transpose(B) *transpose(A))* x) +2* (A *(B* x))
152
153
end
153
154
end
154
155
```
@@ -172,5 +173,51 @@ g_fun(An, Bn, xn)
172
173
450.0
173
174
```
174
175
176
+
The `JuliaFunc` generator may use functions and primitives defined in `LinearAlgebra`, such as e.g. `diagm` and `I`. These functions need to be explicitly imported by the user prior to usage:
177
+
178
+
```jldoctest usage
179
+
g = gradient(log.(A * x)' * x, x)
180
+
g_fun = eval(to_std(g; format = JuliaFunc()))
181
+
182
+
An = exp(3) * ones(3,3)
183
+
xn = Float64[1; 0; 0]
184
+
185
+
g_fun(An, xn)
186
+
187
+
# output
188
+
189
+
ERROR: UndefVarError: `diagm` not defined
190
+
```
191
+
192
+
```jldoctest usage
193
+
using LinearAlgebra: diagm
194
+
195
+
g_fun(An, xn)
196
+
197
+
# output
198
+
199
+
3-element Vector{Float64}:
200
+
4.0
201
+
4.0
202
+
4.0
203
+
```
204
+
205
+
The order of the arguments of the generated function can be specified through `JuliaFunc`:
0 commit comments