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

org.nd4j.context.Nd4jContext Maven / Gradle / Ivy

There is a newer version: 1.0.0-beta6
Show newest version
package org.nd4j.context;

import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
import java.util.Properties;

/**
 * Holds properties for nd4j to be used
 * across different modules
 *
 * @author Adam Gibson
 */
public class Nd4jContext implements Serializable {
    private  Properties conf;
    private static Nd4jContext INSTANCE;

    private Nd4jContext() {}

    public static Nd4jContext getInstance() {
        if(INSTANCE == null)
            INSTANCE = new Nd4jContext();
        return INSTANCE;
    }

    /**
     * Load the properties
     * from an input stream
     * @param inputStream
     */
    public void updateProperties(InputStream inputStream) {
        if(conf == null) {
            conf = new Properties();
            conf.putAll(System.getProperties());
        }

        try {
            String dType = conf.getProperty("dtype");
            conf.load(inputStream);
            if (dType != null)
                conf.put("dtype", dType);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * Get the configuration for nd4j
     * @return
     */
    public  Properties getConf() {
        if(conf == null) {
            conf = new Properties();
            conf.putAll(System.getProperties());
        }

        return conf;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy