All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jdplus.sa.base.csv.DoubleArray Maven / Gradle / Ivy

There is a newer version: 3.3.0
Show newest version
/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
 */
package jdplus.sa.base.csv;

import jdplus.toolkit.base.api.data.DoubleSeq;
import jdplus.toolkit.base.api.math.matrices.Matrix;

/**
 *
 * @author PALATEJ
 */
@lombok.Value
public class DoubleArray {
    
    private static final DoubleArray EMPTY=new DoubleArray(new int[0], DoubleSeq.EMPTYARRAY);
    
    @lombok.NonNull
    int[] dimensions;
    @lombok.NonNull
    double[] data;
    
    public boolean isEmpty(){
        return dimensions.length == 0;
    }
    
    public static DoubleArray of(DoubleSeq d){
        if (d == null || d.isEmpty())
            return empty();
        return new DoubleArray(new int[]{d.length()}, d.toArray());
    }
    
   public static DoubleArray of(double[] d){
        if (d == null || d.length == 0)
            return empty();
        return new DoubleArray(new int[]{d.length}, d);
    }

   public static DoubleArray of(Matrix m){
        if (m == null || m.isEmpty())
            return empty();
        return new DoubleArray(new int[]{m.getRowsCount(), m.getColumnsCount()}, m.toArray());
    }

    public static DoubleArray empty(){
        return EMPTY;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy