Difference between revisions of "Slices"

From CSE231 Wiki
Jump to navigation Jump to search
Line 73: Line 73:
 
use: [https://www.cse.wustl.edu/~cosgroved/courses/cse231/current/apidocs/slice/core/Slice.html class Slice]
 
use: [https://www.cse.wustl.edu/~cosgroved/courses/cse231/current/apidocs/slice/core/Slice.html class Slice]
  
This class has everything you need for [[Nucleobase_Counting#Coarsening_N-Way_Split n-way split] problems, specifically: [https://www.cse.wustl.edu/~cosgroved/courses/cse231/current/apidocs/slice/core/Slice.html#getSliceIndexId-- getSliceIndexId()], [https://www.cse.wustl.edu/~cosgroved/courses/cse231/current/apidocs/slice/core/Slice.html#getMinInclusive-- getMinInclusive()], and [https://www.cse.wustl.edu/~cosgroved/courses/cse231/current/apidocs/slice/core/Slice.html#getMaxExclusive-- getMaxExclusive()].
+
This class has everything you need for [[Nucleobase_Counting#Coarsening_N-Way_Split|n-way split]] problems, specifically: [https://www.cse.wustl.edu/~cosgroved/courses/cse231/current/apidocs/slice/core/Slice.html#getSliceIndexId-- getSliceIndexId()], [https://www.cse.wustl.edu/~cosgroved/courses/cse231/current/apidocs/slice/core/Slice.html#getMinInclusive-- getMinInclusive()], and [https://www.cse.wustl.edu/~cosgroved/courses/cse231/current/apidocs/slice/core/Slice.html#getMaxExclusive-- getMaxExclusive()].
  
[https://www.cse.wustl.edu/~cosgroved/courses/cse231/current/apidocs/slice/core/Slice.html#getOriginalUnslicedData-- getOriginalUnslicedData()] is not necessary until the [[https://classes.engineering.wustl.edu/cse231/core/index.php?title=K-MerCounting_Assignment K-Mer Counting Lab]]
+
[https://www.cse.wustl.edu/~cosgroved/courses/cse231/current/apidocs/slice/core/Slice.html#getOriginalUnslicedData-- getOriginalUnslicedData()] is not necessary until the [[K-MerCounting_Assignment|K-Mer Counting Lab]]
  
 
=Testing Your Solution=
 
=Testing Your Solution=
 
==Correctness==
 
==Correctness==
 
{{TestSuite|SlicesTestSuite|slice.studio}}
 
{{TestSuite|SlicesTestSuite|slice.studio}}

Revision as of 04:25, 22 January 2018

Motivation

Coarsening, or n-way split as we tend to call it in this course, comes up a fair amount. This studio has you implement a utility that you can use over and over throughout the semester.

In order to support future testing well, we are strict about exactly how the data is split up among the slices.

Code to Implement

class: Slices.java Java.png
methods: createNSlicesForArrayObject
package: slices.studio
source folder: student/src/main/java

createNSlicesForArrayObject

In order to support primitive arrays (e.g. byte[], int[], et cetera) and non-primitive arrays (e.g. Object[]) we provide all of the public methods, each which simply call the single method requiring implementation:

method: createNSlicesForArrayObject Sequential.svg (sequential implementation only)

	public static <T> List<Slice<T[]>> createNSlices(T[] data, int numSlices) {
		return createNSlicesForArrayObject(data, numSlices);
	}
	public static List<Slice<byte[]>> createNSlices(byte[] data, int numSlices) {
		return createNSlicesForArrayObject(data, numSlices);
	}
	public static List<Slice<char[]>> createNSlices(char[] data, int numSlices) {
		return createNSlicesForArrayObject(data, numSlices);
	}
	public static List<Slice<short[]>> createNSlices(short[] data, int numSlices) {
		return createNSlicesForArrayObject(data, numSlices);
	}
	public static List<Slice<int[]>> createNSlices(int[] data, int numSlices) {
		return createNSlicesForArrayObject(data, numSlices);
	}
	public static List<Slice<long[]>> createNSlices(long[] data, int numSlices) {
		return createNSlicesForArrayObject(data, numSlices);
	}
	public static List<Slice<float[]>> createNSlices(float[] data, int numSlices) {
		return createNSlicesForArrayObject(data, numSlices);
	}
	public static List<Slice<double[]>> createNSlices(double[] data, int numSlices) {
		return createNSlicesForArrayObject(data, numSlices);
	}

To pull this off we will need to use the Array.getLength(Object) method.

Strict Specification

We are overly strict about the specification of how the data must be sliced up. This is to allow to accurately compare results intermediate results throughout the semester.

Example: array.length=7; numSlices=4

Distribute the remainder 1 each to the lower end slices.

A A B B C C D
Attention niels epting.svg Warning:Do NOT slice up the data by giving all of the remainder to one slice

A |B |C |D |D |D |D

Mistakes To Avoid

Attention niels epting.svg Warning: Do NOT Parallelize
Attention niels epting.svg Warning: Do NOT Copy The Data Into SubArrays

class Slice<T>

use: class Slice

This class has everything you need for n-way split problems, specifically: getSliceIndexId(), getMinInclusive(), and getMaxExclusive().

getOriginalUnslicedData() is not necessary until the K-Mer Counting Lab

Testing Your Solution

Correctness

class: SlicesTestSuite.java Junit.png
package: slice.studio
source folder: testing/src/test/java