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

mikera.arrayz.impl.BaseShapedArray Maven / Gradle / Ivy

Go to download

Fast double-precision vector and matrix maths library for Java, supporting N-dimensional numeric arrays.

There is a newer version: 0.67.0
Show newest version
package mikera.arrayz.impl;

import mikera.arrayz.INDArray;
import mikera.vectorz.Op2;
import mikera.vectorz.util.ErrorMessages;
import mikera.vectorz.util.IntArrays;

/**
 * Abstract base class for N-dimensional arrays that use a fixed int[] shape vector.
 * 
 * Any dimensionality (including 0) is supported.
 * 
 * @author Mike
 */
public abstract class BaseShapedArray extends AbstractArray {
	private static final long serialVersionUID = -1486048632091493890L;

	protected final int[] shape;
	
	public BaseShapedArray(int [] shape) {
		this.shape=shape;
	}

	@Override
	public int dimensionality() {
		return shape.length;
	}

	@Override
	public int[] getShape() {
		return shape;
	}
	
	@Override
	public int[] getShapeClone() {
		return shape.clone();
	}

	@Override
	public int sliceCount() {
		return shape[0];
	}
	
	@Override
	public double reduce(Op2 op, double init) {
		if (shape.length==0) return op.apply(init, get());
		double result=init;
		int n=sliceCount();
		for (int i=0; i




© 2015 - 2025 Weber Informatics LLC | Privacy Policy