Skip to content
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

Better errors on unloaded extensions #344

Merged
merged 5 commits into from
Dec 6, 2023
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
4 changes: 2 additions & 2 deletions ext/HDF5Ext.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ using Finch.DataStructures

isdefined(Base, :get_extension) ? (using HDF5) : (using ..HDF5)

function Finch.bspread_h5(fname)
function Finch.bspread_h5(fname::AbstractString)
h5open(fname, "r") do io
Finch.bspread(io)
end
end

function Finch.bspwrite_h5(fname, arr, attrs = OrderedDict())
function Finch.bspwrite_h5(fname::AbstractString, arr, attrs = OrderedDict())
h5open(fname, "w") do io
Finch.bspwrite(io, arr, attrs)
end
Expand Down
4 changes: 2 additions & 2 deletions ext/NPZExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ Finch.bspwrite_header(g::NPYPath, str::String) = write(joinpath(mkpath(g.dirname
Finch.bspread_vector(g::NPYPath, key) = g[key]
Finch.bspwrite_vector(g::NPYPath, vec, key) = (g[key] = vec)

function Finch.bspread_bspnpy(fname)
function Finch.bspread_bspnpy(fname::AbstractString)
bspread(NPYPath(fname))
end

function Finch.bspwrite_bspnpy(fname, arr, attrs = OrderedDict())
function Finch.bspwrite_bspnpy(fname::AbstractString, arr, attrs = OrderedDict())
bspwrite(NPYPath(fname), arr, attrs)
fname
end
Expand Down
8 changes: 4 additions & 4 deletions ext/TensorMarketExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ using Finch

isdefined(Base, :get_extension) ? (using TensorMarket) : (using ..TensorMarket)

function Finch.fttread(filename, infoonly = false, retcoord=false)
function Finch.fttread(filename::AbstractString, infoonly = false, retcoord=false)
infoonly && return ttread(filename, true)
out = ttread(filename, false, retcoord)
if out isa Tuple
Expand All @@ -20,15 +20,15 @@ function Finch.fttread(filename, infoonly = false, retcoord=false)
end
end

function Finch.fttwrite(filename, A)
function Finch.fttwrite(filename::AbstractString, A)
ttwrite(filename, ffindnz(A)..., size(A))
end

function Finch.ftnsread(filename)
function Finch.ftnsread(filename::AbstractString)
fsparse(tnsread(filename)...)
end

function Finch.ftnswrite(filename, A)
function Finch.ftnswrite(filename::AbstractString, A)
tnswrite(filename, ffindnz(A)...)
end

Expand Down
11 changes: 9 additions & 2 deletions src/Finch.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ export parallelAnalysis, ParallelAnalysisResults
export parallel, extent, dimless
export CPU, CPULocalVector, CPULocalMemory

struct FinchProtocolError <: Exception
msg::String
end

struct FinchExtensionError <: Exception
msg::String
end

include("base/limits.jl")
export Limit

Expand Down Expand Up @@ -131,6 +139,7 @@ include("base/mapreduce.jl")
include("base/compare.jl")
include("base/copy.jl")
include("base/fsparse.jl")
include("base/fileio/fileio.jl")

@static if !isdefined(Base, :get_extension)
function __init__()
Expand Down Expand Up @@ -158,6 +167,4 @@ end
end
end

include("fileio/fileio.jl")

end
80 changes: 0 additions & 80 deletions src/base/fileio.jl

This file was deleted.

8 changes: 4 additions & 4 deletions src/fileio/binsparse.jl → src/base/fileio/binsparse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,8 @@
dirname::String
end

function bspwrite_h5 end
function bspwrite_bspnpy end
bspwrite_h5(args...) = throw(FinchExtensionError("HDF5.jl must be loaded to write .bsp.h5 files (hint: `using HDF5`)"))
bspwrite_bspnpy(args...) = throw(FinchExtensionError("NPZ.jl must be loaded to write .bspnpy files (hint: `using NPZ`)"))

Check warning on line 258 in src/base/fileio/binsparse.jl

View check run for this annotation

Codecov / codecov/patch

src/base/fileio/binsparse.jl#L257-L258

Added lines #L257 - L258 were not covered by tests

function bspwrite(fname::AbstractString, arr, attrs = OrderedDict())
if endswith(fname, ".h5") || endswith(fname, ".hdf5")
Expand Down Expand Up @@ -292,8 +292,8 @@

function bspwrite_header end

function bspread_h5 end
function bspread_bspnpy end
bspread_h5(args...) = throw(FinchExtensionError("HDF5.jl must be loaded to read .bsp.h5 files (hint: `using HDF5`)"))
bspread_bspnpy(args...) = throw(FinchExtensionError("NPZ.jl must be loaded to read .bspnpy files (hint: `using NPZ`)"))

Check warning on line 296 in src/base/fileio/binsparse.jl

View check run for this annotation

Codecov / codecov/patch

src/base/fileio/binsparse.jl#L295-L296

Added lines #L295 - L296 were not covered by tests

function bspread(fname::AbstractString)
if endswith(fname, ".h5") || endswith(fname, ".hdf5")
Expand Down
8 changes: 2 additions & 6 deletions src/fileio/fileio.jl → src/base/fileio/fileio.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ function fwrite(filename::AbstractString, tns)
ftnswrite(filename, tns)
elseif endswith(filename, ".ttx") || endswith(filename, ".mtx")
fttwrite(filename, tns)
elseif endswith(filename, ".bsp.h5") || endswith(filename, ".bsp.hdf5")
bspwrite(filename, tns)
elseif endswith(filename, ".bspnpy")
elseif endswith(filename, ".bsp.h5") || endswith(filename, ".bsp.hdf5") || endswith(filename, ".bspnpy")
bspwrite(filename, tns)
else
error("Unknown file extension for file $filename")
Expand All @@ -41,9 +39,7 @@ function fread(filename::AbstractString)
ftnsread(filename)
elseif endswith(filename, ".ttx") || endswith(filename, ".mtx")
fttread(filename)
elseif endswith(filename, ".bsp.h5") || endswith(filename, ".bsp.hdf5")
bspread(filename)
elseif endswith(filename, ".bspnpy")
elseif endswith(filename, ".bsp.h5") || endswith(filename, ".bsp.hdf5") || endswith(filename, ".bspnpy")
bspread(filename)
else
error("Unknown file extension for file $filename")
Expand Down
12 changes: 6 additions & 6 deletions src/fileio/tensormarket.jl → src/base/fileio/tensormarket.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

See also: [ttwrite](http://willowahrens.io/TensorMarket.jl/stable/#TensorMarket.ttwrite)
"""
function fttwrite end
fttwrite(args...) = throw(FinchExtensionError("TensorMarket.jl must be loaded to use write .ttx files (hint: `using TensorMarket`)"))

Check warning on line 10 in src/base/fileio/tensormarket.jl

View check run for this annotation

Codecov / codecov/patch

src/base/fileio/tensormarket.jl#L10

Added line #L10 was not covered by tests

"""
fttread(filename, infoonly=false, retcoord=false)
Expand All @@ -19,12 +19,12 @@

See also: [ttread](http://willowahrens.io/TensorMarket.jl/stable/#TensorMarket.ttread)
"""
function fttread end
fttread(args...) = throw(FinchExtensionError("TensorMarket.jl must be loaded to use read .ttx files (hint: `using TensorMarket`)"))

Check warning on line 22 in src/base/fileio/tensormarket.jl

View check run for this annotation

Codecov / codecov/patch

src/base/fileio/tensormarket.jl#L22

Added line #L22 was not covered by tests

"""
ftnswrite(filename, tns)

Write a sparse Finch fiber to a [FROSTT](http://frostt.io/tensors/) `.tns` file.
Write a sparse Finch fiber to a FROSTT `.tns` file.

[TensorMarket](https://github.com/willow-ahrens/TensorMarket.jl) must be loaded for this function to be available.

Expand All @@ -34,12 +34,12 @@

See also: [tnswrite](http://willowahrens.io/TensorMarket.jl/stable/#TensorMarket.tnswrite)
"""
function ftnswrite end
ftnswrite(args...) = throw(FinchExtensionError("TensorMarket.jl must be loaded to write .tns files (hint: `using TensorMarket`)"))

Check warning on line 37 in src/base/fileio/tensormarket.jl

View check run for this annotation

Codecov / codecov/patch

src/base/fileio/tensormarket.jl#L37

Added line #L37 was not covered by tests

"""
ftnsread(filename)

Read the contents of the [FROSTT](http://frostt.io/tensors/) `.tns` file 'filename' into a Finch COO Fiber.
Read the contents of the FROSTT `.tns` file 'filename' into a Finch COO Fiber.

[TensorMarket](https://github.com/willow-ahrens/TensorMarket.jl) must be loaded for this function to be available.

Expand All @@ -49,4 +49,4 @@

See also: [tnsread](http://willowahrens.io/TensorMarket.jl/stable/#TensorMarket.tnsread)
"""
function ftnsread end
ftnsread(args...) = throw(FinchExtensionError("TensorMarket.jl must be loaded to read .tns files (hint: `using TensorMarket`)"))

Check warning on line 52 in src/base/fileio/tensormarket.jl

View check run for this annotation

Codecov / codecov/patch

src/base/fileio/tensormarket.jl#L52

Added line #L52 was not covered by tests
3 changes: 0 additions & 3 deletions src/looplets/unfurl.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ FinchNotation.finch_leaf(x::Furlable) = virtual(x)
# print(io, "Furlable()")
#end

struct FinchProtocolError <: Exception
msg::String
end

"""
unfurl(tns, ctx, ext, protos...)
Expand Down
Loading