Beispiel #1
0
void Matrix::randomize()
{
    const int dev = computeStrategy1();
    writeLock(dev);
    matty::getDevice(dev)->randomize(getArray(dev));
    writeUnlock(dev);
}
void VectorMatrix::randomize()
{
	const int dev = computeStrategy1();
	writeLock(dev);
	for (int c=0; c<num_arrays; ++c) {
		matty::getDevice(dev)->randomize(getArray(dev, c));
	}
	writeUnlock(dev);
}
Beispiel #3
0
double Matrix::average() const
{
    if (isUniform()) {
        return getUniformValue();
    } else {
        const int dev = computeStrategy1();
        readLock(dev);
        const double avg = matty::getDevice(dev)->average(getArray(dev));
        readUnlock(dev);
        return avg;
    }
}
Beispiel #4
0
double Matrix::sum() const
{
    if (isUniform()) {
        return getUniformValue() * getShape().getNumEl();
    } else {
        const int dev = computeStrategy1();
        readLock(dev);
        const double sum = matty::getDevice(dev)->sum(getArray(dev));
        readUnlock(dev);
        return sum;
    }
}
Beispiel #5
0
double Matrix::minimum() const
{
    if (isUniform()) {
        return getUniformValue();
    } else {
        const int dev = computeStrategy1();
        readLock(dev);
        const double min = matty::getDevice(dev)->minimum(getArray(dev));
        readUnlock(dev);
        return min;
    }
}
void VectorMatrix::normalize(double len)
{
	if (isUniform()) {
		Vector3d uni = getUniformValue();
		uni.normalize(len);
		fill(uni);
	} else {
		const int dev = computeStrategy1();
		writeLock(dev); 
		getDevice(dev)->normalize3(getArray(dev, 0), getArray(dev, 1), getArray(dev, 2), len);
		writeUnlock(dev); 
	}
}
Beispiel #7
0
void Matrix::scale(double factor)
{
    if (factor == 0.0) {
        fill(0.0);
    } else if (isUniform()) {
        fill(getUniformValue() * factor);
    } else {
        const int dev = computeStrategy1();
        readLock(dev);
        matty::getDevice(dev)->scale(getArray(dev), factor);
        readUnlock(dev);
    }
}
double VectorMatrix::absMax() const
{
	if (isUniform()) {
		const double x = uval[0], y = uval[1], z = uval[2];
		return std::sqrt(x*x+y*y+z*z);
	} else {
		const int dev = computeStrategy1();
		readLock(dev); 
		const double max = matty::getDevice(dev)->absmax3(
			this->getArray(dev, 0), this->getArray(dev, 1), this->getArray(dev, 2)
		);
		readUnlock(dev);
		return max;
	}
}
void VectorMatrix::scale(double factor)
{
	if (factor == 0.0) {
		fill(Vector3d(0.0, 0.0, 0.0));
	} else if (isUniform()) {
		fill(getUniformValue() * factor);
	} else {
		const int dev = computeStrategy1();
		readLock(dev);
		for (int c=0; c<num_arrays; ++c) {
			matty::getDevice(dev)->scale(getArray(dev, c), factor);
		}
		readUnlock(dev);
	}
}
Vector3d VectorMatrix::average() const
{
	if (isUniform()) {
		return getUniformValue();
	} else {
		const int dev = computeStrategy1();
		readLock(dev);
		const Vector3d avg(
			matty::getDevice(dev)->average(getArray(dev, 0)),
			matty::getDevice(dev)->average(getArray(dev, 1)),
			matty::getDevice(dev)->average(getArray(dev, 2))
		);
		readUnlock(dev);
		return avg;
	}
}
Vector3d VectorMatrix::maximum() const
{
	if (isUniform()) {
		return getUniformValue();
	} else {
		const int dev = computeStrategy1();
		readLock(dev);
		const Vector3d max(
			matty::getDevice(dev)->maximum(getArray(dev, 0)),
			matty::getDevice(dev)->maximum(getArray(dev, 1)),
			matty::getDevice(dev)->maximum(getArray(dev, 2))
		);
		readUnlock(dev);
		return max;
	}
}
void VectorMatrix::scale(const Vector3d &factors)
{
	if (factors == Vector3d(0.0, 0.0, 0.0)) {
		fill(Vector3d(0.0, 0.0, 0.0));
	} else if (isUniform()) {
		const Vector3d uni = getUniformValue();
		fill(Vector3d(uni.x*factors.x, uni.y*factors.y, uni.z*factors.z));
	} else {
		const int dev = computeStrategy1();
		readLock(dev);
		matty::getDevice(dev)->scale(getArray(dev, 0), factors.x);
		matty::getDevice(dev)->scale(getArray(dev, 1), factors.y);
		matty::getDevice(dev)->scale(getArray(dev, 2), factors.z);
		readUnlock(dev);
	}
}
Vector3d VectorMatrix::sum() const
{
	if (isUniform()) {
		return getUniformValue() * getShape().getNumEl();
	} else {
		const int dev = computeStrategy1();
		readLock(dev);
		
		const Vector3d sum(
			matty::getDevice(dev)->sum(getArray(dev, 0)),
			matty::getDevice(dev)->sum(getArray(dev, 1)),
			matty::getDevice(dev)->sum(getArray(dev, 2))
		);
		readUnlock(dev);
		return sum;
	}
}