Ejemplo n.º 1
0
/*! \relates XsVector
	\brief Initialize the XsVector using \a sz number of items from \a src
	\param sz The desired size of the vector
	\param src 0 or a pointer to a buffer containing \a sz items to copy into the %XsVector
*/
void XsVector_assign(XsVector* thisPtr, XsSize sz, const XsReal* src)
{
	if (thisPtr->m_flags == XSDF_FixedSize)
	{
		if (sz == 0)
		{
			*((int*) &thisPtr->m_flags) |= XSDF_Empty;
			return;
		}
		assert(sz == thisPtr->m_size);
		*((int*) &thisPtr->m_flags) &= ~XSDF_Empty;
	}

	if (sz > thisPtr->m_size || sz == 0)
	{
		XsVector_destruct(thisPtr);
		if (sz)
		{
			// init to size
			XsReal* data = (XsReal*) xsMathMalloc(sz*sizeof(XsReal));
			assert(data);
			*((XsReal**) &thisPtr->m_data) = data;
			*((int*) &thisPtr->m_flags) = XSDF_Managed;
			INC_ALLOC();
		}
	}
	*((XsSize*) &thisPtr->m_size) = sz;
	if (src && sz)
		memcpy(thisPtr->m_data, src, sz*sizeof(XsReal));
}
Ejemplo n.º 2
0
/*! \relates XsMatrix \brief Init the %XsMatrix and copy the data from \a src into the matrix if \a src is not null */
void XsMatrix_construct(XsMatrix* thisPtr, XsSize rows, XsSize cols, XsSize stride, const XsReal* src, XsSize srcStride)
{
	XsSize r,c;
	XsSize size = rows*stride;

	if (stride == 0)
	{
		stride = cols;
		size = rows * stride;
	}
	if (size)
	{
		// init to size
		*((XsReal**) &thisPtr->m_data) = (XsReal*) xsMathMalloc(size*sizeof(XsReal));
		INC_ALLOC();
	}
	else
		*((XsReal**) &thisPtr->m_data) = 0;
	*((int*) &thisPtr->m_flags) = XSDF_Managed;
	*((XsSize*) &thisPtr->m_rows) = rows;
	*((XsSize*) &thisPtr->m_cols) = cols;
	*((XsSize*) &thisPtr->m_stride) = stride;

	if (src && size)
	{
		if (srcStride == 0 || srcStride == stride)
			memcpy(thisPtr->m_data, src, size*sizeof(XsReal));
		else
		{
			for (r = 0; r < rows; ++r)
				for (c = 0; c < cols; ++c)
					thisPtr->m_data[r*stride+c] = src[r*srcStride + c];
		}
	}
}
Ejemplo n.º 3
0
//! \relates XsVector \brief Initialize the %XsVector using \a sz number of items from \a src
void XsVector_construct(XsVector* thisPtr, XsSize sz, const XsReal* src)
{
	if (sz)
	{
		// init to size
		*((XsReal**) &thisPtr->m_data) = (XsReal*) xsMathMalloc(sz*sizeof(XsReal));
		INC_ALLOC();
	}
	else
		*((XsReal**) &thisPtr->m_data) = 0;
	*((int*) &thisPtr->m_flags) = XSDF_Managed;
	*((XsSize*) &thisPtr->m_size) = sz;
	if (src && sz)
		memcpy(thisPtr->m_data, src, sz*sizeof(XsReal));
}
Ejemplo n.º 4
0
/*! \relates XsMatrix \brief Init the %XsMatrix and copy the data from \a src into the matrix if \a src is not null */
void XsMatrix_assign(XsMatrix* thisPtr, XsSize rows, XsSize cols, XsSize stride, const XsReal* src, XsSize srcStride)
{
	XsSize r,c;
	XsSize size = rows*stride;

	if (thisPtr->m_flags & XSDF_FixedSize)
	{
		if (rows == 0 && cols == 0)
		{
			*((int*) &thisPtr->m_flags) |= XSDF_Empty;
			return;
		}

		assert(thisPtr->m_rows == rows && thisPtr->m_cols == cols);
		stride = thisPtr->m_stride;
		size = thisPtr->m_rows * stride;
		*((int*) &thisPtr->m_flags) &= ~XSDF_Empty;
	}
	else
	{
		if (thisPtr->m_rows == rows && thisPtr->m_cols == cols &&
			(stride == 0 || stride == thisPtr->m_stride))
		{
			stride = thisPtr->m_stride;
			size = rows * stride;
		}
		else
		{
			if (stride == 0)
			{
				stride = cols;
				size = rows * stride;
			}
			if (size > thisPtr->m_rows*thisPtr->m_stride || thisPtr->m_rows == 0)
			{
				XsMatrix_destruct(thisPtr);
				if (size)
				{
					// init to size
					*((XsReal**) &thisPtr->m_data) = (XsReal*) xsMathMalloc(size*sizeof(XsReal));
					*((int*) &thisPtr->m_flags) = XSDF_Managed;
					INC_ALLOC();
				}
			}
			*((XsSize*) &thisPtr->m_rows) = rows;
			*((XsSize*) &thisPtr->m_cols) = cols;
			*((XsSize*) &thisPtr->m_stride) = stride;
		}
	}
	if (src && size)
	{
		if (srcStride == 0 || srcStride == stride)
			memcpy(thisPtr->m_data, src, size*sizeof(XsReal));
		else
		{
			for (r = 0; r < rows; ++r)
				for (c = 0; c < cols; ++c)
					thisPtr->m_data[r*stride+c] = src[r*srcStride + c];
		}
	}
}