Comments (11)
I think you're looking for a custom serializer: https://github.com/JuliaIO/JLD.jl/blob/master/doc/jld.md#custom-serialization. You can define JLD.readas
and JLD.writeas
methods for your types in your packages. (That makes JLD a dependency, of course.)
Since I don't think this is a FileIO issue, I'm closing this (but if you disagree, I can reopen).
from fileio.jl.
Thanks,
This is more/less what I was looking for. I had missed that part in the docs... There still might be a small relation to FileIO: In the documented example, an obj2 = load(filename)
will still result in an object of type MyVectors5Serializer
, so the FileIO magic goes as far as running JLD.jldopen()
I suppose, but not the associated JLD.readas()
. At least, this is what happened for my type. Is this right?
Would there be a way of cascading the FileIO magic to readas
?
from fileio.jl.
There still might be a small relation to FileIO: In the documented example, an obj2 = load(filename) will still result in an object of type MyVectors5Serializer
It shouldn't, if the package that defines the readas
method has been loaded. If you can observe this behavior in a reproducible example, then it's a bug that should be filed to JLD.jl.
from fileio.jl.
Relevant to the previous point: see also the part in the docs about addrequire
.
from fileio.jl.
Yes, thanks, I did have the addrequire
in the jldopen(filename, "w") do ... end
in my test. But perhaps the test didn't result in the right result because of module-reloading issues. I'll try to do a clean test now
from fileio.jl.
Ah---I found the reason why it just does not exactly what I want, and why I was looking for a FileIO solution.
In the documented example, things work if I say something like
obj4 = FileIO.load(filename, "somedata")
but what I was looking for was a way to be able to say
obj3 = FileIO.load(filename)
which would need additional magic that files that require MyModule
and have as a root dataset "somedata"
(a better name would be MyVector5
in such a case).
The parallel with FileIO would be that most standard formats have "unnamed" objects as well, e.g., :WAV
just has the audio. I am looking for a way to save objects from my types in a JLD container, namelessly.
from fileio.jl.
You'd probably need to define a new file extension, and most likely give it a special magic #.
from fileio.jl.
Is there a way to add additional magic after string(magic_base, f.version)
in JLD, so that the file will be both :JLD
and the special :MyVector5
file type? I assume I can always re-write the header by hand.
This is assuming that FileIO will go for the longer magic match.
from fileio.jl.
I don't think that FileIO can (in the central repository) reasonably support "custom JLD content" as separate file types; after all, there are an infinite number of possible combinations of variable names, types, etc., and so you might define 3 different ones, I might define 5 different ones, etc. Only if there is some standard in widespread use would we consider such a thing.
However, of course you can add this locally. But perhaps an easier option would be to write a function called myload
which checks to see if it's a JLD file and, if so, asks whether the content is one of your "standard" formats. If not, myload
can call load
.
from fileio.jl.
Yes, that makes sense.
It is funny, though, that I tend to save objects (GaussianMixtures.GMM
, IVectors.IExtractor
) in a JLD under their type name. Another interface that appears to make sense is load(file, ::Type)
, because in the code that calls load
you usually know what the resulting type should be. This makes it a little more explicit.
from fileio.jl.
Right, but other people might save 20 different objects of the same type to a single file, using a different pathname for each.
from fileio.jl.
Related Issues (20)
- The 1.6 update seems to have broken load from URLs for CSVFiles
- Saving output to txt/CSV file? HOT 1
- Proposal: FileIO.save keyword argument syntax (FileIO.kwsave ?) HOT 3
- FIle collision on case sensitive file systems after recent release.
- House AVSfldIO.jl under JulioIO ? HOT 9
- FileIO is not threadsafe HOT 4
- Error in magic function detect_rdata HOT 4
- There was an error in magic function detect_rdata_single HOT 5
- No applicable_loaders found for UNKNOWN HOT 3
- RData can't load .rda files with [email protected] but can with [email protected] HOT 2
- Confusing error when saving the wrong thing
- AstroIO required when it shouldn't be HOT 5
- Too many open files HOT 4
- FileIO not loading / requiring dependency AVSfldIO properly HOT 2
- @maybe macro
- registering zarr files HOT 1
- register Matlab's .mat HOT 1
- Incorrectly export GIF image
- Unhelpful output `#27 (generic function with 1 method)` HOT 2
- [FR] suppert for .webp format HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fileio.jl.