Skip to content

Commit 5721d75

Browse files
committed
Format code
1 parent 16b1301 commit 5721d75

File tree

10 files changed

+377
-300
lines changed

10 files changed

+377
-300
lines changed

deps/build.jl

+27-16
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const depsfile = joinpath(@__DIR__, "deps.jl")
55
function find_matlab_root()
66
# Determine MATLAB library path and provide facilities to load libraries with this path
77
matlab_root = get(ENV, "MATLAB_ROOT",
8-
get(ENV, "MATLAB_HOME", nothing))
8+
get(ENV, "MATLAB_HOME", nothing))
99
if isnothing(matlab_root)
1010
matlab_exe = Sys.which("matlab")
1111
if !isnothing(matlab_exe)
@@ -22,7 +22,9 @@ function find_matlab_root()
2222
end
2323
end
2424
elseif Sys.iswindows()
25-
default_dir = Sys.WORD_SIZE == 32 ? "C:\\Program Files (x86)\\MATLAB" : "C:\\Program Files\\MATLAB"
25+
default_dir =
26+
Sys.WORD_SIZE == 32 ? "C:\\Program Files (x86)\\MATLAB" :
27+
"C:\\Program Files\\MATLAB"
2628
if isdir(default_dir)
2729
dirs = readdir(default_dir)
2830
filter!(dir -> occursin(r"^R[0-9]+[ab]$", dir), dirs)
@@ -42,7 +44,8 @@ function find_matlab_root()
4244
end
4345
end
4446
end
45-
!isnothing(matlab_root) && isdir(matlab_root) && @info("Detected MATLAB root folder at \"$matlab_root\"")
47+
!isnothing(matlab_root) && isdir(matlab_root) &&
48+
@info("Detected MATLAB root folder at \"$matlab_root\"")
4649
return matlab_root
4750
end
4851

@@ -63,7 +66,12 @@ end
6366

6467
function find_matlab_cmd(matlab_root)
6568
if Sys.iswindows()
66-
matlab_cmd = joinpath(matlab_root, "bin", (Sys.WORD_SIZE == 32 ? "win32" : "win64"), "matlab.exe")
69+
matlab_cmd = joinpath(
70+
matlab_root,
71+
"bin",
72+
(Sys.WORD_SIZE == 32 ? "win32" : "win64"),
73+
"matlab.exe",
74+
)
6775
isfile(matlab_cmd) && @info("Detected MATLAB executable at \"$matlab_cmd\"")
6876
else
6977
matlab_exe = joinpath(matlab_root, "bin", "matlab")
@@ -89,13 +97,14 @@ if !isnothing(matlab_root)
8997
error("MATLAB library has changed, re-run Pkg.build(\\\"MATLAB\\\")")
9098
end
9199
end
92-
"""
93-
)
94-
println(io, "const matlab_libpath = \"$(escape_string(matlab_libpath))\"")
95-
println(io, "const matlab_cmd = \"$(escape_string(matlab_cmd))\"")
96-
println(io, "const libmx_size = $libmx_size")
100+
""",
101+
)
102+
println(io, "const matlab_libpath = \"$(escape_string(matlab_libpath))\"")
103+
println(io, "const matlab_cmd = \"$(escape_string(matlab_cmd))\"")
104+
println(io, "const libmx_size = $libmx_size")
97105
end
98-
elseif get(ENV, "JULIA_REGISTRYCI_AUTOMERGE", nothing) == "true" || get(ENV, "CI", nothing) == "true"
106+
elseif get(ENV, "JULIA_REGISTRYCI_AUTOMERGE", nothing) == "true" ||
107+
get(ENV, "CI", nothing) == "true"
99108
# We need to be able to install and load this package without error for
100109
# Julia's registry AutoMerge to work, so we just use dummy values.
101110
# Similarly we want to also be able to install and load this package for CI.
@@ -109,12 +118,14 @@ elseif get(ENV, "JULIA_REGISTRYCI_AUTOMERGE", nothing) == "true" || get(ENV, "CI
109118
# This file is automatically generated, do not edit.
110119
111120
check_deps() = nothing
112-
"""
113-
)
114-
println(io, "const matlab_libpath = \"$(escape_string(matlab_libpath))\"")
115-
println(io, "const matlab_cmd = \"$(escape_string(matlab_cmd))\"")
116-
println(io, "const libmx_size = $libmx_size")
121+
""",
122+
)
123+
println(io, "const matlab_libpath = \"$(escape_string(matlab_libpath))\"")
124+
println(io, "const matlab_cmd = \"$(escape_string(matlab_cmd))\"")
125+
println(io, "const libmx_size = $libmx_size")
117126
end
118127
else
119-
error("MATLAB cannot be found. Set the \"MATLAB_ROOT\" environment variable to the MATLAB root directory and re-run Pkg.build(\"MATLAB\").")
128+
error(
129+
"MATLAB cannot be found. Set the \"MATLAB_ROOT\" environment variable to the MATLAB root directory and re-run Pkg.build(\"MATLAB\").",
130+
)
120131
end

src/MATLAB.jl

+120-122
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,29 @@ using SparseArrays
66
import Base: eltype, close, size, copy, ndims, unsafe_convert
77

88
# mxarray
9-
export MxArray, mxClassID, mxComplexity,
10-
mxclassid, data_ptr,
11-
classid, nrows, ncols, nelems, elsize
9+
export MxArray,
10+
mxClassID, mxComplexity,
11+
mxclassid, data_ptr,
12+
classid, nrows, ncols, nelems, elsize
1213

1314
export is_double, is_single,
14-
is_int8, is_uint8, is_int16, is_uint16,
15-
is_int32, is_uint32, is_int64, is_uint64,
16-
is_numeric, is_complex, is_sparse, is_empty,
17-
is_logical, is_char, is_struct, is_cell
15+
is_int8, is_uint8, is_int16, is_uint16,
16+
is_int32, is_uint32, is_int64, is_uint64,
17+
is_numeric, is_complex, is_sparse, is_empty,
18+
is_logical, is_char, is_struct, is_cell
1819

1920
export mxarray, mxsparse, delete,
20-
mxcellarray, get_cell, set_cell,
21-
mxstruct, mxstructarray, mxnfields, get_fieldname, get_field, set_field,
22-
jvalue, jarray, jscalar, jvector, jmatrix, jsparse, jstring, jdict
21+
mxcellarray, get_cell, set_cell,
22+
mxstruct, mxstructarray, mxnfields, get_fieldname, get_field, set_field,
23+
jvalue, jarray, jscalar, jvector, jmatrix, jsparse, jstring, jdict
2324

2425
# engine & matfile
2526
export MSession, MatFile,
26-
get_default_msession, restart_default_msession, close_default_msession,
27-
eval_string, get_mvariable, get_variable, put_variable, put_variables,
28-
variable_names, read_matfile, write_matfile,
29-
mxcall,
30-
@mput, @mget, @mat_str
27+
get_default_msession, restart_default_msession, close_default_msession,
28+
eval_string, get_mvariable, get_variable, put_variable, put_variables,
29+
variable_names, read_matfile, write_matfile,
30+
mxcall,
31+
@mput, @mget, @mat_str
3132

3233
if Sys.iswindows()
3334
export show_msession, hide_msession, get_msession_visiblity
@@ -37,7 +38,9 @@ const depsfile = joinpath(dirname(@__DIR__), "deps", "deps.jl")
3738
if isfile(depsfile)
3839
include(depsfile)
3940
else
40-
error("MATLAB is not properly installed. Please run Pkg.build(\"MATLAB\") and restart Julia.")
41+
error(
42+
"MATLAB is not properly installed. Please run Pkg.build(\"MATLAB\") and restart Julia.",
43+
)
4144
end
4245

4346
# exceptions
@@ -79,119 +82,114 @@ function __init__()
7982

8083
if libmx_size > 0 # non-zero size library path
8184

82-
# load libraries
83-
# workaround for https://github.com/JuliaInterop/MATLAB.jl/issues/200
84-
if Sys.iswindows()
85-
ENV["PATH"] = string(matlab_libpath, ";", ENV["PATH"])
86-
elseif Sys.islinux()
87-
ENV["PATH"] = string(matlab_libpath, ":", ENV["PATH"])
88-
end
89-
libmx[] = Libdl.dlopen(joinpath(matlab_libpath, "libmx"), Libdl.RTLD_GLOBAL)
90-
libmat[] = Libdl.dlopen(joinpath(matlab_libpath, "libmat"), Libdl.RTLD_GLOBAL)
91-
libeng[] = Libdl.dlopen(joinpath(matlab_libpath, "libeng"), Libdl.RTLD_GLOBAL)
92-
93-
# engine functions
94-
95-
eng_open[] = engfunc(:engOpen)
96-
eng_close[] = engfunc(:engClose)
97-
eng_set_visible[] = engfunc(:engSetVisible)
98-
eng_get_visible[] = engfunc(:engGetVisible)
99-
eng_output_buffer[] = engfunc(:engOutputBuffer)
100-
eng_eval_string[] = engfunc(:engEvalString)
101-
eng_put_variable[] = engfunc(:engPutVariable)
102-
eng_get_variable[] = engfunc(:engGetVariable)
103-
104-
# mxarray functions
105-
106-
mx_destroy_array[] = mxfunc(:mxDestroyArray)
107-
mx_duplicate_array[] = mxfunc(:mxDuplicateArray)
108-
109-
# load functions to access mxarray
110-
111-
mx_free[] = mxfunc(:mxFree)
112-
113-
mx_get_classid[] = mxfunc(:mxGetClassID)
114-
mx_get_m[] = mxfunc(:mxGetM)
115-
mx_get_n[] = mxfunc(:mxGetN)
116-
mx_get_nelems[] = mxfunc(:mxGetNumberOfElements)
117-
mx_get_ndims[] = mxfunc(:mxGetNumberOfDimensions_730)
118-
mx_get_elemsize[] = mxfunc(:mxGetElementSize)
119-
mx_get_data[] = mxfunc(:mxGetData)
120-
mx_get_dims[] = mxfunc(:mxGetDimensions_730)
121-
mx_get_nfields[] = mxfunc(:mxGetNumberOfFields)
122-
mx_get_pr[] = mxfunc(:mxGetPr)
123-
mx_get_pi[] = mxfunc(:mxGetPi)
124-
mx_get_ir[] = mxfunc(:mxGetIr_730)
125-
mx_get_jc[] = mxfunc(:mxGetJc_730)
126-
127-
mx_is_double[] = mxfunc(:mxIsDouble)
128-
mx_is_single[] = mxfunc(:mxIsSingle)
129-
mx_is_int64[] = mxfunc(:mxIsInt64)
130-
mx_is_uint64[] = mxfunc(:mxIsUint64)
131-
mx_is_int32[] = mxfunc(:mxIsInt32)
132-
mx_is_uint32[] = mxfunc(:mxIsUint32)
133-
mx_is_int16[] = mxfunc(:mxIsInt16)
134-
mx_is_uint16[] = mxfunc(:mxIsUint16)
135-
mx_is_int8[] = mxfunc(:mxIsInt8)
136-
mx_is_uint8[] = mxfunc(:mxIsUint8)
137-
mx_is_char[] = mxfunc(:mxIsChar)
138-
139-
mx_is_numeric[] = mxfunc(:mxIsNumeric)
140-
mx_is_logical[] = mxfunc(:mxIsLogical)
141-
mx_is_complex[] = mxfunc(:mxIsComplex)
142-
mx_is_sparse[] = mxfunc(:mxIsSparse)
143-
mx_is_empty[] = mxfunc(:mxIsEmpty)
144-
mx_is_struct[] = mxfunc(:mxIsStruct)
145-
mx_is_cell[] = mxfunc(:mxIsCell)
146-
147-
148-
# load functions to create & delete MATLAB array
149-
150-
mx_create_numeric_matrix[] = mxfunc(:mxCreateNumericMatrix_730)
151-
mx_create_numeric_array[] = mxfunc(:mxCreateNumericArray_730)
152-
153-
mx_create_double_scalar[] = mxfunc(:mxCreateDoubleScalar)
154-
mx_create_logical_scalar[] = mxfunc(:mxCreateLogicalScalar)
155-
156-
mx_create_sparse[] = mxfunc(:mxCreateSparse_730)
157-
mx_create_sparse_logical[] = mxfunc(:mxCreateSparseLogicalMatrix_730)
158-
159-
mx_create_string[] = mxfunc(:mxCreateString)
160-
mx_create_char_array[] = mxfunc(:mxCreateCharArray_730)
161-
162-
mx_create_cell_array[] = mxfunc(:mxCreateCellArray_730)
163-
164-
mx_create_struct_matrix[] = mxfunc(:mxCreateStructMatrix_730)
165-
mx_create_struct_array[] = mxfunc(:mxCreateStructArray_730)
166-
167-
mx_get_cell[] = mxfunc(:mxGetCell_730)
168-
mx_set_cell[] = mxfunc(:mxSetCell_730)
169-
170-
mx_get_field[] = mxfunc(:mxGetField_730)
171-
mx_set_field[] = mxfunc(:mxSetField_730)
172-
mx_get_field_bynum[] = mxfunc(:mxGetFieldByNumber_730)
173-
mx_get_fieldname[] = mxfunc(:mxGetFieldNameByNumber)
174-
175-
mx_get_string[] = mxfunc(:mxGetString_730)
176-
177-
178-
# load I/O mat functions
179-
180-
mat_open[] = matfunc(:matOpen)
181-
mat_close[] = matfunc(:matClose)
182-
mat_get_variable[] = matfunc(:matGetVariable)
183-
mat_put_variable[] = matfunc(:matPutVariable)
184-
mat_get_dir[] = matfunc(:matGetDir)
185-
85+
# load libraries
86+
# workaround for https://github.com/JuliaInterop/MATLAB.jl/issues/200
87+
if Sys.iswindows()
88+
ENV["PATH"] = string(matlab_libpath, ";", ENV["PATH"])
89+
elseif Sys.islinux()
90+
ENV["PATH"] = string(matlab_libpath, ":", ENV["PATH"])
91+
end
92+
libmx[] = Libdl.dlopen(joinpath(matlab_libpath, "libmx"), Libdl.RTLD_GLOBAL)
93+
libmat[] = Libdl.dlopen(joinpath(matlab_libpath, "libmat"), Libdl.RTLD_GLOBAL)
94+
libeng[] = Libdl.dlopen(joinpath(matlab_libpath, "libeng"), Libdl.RTLD_GLOBAL)
95+
96+
# engine functions
97+
98+
eng_open[] = engfunc(:engOpen)
99+
eng_close[] = engfunc(:engClose)
100+
eng_set_visible[] = engfunc(:engSetVisible)
101+
eng_get_visible[] = engfunc(:engGetVisible)
102+
eng_output_buffer[] = engfunc(:engOutputBuffer)
103+
eng_eval_string[] = engfunc(:engEvalString)
104+
eng_put_variable[] = engfunc(:engPutVariable)
105+
eng_get_variable[] = engfunc(:engGetVariable)
106+
107+
# mxarray functions
108+
109+
mx_destroy_array[] = mxfunc(:mxDestroyArray)
110+
mx_duplicate_array[] = mxfunc(:mxDuplicateArray)
111+
112+
# load functions to access mxarray
113+
114+
mx_free[] = mxfunc(:mxFree)
115+
116+
mx_get_classid[] = mxfunc(:mxGetClassID)
117+
mx_get_m[] = mxfunc(:mxGetM)
118+
mx_get_n[] = mxfunc(:mxGetN)
119+
mx_get_nelems[] = mxfunc(:mxGetNumberOfElements)
120+
mx_get_ndims[] = mxfunc(:mxGetNumberOfDimensions_730)
121+
mx_get_elemsize[] = mxfunc(:mxGetElementSize)
122+
mx_get_data[] = mxfunc(:mxGetData)
123+
mx_get_dims[] = mxfunc(:mxGetDimensions_730)
124+
mx_get_nfields[] = mxfunc(:mxGetNumberOfFields)
125+
mx_get_pr[] = mxfunc(:mxGetPr)
126+
mx_get_pi[] = mxfunc(:mxGetPi)
127+
mx_get_ir[] = mxfunc(:mxGetIr_730)
128+
mx_get_jc[] = mxfunc(:mxGetJc_730)
129+
130+
mx_is_double[] = mxfunc(:mxIsDouble)
131+
mx_is_single[] = mxfunc(:mxIsSingle)
132+
mx_is_int64[] = mxfunc(:mxIsInt64)
133+
mx_is_uint64[] = mxfunc(:mxIsUint64)
134+
mx_is_int32[] = mxfunc(:mxIsInt32)
135+
mx_is_uint32[] = mxfunc(:mxIsUint32)
136+
mx_is_int16[] = mxfunc(:mxIsInt16)
137+
mx_is_uint16[] = mxfunc(:mxIsUint16)
138+
mx_is_int8[] = mxfunc(:mxIsInt8)
139+
mx_is_uint8[] = mxfunc(:mxIsUint8)
140+
mx_is_char[] = mxfunc(:mxIsChar)
141+
142+
mx_is_numeric[] = mxfunc(:mxIsNumeric)
143+
mx_is_logical[] = mxfunc(:mxIsLogical)
144+
mx_is_complex[] = mxfunc(:mxIsComplex)
145+
mx_is_sparse[] = mxfunc(:mxIsSparse)
146+
mx_is_empty[] = mxfunc(:mxIsEmpty)
147+
mx_is_struct[] = mxfunc(:mxIsStruct)
148+
mx_is_cell[] = mxfunc(:mxIsCell)
149+
150+
# load functions to create & delete MATLAB array
151+
152+
mx_create_numeric_matrix[] = mxfunc(:mxCreateNumericMatrix_730)
153+
mx_create_numeric_array[] = mxfunc(:mxCreateNumericArray_730)
154+
155+
mx_create_double_scalar[] = mxfunc(:mxCreateDoubleScalar)
156+
mx_create_logical_scalar[] = mxfunc(:mxCreateLogicalScalar)
157+
158+
mx_create_sparse[] = mxfunc(:mxCreateSparse_730)
159+
mx_create_sparse_logical[] = mxfunc(:mxCreateSparseLogicalMatrix_730)
160+
161+
mx_create_string[] = mxfunc(:mxCreateString)
162+
mx_create_char_array[] = mxfunc(:mxCreateCharArray_730)
163+
164+
mx_create_cell_array[] = mxfunc(:mxCreateCellArray_730)
165+
166+
mx_create_struct_matrix[] = mxfunc(:mxCreateStructMatrix_730)
167+
mx_create_struct_array[] = mxfunc(:mxCreateStructArray_730)
168+
169+
mx_get_cell[] = mxfunc(:mxGetCell_730)
170+
mx_set_cell[] = mxfunc(:mxSetCell_730)
171+
172+
mx_get_field[] = mxfunc(:mxGetField_730)
173+
mx_set_field[] = mxfunc(:mxSetField_730)
174+
mx_get_field_bynum[] = mxfunc(:mxGetFieldByNumber_730)
175+
mx_get_fieldname[] = mxfunc(:mxGetFieldNameByNumber)
176+
177+
mx_get_string[] = mxfunc(:mxGetString_730)
178+
179+
# load I/O mat functions
180+
181+
mat_open[] = matfunc(:matOpen)
182+
mat_close[] = matfunc(:matClose)
183+
mat_get_variable[] = matfunc(:matGetVariable)
184+
mat_put_variable[] = matfunc(:matPutVariable)
185+
mat_get_dir[] = matfunc(:matGetDir)
186186
end
187187
end
188188

189-
190189
###########################################################
191190
#
192191
# deprecations
193192
#
194193
###########################################################
195194

196-
197195
end

0 commit comments

Comments
 (0)