From 692b8a380736597eec9f4c01004554f81ffb4b68 Mon Sep 17 00:00:00 2001 From: Willow Ahrens Date: Wed, 6 Dec 2023 08:44:13 -0500 Subject: [PATCH 1/5] fix the error --- ext/TensorMarketExt.jl | 8 +-- src/Finch.jl | 11 +++- src/base/fileio.jl | 80 --------------------------- src/{ => base}/fileio/binsparse.jl | 8 +-- src/{ => base}/fileio/fileio.jl | 8 +-- src/{ => base}/fileio/tensormarket.jl | 16 +++--- src/looplets/unfurl.jl | 3 - 7 files changed, 27 insertions(+), 107 deletions(-) delete mode 100644 src/base/fileio.jl rename src/{ => base}/fileio/binsparse.jl (96%) rename src/{ => base}/fileio/fileio.jl (92%) rename src/{ => base}/fileio/tensormarket.jl (65%) diff --git a/ext/TensorMarketExt.jl b/ext/TensorMarketExt.jl index 8f3c37b7b..21b4dee9d 100644 --- a/ext/TensorMarketExt.jl +++ b/ext/TensorMarketExt.jl @@ -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 @@ -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 diff --git a/src/Finch.jl b/src/Finch.jl index 172a633a3..22bce6e23 100644 --- a/src/Finch.jl +++ b/src/Finch.jl @@ -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 @@ -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__() @@ -158,6 +167,4 @@ end end end -include("fileio/fileio.jl") - end diff --git a/src/base/fileio.jl b/src/base/fileio.jl deleted file mode 100644 index 7de787142..000000000 --- a/src/base/fileio.jl +++ /dev/null @@ -1,80 +0,0 @@ -""" - ttxwrite(filename, tns) - -Write a sparse Finch fiber to a TensorMarket file. - -[TensorMarket](https://github.com/willow-ahrens/TensorMarket.jl) must be loaded for this function to be available. - -See also: [ttwrite](http://willowahrens.io/TensorMarket.jl/stable/#TensorMarket.ttwrite) -""" -function ttxwrite end - -""" - ttxread(filename, infoonly=false, retcoord=false) - -Read the TensorMarket file into a Finch fiber. The fiber will be dense or -COO depending on the format of the file. - -[TensorMarket](https://github.com/willow-ahrens/TensorMarket.jl) must be loaded for this function to be available. - -See also: [ttread](http://willowahrens.io/TensorMarket.jl/stable/#TensorMarket.ttread) -""" -function ttxread end - -""" - tnswrite(filename, tns) - -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. - -!!! danger - This file format does not record the size or eltype of the tensor, and is provided for - archival purposes only. - -See also: [tnswrite](http://willowahrens.io/TensorMarket.jl/stable/#TensorMarket.tnswrite) -""" -function tnswrite end - -""" - tnsread(filename) - -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. - -!!! danger - This file format does not record the size or eltype of the tensor, and is provided for - archival purposes only. - -See also: [tnsread](http://willowahrens.io/TensorMarket.jl/stable/#TensorMarket.tnsread) -""" -function tnsread end - -""" - bspwrite(filename, tns) - -Write the Finch fiber to a file using -[Binsparse](https://github.com/GraphBLAS/binsparse-specification) HDF5 file -format. - -[HDF5](https://github.com/JuliaIO/HDF5.jl) must be loaded for this function to be available - -!!! warning - The Binsparse spec is under development. Additionally, this function may not - be fully conformant. Please file bug reports if you see anything amiss. -""" -function bspwrite end - -""" - bspread(filename) - -Read the [Binsparse](https://github.com/GraphBLAS/binsparse-specification) HDF5 file into a Finch tensor. - -[HDF5](https://github.com/JuliaIO/HDF5.jl) must be loaded for this function to be available - -!!! warning - The Binsparse spec is under development. Additionally, this function may not - be fully conformant. Please file bug reports if you see anything amiss. -""" -function bspread end \ No newline at end of file diff --git a/src/fileio/binsparse.jl b/src/base/fileio/binsparse.jl similarity index 96% rename from src/fileio/binsparse.jl rename to src/base/fileio/binsparse.jl index 916da2b3a..e1015a629 100644 --- a/src/fileio/binsparse.jl +++ b/src/base/fileio/binsparse.jl @@ -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 Binsparse HDF5 (hint: `using HDF5`)")) +bspwrite_bspnpy(args...) = throw(FinchExtensionError("NPZ.jl must be loaded to write Binsparse NPY (hint: `using NPZ`)")) function bspwrite(fname::AbstractString, arr, attrs = OrderedDict()) if endswith(fname, ".h5") || endswith(fname, ".hdf5") @@ -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 Binsparse HDF5 (hint: `using HDF5`)")) +bspread_bspnpy(args...) = throw(FinchExtensionError("NPZ.jl must be loaded to read Binsparse NPY (hint: `using NPZ`)")) function bspread(fname::AbstractString) if endswith(fname, ".h5") || endswith(fname, ".hdf5") diff --git a/src/fileio/fileio.jl b/src/base/fileio/fileio.jl similarity index 92% rename from src/fileio/fileio.jl rename to src/base/fileio/fileio.jl index c7edf8177..473fce149 100644 --- a/src/fileio/fileio.jl +++ b/src/base/fileio/fileio.jl @@ -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") @@ -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") diff --git a/src/fileio/tensormarket.jl b/src/base/fileio/tensormarket.jl similarity index 65% rename from src/fileio/tensormarket.jl rename to src/base/fileio/tensormarket.jl index b141b1ae6..4c2c2ae28 100644 --- a/src/fileio/tensormarket.jl +++ b/src/base/fileio/tensormarket.jl @@ -1,5 +1,5 @@ """ - fttwrite(filename, tns) + fttxwrite(filename, tns) Write a sparse Finch fiber to a TensorMarket file. @@ -7,10 +7,10 @@ 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 fttxwrite (hint: `using TensorMarket`)")) """ - fttread(filename, infoonly=false, retcoord=false) + fttxread(filename, infoonly=false, retcoord=false) Read the TensorMarket file into a Finch fiber. The fiber will be dense or COO depending on the format of the file. @@ -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 fttxread (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. @@ -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 use ftnswrite (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. @@ -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 \ No newline at end of file +ftnsread() = throw(FinchExtensionError("TensorMarket.jl must be loaded to use ftnsread (hint: `using TensorMarket`)")) diff --git a/src/looplets/unfurl.jl b/src/looplets/unfurl.jl index 3284519b2..398ab3d7d 100644 --- a/src/looplets/unfurl.jl +++ b/src/looplets/unfurl.jl @@ -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...) From 0405a2c78bb64d64469ddb5e11aec87d29ee97c3 Mon Sep 17 00:00:00 2001 From: Willow Ahrens Date: Wed, 6 Dec 2023 08:51:52 -0500 Subject: [PATCH 2/5] cool --- src/base/fileio/tensormarket.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/base/fileio/tensormarket.jl b/src/base/fileio/tensormarket.jl index 4c2c2ae28..b35a30aa5 100644 --- a/src/base/fileio/tensormarket.jl +++ b/src/base/fileio/tensormarket.jl @@ -1,5 +1,5 @@ """ - fttxwrite(filename, tns) + fttwrite(filename, tns) Write a sparse Finch fiber to a TensorMarket file. @@ -10,7 +10,7 @@ See also: [ttwrite](http://willowahrens.io/TensorMarket.jl/stable/#TensorMarket. fttwrite(args...) = throw(FinchExtensionError("TensorMarket.jl must be loaded to use fttxwrite (hint: `using TensorMarket`)")) """ - fttxread(filename, infoonly=false, retcoord=false) + fttread(filename, infoonly=false, retcoord=false) Read the TensorMarket file into a Finch fiber. The fiber will be dense or COO depending on the format of the file. From d085dd141fae6bc85690a44ab35b19cb97dd7fe6 Mon Sep 17 00:00:00 2001 From: Willow Ahrens Date: Wed, 6 Dec 2023 08:57:54 -0500 Subject: [PATCH 3/5] messaging --- src/base/fileio/tensormarket.jl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/base/fileio/tensormarket.jl b/src/base/fileio/tensormarket.jl index b35a30aa5..07690c343 100644 --- a/src/base/fileio/tensormarket.jl +++ b/src/base/fileio/tensormarket.jl @@ -7,7 +7,7 @@ Write a sparse Finch fiber to a TensorMarket file. See also: [ttwrite](http://willowahrens.io/TensorMarket.jl/stable/#TensorMarket.ttwrite) """ -fttwrite(args...) = throw(FinchExtensionError("TensorMarket.jl must be loaded to use fttxwrite (hint: `using TensorMarket`)")) +fttwrite(args...) = throw(FinchExtensionError("TensorMarket.jl must be loaded to use write .ttx files (hint: `using TensorMarket`)")) """ fttread(filename, infoonly=false, retcoord=false) @@ -19,7 +19,7 @@ COO depending on the format of the file. See also: [ttread](http://willowahrens.io/TensorMarket.jl/stable/#TensorMarket.ttread) """ -fttread(args...) = throw(FinchExtensionError("TensorMarket.jl must be loaded to use fttxread (hint: `using TensorMarket`)")) +fttread(args...) = throw(FinchExtensionError("TensorMarket.jl must be loaded to use read .ttx files (hint: `using TensorMarket`)")) """ ftnswrite(filename, tns) @@ -34,7 +34,7 @@ Write a sparse Finch fiber to a FROSTT `.tns` file. See also: [tnswrite](http://willowahrens.io/TensorMarket.jl/stable/#TensorMarket.tnswrite) """ -ftnswrite(args...) = throw(FinchExtensionError("TensorMarket.jl must be loaded to use ftnswrite (hint: `using TensorMarket`)")) +ftnswrite(args...) = throw(FinchExtensionError("TensorMarket.jl must be loaded to write .tns files (hint: `using TensorMarket`)")) """ ftnsread(filename) @@ -49,4 +49,4 @@ Read the contents of the FROSTT `.tns` file 'filename' into a Finch COO Fiber. See also: [tnsread](http://willowahrens.io/TensorMarket.jl/stable/#TensorMarket.tnsread) """ -ftnsread() = throw(FinchExtensionError("TensorMarket.jl must be loaded to use ftnsread (hint: `using TensorMarket`)")) +ftnsread(args...) = throw(FinchExtensionError("TensorMarket.jl must be loaded to read .tns files (hint: `using TensorMarket`)")) From 17b642955f698f522caf2523564178a44ada5ea4 Mon Sep 17 00:00:00 2001 From: Willow Ahrens Date: Wed, 6 Dec 2023 08:59:06 -0500 Subject: [PATCH 4/5] error messages --- src/base/fileio/binsparse.jl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/base/fileio/binsparse.jl b/src/base/fileio/binsparse.jl index e1015a629..b906b1f05 100644 --- a/src/base/fileio/binsparse.jl +++ b/src/base/fileio/binsparse.jl @@ -254,8 +254,8 @@ struct NPYPath dirname::String end -bspwrite_h5(args...) = throw(FinchExtensionError("HDF5.jl must be loaded to write Binsparse HDF5 (hint: `using HDF5`)")) -bspwrite_bspnpy(args...) = throw(FinchExtensionError("NPZ.jl must be loaded to write Binsparse NPY (hint: `using NPZ`)")) +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") @@ -292,8 +292,8 @@ end function bspwrite_header end -bspread_h5(args...) = throw(FinchExtensionError("HDF5.jl must be loaded to read Binsparse HDF5 (hint: `using HDF5`)")) -bspread_bspnpy(args...) = throw(FinchExtensionError("NPZ.jl must be loaded to read Binsparse NPY (hint: `using NPZ`)")) +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") From 0b10a7182496f9616f58f983d199d5ec2b0d79c4 Mon Sep 17 00:00:00 2001 From: Willow Ahrens Date: Wed, 6 Dec 2023 09:01:00 -0500 Subject: [PATCH 5/5] type annotations --- ext/HDF5Ext.jl | 4 ++-- ext/NPZExt.jl | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ext/HDF5Ext.jl b/ext/HDF5Ext.jl index acdeaa567..96ec3d36e 100644 --- a/ext/HDF5Ext.jl +++ b/ext/HDF5Ext.jl @@ -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 diff --git a/ext/NPZExt.jl b/ext/NPZExt.jl index b3764e540..6360cb53d 100644 --- a/ext/NPZExt.jl +++ b/ext/NPZExt.jl @@ -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