runner.jl (1400B)
1 #!/usr/bin/env julia 2 # 3 # @license Apache-2.0 4 # 5 # Copyright (c) 2018 The Stdlib Authors. 6 # 7 # Licensed under the Apache License, Version 2.0 (the "License"); 8 # you may not use this file except in compliance with the License. 9 # You may obtain a copy of the License at 10 # 11 # http://www.apache.org/licenses/LICENSE-2.0 12 # 13 # Unless required by applicable law or agreed to in writing, software 14 # distributed under the License is distributed on an "AS IS" BASIS, 15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 # See the License for the specific language governing permissions and 17 # limitations under the License. 18 19 import JSON 20 21 """ 22 gen( x, filepath ) 23 24 Generate fixture data and write to file. 25 26 # Arguments 27 28 * `x`: domain 29 * `filepath::AbstractString`: filepath of the output file 30 31 # Examples 32 33 ``` julia 34 julia> x = range( -1000, stop = 1000, length = 2001 ); 35 julia> gen( x, \"./data.json\" ); 36 ``` 37 """ 38 function gen( x, filepath ) 39 y = Array{Float64}( undef, length(x) ); 40 for i in eachindex(x) 41 y[i] = exp( x[i] ); 42 end 43 44 data = Dict([ 45 ("x", x), 46 ("expected", y) 47 ]); 48 49 outfile = open( filepath, "w" ); 50 write( outfile, JSON.json(data) ); 51 close( outfile ); 52 end 53 54 # Get the filename: 55 file = @__FILE__; 56 57 # Extract the directory in which this file resides: 58 dir = dirname( file ); 59 60 x = range( -300, stop = 300, length = 10000 ); 61 out = joinpath( dir, "data.json" ); 62 gen( x, out );