kronenthaler / libai

4 stars 2 forks source link

Implement Octave binary `mat` format #22

Closed dktcoding closed 7 years ago

dktcoding commented 7 years ago

Here's the implementation of GNU Octave binary mat format, the good:

Some considerations (not actually good or bad):

Also, I took the liberty of change the target-source of the Netbeans project to 1.7 (since it's the minimum supported version, and It has a couple of small code advantages over 1.6).

kronenthaler commented 7 years ago

I was giving this a thought, i would like to implement something like ImageIO class. A class (factory) that allows to serialize a particular kind of object, keeping the object entirely agnostic of the different formats. For instance, a class MatrixIO, can have 2 methods, write(Matrix, format), and read(format) -> Matrix. Based on the format parameter (enum type?) a specific serializer is selected for the task. The advantages are that, the matrix class remains agnostic, no knowledge about multiple formats and more formats can be added without changing the Matrix itself.

Maybe just left in the Matrix class the toString method for debugging purposes, OpenOffice format can be also be extracted out.

Additional note: i want to integrate the project with travis-ci whenever i have time, it will allows to test it automatically, i will need to know what packages you need to install to test with octane :)

dktcoding commented 7 years ago

Sounds good, what about something like:

public class MatrixIO {
    public static enum Target {
        SERIAL, //default to jvm serialization
        CSV,
        TSV,
        OCTAVE_32,
        OCTAVE_64
    }

    public boolean write(String file, Matrix a) {}
    public boolean write(String file, Matrix a, Target t) {}
    public boolean write(String file, Map<String, Matrix> m, Target t) {
         //This one is needed (at least) for Octave since matrices need their own name
         //The other methods can have a default name, let's say 'a'
    }
}

As for packages, only octave is needed since I used built-in functions.

kronenthaler commented 7 years ago

I would just change the String file, to a OutputStream output, so we can output it on the console as well if needed. And the first method i will remove it too. I think you always should specify the type we want.

Later on we can include the read counterparts :)

On Thu, Dec 1, 2016 at 11:48 AM, Federico Vera notifications@github.com wrote:

Sounds good, what about something like:

public class MatrixIO { public static enum Target { SERIAL, //default to jvm serialization CSV, TSV, OCTAVE_32, OCTAVE_64 }

public boolean write(String file, Matrix a) {}
public boolean write(String file, Matrix a, Target t) {}
public boolean write(String file, Map<String, Matrix> m, Target t) {
     //This one is needed (at least) for Octave since matrices need their own name
     //The other methods can have a default name, let's say 'a'
}

}

As for packages, only octave is needed since I used built-in functions.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/kronenthaler/libai/pull/22#issuecomment-264140217, or mute the thread https://github.com/notifications/unsubscribe-auth/AAfVI3GMs1cIuKVcaD0CPuUjXRSRYzpxks5rDqYLgaJpZM4LBLCs .

--

.: Kronenthaler :.

kronenthaler@gmail.com | yahoo.com

dktcoding commented 7 years ago

Great! I'll send the commits later today

dktcoding commented 7 years ago

I also changed the NullPointerException to IllegalArgumentException since that's what ImageIO does now.