Skip to content

Commit

Permalink
Merge pull request #344 from willow-ahrens/wma/fix343
Browse files Browse the repository at this point in the history
Better errors on unloaded extensions
  • Loading branch information
willow-ahrens authored Dec 6, 2023
2 parents 83e2f05 + 0b10a71 commit 2083d0a
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 109 deletions.
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 @@ struct NPYPath
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`)"))

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

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`)"))

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 @@ Write a sparse Finch fiber to a TensorMarket file.
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`)"))

"""
fttread(filename, infoonly=false, retcoord=false)
Expand All @@ -19,12 +19,12 @@ COO depending on the format of the file.
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`)"))

"""
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 @@ Write a sparse Finch fiber to a [FROSTT](http://frostt.io/tensors/) `.tns` file.
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`)"))

"""
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 @@ Read the contents of the [FROSTT](http://frostt.io/tensors/) `.tns` file 'filena
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`)"))
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

0 comments on commit 2083d0a

Please sign in to comment.