<commit_before>/**
 *
 */
package ca.eandb.jmist.util.matlab;

import java.io.IOException;
import java.io.OutputStream;

import ca.eandb.jmist.math.Complex;

/**
 * Convenience class for writing array variables to a
 * <code>MatlabOutputStream</code>.
 * @author <NAME>
 */
public final class MatlabWriter {

	/**
	 * Creates a new <code>MatlabWriter</code>.
	 * @param out The <code>OutputStream</code> to write to.
	 * @throws IOException if writing to <code>out</code> fails.
	 */
	public MatlabWriter(OutputStream out) throws IOException {
		this(new MatlabOutputStream(out));
	}

	/**
	 * Creates a new <code>MatlabWriter</code>.
	 * @param out The <code>MatlabOutputStream</code> to write to.
	 * @throws IOException if writing to <code>out</code> fails.
	 */
	public MatlabWriter(MatlabOutputStream out) throws IOException {
		this.out = out;
	}

	/**
	 * Flushes the underlying stream.
	 * @throws IOException if writing to the underlying stream fails.
	 */
	public void flush() throws IOException {
		this.out.flush();
	}

	/**
	 * Closes the underlying stream.
	 * @throws IOException if closing the stream fails.
	 */
	public void close() throws IOException {
		this.out.close();
	}

	/**
	 * Writes a <code>double</code> array variable to the MAT-file.
	 * @param name The name of the variable.
	 * @param pr The real parts of the array elements.
	 * @param pi The imaginary parts of the array elements (optional, must
	 * 		be the same length as <code>pr</code> if provided).
	 * @param dimensions The array dimensions (there must be at least two
	 * 		dimensions and the product of the dimensions must be
	 * 		<code>pr.length</code>).
	 * @throws IOException if writing to the underlying stream fails.<commit_msg>Added convenience methods to MatlabWriter to write a one dimensional array without having to provide the dimensions explicitly.<commit_after>/**
 *
 */
package ca.eandb.jmist.util.matlab;

import java.io.IOException;
import java.io.OutputStream;

import ca.eandb.jmist.math.Complex;

/**
 * Convenience class for writing array variables to a
 * <code>MatlabOutputStream</code>.
 * @author <NAME>
 */
public final class MatlabWriter {

	/**
	 * Creates a new <code>MatlabWriter</code>.
	 * @param out The <code>OutputStream</code> to write to.
	 * @throws IOException if writing to <code>out</code> fails.
	 */
	public MatlabWriter(OutputStream out) throws IOException {
		this(new MatlabOutputStream(out));
	}

	/**
	 * Creates a new <code>MatlabWriter</code>.
	 * @param out The <code>MatlabOutputStream</code> to write to.
	 * @throws IOException if writing to <code>out</code> fails.
	 */
	public MatlabWriter(MatlabOutputStream out) throws IOException {
		this.out = out;
	}

	/**
	 * Flushes the underlying stream.
	 * @throws IOException if writing to the underlying stream fails.
	 */
	public void flush() throws IOException {
		this.out.flush();
	}

	/**
	 * Closes the underlying stream.
	 * @throws IOException if closing the stream fails.
	 */
	public void close() throws IOException {
		this.out.close();
	}
	
	/**
	 * Writes a one-dimensional array of <code>double</code>s to the MAT-file.
	 * @param name The name of the variable.
	 * @param pr The array of elements to write.
	 * @throws IOException If writing to the underlying stream fails.
	 */
	public void write(String name, double[] pr) throws IOException {
		write(name, pr, new int[]{ pr.length, 1 });
	}
	
	/**
	 * Writes a one-dimensional array of <code>float</code>s to the MAT-file.
	 * @param name The name of the variable.
	 * @param pr The array of elements to write.
	 * @throws IOException If writing to the underlying stream fails.
	 */
	public void write(String name, float[] pr) throws IOException {
		write(name, pr, new int[]{ pr.length, 1 });		
	}
	
	/**
	 * Writes a one-dimensional array of <code>boolean</code>s to the MAT-file.
	 * @param name The name of the variable.
	 * @param pr The array of elements to write.
	 * @throws IOException If writing to the underlying stream fails.
	 */
	public void write(String name, boolean[] pr) throws IOException {
		write(name, pr, new int[]{ pr.length, 1 });				
	}
	
	/**
	 * Writes a one-dimensional array of <code>int</code>s to the MAT-file.
	 * @param name The name of the variable.
	 * @param pr The array of elements to write.
	 * @throws IOException If writing to the underlying stream fails.
	 */
	public void write(String name, int[] pr) throws IOException {
		write(name, pr, new int[]{ pr.length, 1 });
	}
	
	/**
	 * Writes a one-dimensional array of <code>short</code>s to the MAT-file.
	 * @param name The name of the variable.
	 * @param pr The array of elements to write.
	 * @throws IOException If writing to the underlying stream fails.
	 */
	public void write(String name, short[] pr) throws IOException {
		write(name, pr, new int[]{ pr.length, 1 });
	}
	
	/**
	 * Writes a one-dimensional array of <code>byte</code>s to the MAT-file.
	 * @param name The name of the variable.
	 * @param pr The array of elements to write.
	 * @throws IOException If writing to the underlying stream fails.
	 */
	public void write(String name, byte[] pr) throws IOException {
		write(name, pr, new int[]{ pr.length, 1 });
	}
	
	/**
	 * Writes a one-dimensional array of <code>int</code>s to the MAT-file.
	 * @param name The name of the variable.
	 * @param pr The array of elements to write.
	 * @throws IOException If writing to the underlying stream fails.
	 */
	public void writeUnsigned(String name, int[] pr) throws IOException {
		writeUnsigned(name, pr, new int[]{ pr.length, 1 });
	}
	
	/**
	 * Writes a one-dimensional array of <code>short</code>s to the MAT-file.
	 * @param name The name of the variable.
	 * @param pr The array of elements to write.
	 * @throws IOException If writing to the underlying stream fails.
	 */
	public void writeUnsigned(String name, short[] pr) throws IOException {
		writeUnsigned(name, pr, new int[]{ pr.length, 1 });
	}
	
	/**
	 * Writes a one-dimensional array of <code>byte</code>s to the MAT-file.
	 * @param name The name of the variable.
	 * @param pr The array of elements to write.
	 * @throws IOException If writing to the underlying stream fails.
	 */
	public void writeUnsigned(String name, byte[] pr) throws IOException {
		writeUnsigned(name, pr, new int[]{ pr.length, 1 });
	}

	/**
	 * Writes a <code>double</code> array variable to the MAT-file.
	 * @param name The name of the variable.
	 * @param pr The real parts of the array elements.
	 * @param pi The imaginary parts of the array elements (optional, must
	 * 		be the same length as <code>pr</code> if provided).
	 * @param dimensions The array dimensions (there must be at least two
	 * 		dimensions and the product of the dimensions must be
	 * 		<code>pr.length</code>).
	 * @throws IOException if writing to the underlying stream fails.
{'fraction_non_alphanumeric': 0.11228378774552918, 'fraction_numerical': 0.0013192612137203166, 'mean_word_length': 3.494729907773386, 'pattern_counts': {'":': 0, '<': 63, '<?xml version=': 0, '>': 63, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5005040', 'n_tokens_mistral': 2100, 'n_tokens_neox': 1927, 'n_words': 805}