Hirdetés

Keresés

Új hozzászólás Aktív témák

  • axioma

    veterán

    válasz axioma #10243 üzenetére

    Na valahogy igy nez ki:
    public interface ProjMatrix<M> {
    public ProjMatrix(double[][] mtx);
    public ProjMatrix(M mtx);
    public M getUnderlying();
    public ProjMatrix add(M mtx);
    ..
    }

    Es van harom megvalositas, ebbol ketto ketretegu, az Nd4j-s hasonlo ehhez:
    public class ApacheMatrix implements ProjMatrix<RealMatrix> {
    private final RealMatrix underlying;
    public ApacheMatrix(double[][] mtx){... underlying=new RealMatrix(mtx); ...}
    public ApacheMatrix(RealMatrix mtx){ underlying=mtx; }
    public RealMatrix getUnderlying() { return underlying; }
    public ApacheMatrix add(RealMatrix other) { return new ApacheMatrix(underlying.add(other.getUnderlying());}
    ...

    Es en csinalnek egy ilyet:
    public class FlatMatrix implements ProjMatrix<FlatMatrix> {
    private final double[] data;
    private final dataLen;
    ... // segedvaltozok
    public FlatMatrix(double[][] mtx) { ....dataLen=...; data=new double[dataLen]; ...}
    public FlatMatrix getUnderlying() { return this;}
    public FlatMatrix add(FlatMatrix other) { ... }
    ...

    Persze ebben az esetben az underlying-gal nem lehet "szepen" konstrualni, az tulkepp egy masolas lesz, de ennek nem lenne jelentosege.
    Csak fejbol kb. a lenyeg, lehet benne egyeb hiba, nem az szamit, hanem a konstrukcio osszessegeben mehet-e igy minden gond nelkul.

    Kosz!

Új hozzászólás Aktív témák