Пример #1
0
void VectorMatrix::normalize(const Matrix &len)
{
	if (isUniform() && len.isUniform()) {
		Vector3d uni = getUniformValue();
		uni.normalize(len.getUniformValue());
		fill(uni);
	} else {
		const int dev = computeStrategy2(len);
		writeLock(dev); len.readLock(dev);
		getDevice(dev)->normalize3(getArray(dev, 0), getArray(dev, 1), getArray(dev, 2), len.getArray(dev));
		len.readUnlock(dev); writeUnlock(dev); 
	}
}
Пример #2
0
void VectorMatrix::assign(const VectorMatrix &op)
{
	if (this == &op) {
		return;
	} else if (op.isUniform()) {
		fill(op.getUniformValue());
	} else {
		const int dev = computeStrategy2(op);
		writeLock(dev); op.readLock(dev);
		for (int c=0; c<num_arrays; ++c) {
			matty::getDevice(dev)->assign(getArray(dev, c), op.getArray(dev, c));
		}
		writeUnlock(dev); op.readUnlock(dev);
	}
}
Пример #3
0
void VectorMatrix::add(const VectorMatrix &op, double factor)
{
	if (this == &op) {
		scale(1.0 + factor);
	} else if (isUniform() && op.isUniform()) {
		fill(getUniformValue() + op.getUniformValue() * factor);
	} else {
		const int dev = computeStrategy2(op);
		writeLock(dev); op.readLock(dev);
		for (int c=0; c<num_arrays; ++c) {
			matty::getDevice(dev)->add(getArray(dev, c), op.getArray(dev, c), factor);
		}
		writeUnlock(dev); op.readUnlock(dev);
	}
}
Пример #4
0
void Matrix::assign(const Matrix &op)
{
    if (this == &op) {
        return;
    } else if (op.isUniform()) {
        fill(op.getUniformValue());
    } else {
        const int dev = computeStrategy2(op);
        writeLock(dev);
        op.readLock(dev);
        matty::getDevice(dev)->assign(getArray(dev), op.getArray(dev));
        writeUnlock(dev);
        op.readUnlock(dev);
    }
}
Пример #5
0
void Matrix::divide(const Matrix &op)
{
    if (this == &op) {
        assert(0);
    } else if (op.isUniform()) {
        scale(1.0 / op.getUniformValue());
    } else {
        const int dev = computeStrategy2(op);
        writeLock(dev);
        op.readLock(dev);
        matty::getDevice(dev)->divide(getArray(dev), op.getArray(dev));
        writeUnlock(dev);
        op.readUnlock(dev);
    }
}
Пример #6
0
double VectorMatrix::dotSum(const VectorMatrix &other) const
{
	if (isUniform() && other.isUniform()) {
		const double x = uval[0], y = uval[1], z = uval[2];
		const double dot = x*x + y*y + z*z;
		return size() * dot;
	} else {
		const int dev = computeStrategy2(other);
		readLock(dev); if (this != &other) other.readLock(dev);
		const double sum = matty::getDevice(dev)->sumdot3(
			this->getArray(dev, 0), this->getArray(dev, 1), this->getArray(dev, 2),
			other.getArray(dev, 0), other.getArray(dev, 1), other.getArray(dev, 2)
		);
		if (this != &other) other.readUnlock(dev); readUnlock(dev);
		return sum;
	}
}