-
-
Save Non-Contradiction/6b09c4c368377a9f341cc5dc28e04907 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(JuliaCall) | |
julia_setup() | |
julia_library("ForwardDiff") | |
f <- function(x) sum(x^2L) | |
julia_assign("ff", f) | |
julia_command("g = x -> ForwardDiff.gradient(ff, x);") | |
julia_command("g([2.0])") | |
## 1-element Array{Float64,1}: | |
## 4.0 | |
julia_command("g([3.0])") | |
## 1-element Array{Float64,1}: | |
## 6.0 | |
## This is problematic, don't know why, but it seems like a problem related to integer? | |
julia_command("g([4.0])") | |
## 1-element Array{Float64,1}: | |
## 32.0 | |
## This works as expected. | |
julia_command("g([4.01])") | |
## 1-element Array{Float64,1}: | |
## 8.02 | |
## This doesn't work also... | |
julia_command("g([1.01,4.01])") | |
## Error: Error happens when you try to call function sum in Julia. | |
## DimensionMismatch("dimensions must match") | |
## But this works... | |
julia_command("g([1.01,2.01])") | |
## 2-element Array{Float64,1}: | |
## 2.02 | |
## 4.02 | |
## And this doesn't work!!! | |
julia_command("g([1.01,2.0])") | |
## Error: Error happens when you try to call function sum in Julia. | |
## DimensionMismatch("dimensions must match") | |
julia_command("g([3.01,2.01])") | |
## 2-element Array{Float64,1}: | |
## 6.02 | |
## 4.02 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment