Skip to content

[pull] master from JuliaInterop:master #21

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

Merged
merged 9 commits into from
Feb 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/" # Location of package manifests
schedule:
interval: "monthly"
2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
arch:
- x64
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@latest
with:
version: ${{ matrix.version }}
Expand Down
19 changes: 19 additions & 0 deletions .github/workflows/TagBot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,22 @@ on:
types:
- created
workflow_dispatch:
inputs:
lookback:
default: 3
permissions:
actions: read
checks: read
contents: write
deployments: read
issues: read
discussions: read
packages: read
pages: read
pull-requests: read
repository-projects: read
security-events: read
statuses: read
jobs:
TagBot:
if: github.event_name == 'workflow_dispatch' || github.actor == 'JuliaTagBot'
Expand All @@ -12,3 +28,6 @@ jobs:
- uses: JuliaRegistries/TagBot@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
# Edit the following line to reflect the actual name of the GitHub Secret containing your private key
ssh: ${{ secrets.DOCUMENTER_KEY }}
# ssh: ${{ secrets.NAME_OF_MY_SSH_PRIVATE_KEY_SECRET }}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## MATLAB

| ❗ Windows and MacOS platforms : MATLAB versions R2022 and R2023 do not work with `MATLAB.jl` ❗ <br/> You can use older versions as explained [further down](https://github.com/JuliaInterop/MATLAB.jl#changing-matlab-version). |
| ❗ If you get a 'Segmentation fault' error when calling MATLAB with version R2022 or newer, try using an [older version](https://github.com/JuliaInterop/MATLAB.jl#changing-matlab-version) of MATLAB. ❗ |
|:----:|

The `MATLAB.jl` package provides an interface for using [MATLAB®](http://www.mathworks.com/products/matlab/) from [Julia](http://julialang.org) using the MATLAB C api. In other words, this package allows users to call MATLAB functions within Julia, thus making it easy to interoperate with MATLAB from the Julia language.
Expand Down
32 changes: 31 additions & 1 deletion src/mxarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ function mxarray(a::AbstractArray{T}) where {T<:MxRealNum}
return mx
end

function mxarray(a::AbstractArray{T}) where {T<:MxComplexNum}
function mxarray(a::AbstractArray{T}) where {T <: MxComplexNum}
mx = mxarray(T, size(a))
na = length(a)
rdat = unsafe_wrap(Array, real_ptr(mx), na)
Expand All @@ -302,6 +302,36 @@ function mxarray(a::AbstractArray{T}) where {T<:MxComplexNum}
end


function mxarray(a::NTuple{N, T}) where {N, T <: MxRealNum}
mx = mxarray(T, N)
pdat = ccall(mx_get_data[], Ptr{T}, (Ptr{Cvoid},), mx)
dat = unsafe_wrap(Array, pdat, N)
for i in 1:N
dat[i] = a[i]
end
return mx
end

function mxarray(a::NTuple{N, T}) where {N, T <: MxComplexNum}
mx = mxarray(T, size(a))
na = length(a)
rdat = unsafe_wrap(Array, real_ptr(mx), na)
idat = unsafe_wrap(Array, imag_ptr(mx), na)
for (i, ix) in enumerate(eachindex(a))
rdat[i] = real(a[ix])
idat[i] = imag(a[ix])
end
return mx
end

function mxarray(a::Tuple)
mx = mxcellarray(length(a))
for i in 1:length(a)
set_cell(mx, i, mxarray(a[i]))
end
return mx
end

# sparse matrix

function mxsparse(ty::Type{Float64}, m::Integer, n::Integer, nzmax::Integer)
Expand Down
22 changes: 22 additions & 0 deletions test/mxarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,28 @@ delete(x)
@test isa(y, Array{Bool,3})
@test isequal(y, a)

# Issue: Tuples converted to MATLAB structs
# https://github.com/JuliaInterop/MATLAB.jl/issues/178
a = (2.5, 2.6)
x = mxarray(a)
y = jvalue(x)
@test classid(x) == MATLAB.mxDOUBLE_CLASS
@test nrows(x) == 2
@test ncols(x) == 1
delete(x)
@test isa(y, Vector{Float64})
@test isequal(y, collect(a))

# Tuple with mixed types
a = (1, 2.0, "MATLAB", [1, 2, 3])
x = mxarray(a)
y = jvalue(x)
@test nrows(x) == 4
@test ncols(x) == 1
@test classid(x) == MATLAB.mxCELL_CLASS
@test isa(y, Vector{Any})
@test length(y) == length(a)
@test isequal(y, collect(a))


##############################
Expand Down
Loading