Example #1
0
static void testInvert() {
	Matrix matrix;
	
	matrix = Matrix_inverted(MATRIX_IDENTITY);
	assertMatrixApproximate(matrix, 1.0f, 0.0f, 0.0f, 0.0f,
	                                0.0f, 1.0f, 0.0f, 0.0f,
	                                0.0f, 0.0f, 1.0f, 0.0f,
	                                0.0f, 0.0f, 0.0f, 1.0f, EPSILON);
	
	matrix = Matrix_inverted(Matrix_init(0.0f, 0.0f, 2.0f, 2.0f,
	                                     2.0f, 0.0f, 0.0f, 3.0f,
	                                     0.0f, 2.0f, 0.0f, 1.0f,
	                                     0.0f, 0.0f, 0.0f, 1.0f));
	assertMatrixApproximate(matrix, 0.0f, 0.5f, 0.0f, -1.5f,
	                                0.0f, 0.0f, 0.5f, -0.5f,
	                                0.5f, 0.0f, 0.0f, -1.0f,
	                                0.0f, 0.0f, 0.0f,  1.0f, EPSILON);
	
	matrix = MATRIX_IDENTITY;
	Matrix_invert(&matrix);
	assertMatrixApproximate(matrix, 1.0f, 0.0f, 0.0f, 0.0f,
	                                0.0f, 1.0f, 0.0f, 0.0f,
	                                0.0f, 0.0f, 1.0f, 0.0f,
	                                0.0f, 0.0f, 0.0f, 1.0f, EPSILON);
	
	matrix = Matrix_init(0.0f, 0.0f, 2.0f, 2.0f,
	                     2.0f, 0.0f, 0.0f, 3.0f,
	                     0.0f, 2.0f, 0.0f, 1.0f,
	                     0.0f, 0.0f, 0.0f, 1.0f);
	Matrix_invert(&matrix);
	assertMatrixApproximate(matrix, 0.0f, 0.5f, 0.0f, -1.5f,
	                                0.0f, 0.0f, 0.5f, -0.5f,
	                                0.5f, 0.0f, 0.0f, -1.0f,
	                                0.0f, 0.0f, 0.0f,  1.0f, EPSILON);
}
Example #2
0
static void testInvert() {
	Matrix matrix;
	
	matrix = Matrix_inverted(Matrix_identity());
	assertMatrixApproximate(matrix, 1.0f, 0.0f, 0.0f, 0.0f,
	                                0.0f, 1.0f, 0.0f, 0.0f,
	                                0.0f, 0.0f, 1.0f, 0.0f,
	                                0.0f, 0.0f, 0.0f, 1.0f, EPSILON);
	
	matrix = Matrix_inverted(Matrix_init(0.0f, 0.0f, 2.0f, 2.0f,
	                                     2.0f, 0.0f, 0.0f, 3.0f,
	                                     0.0f, 2.0f, 0.0f, 1.0f,
	                                     0.0f, 0.0f, 0.0f, 1.0f));
	assertMatrixApproximate(matrix, 0.0f, 0.5f, 0.0f, -1.5f,
	                                0.0f, 0.0f, 0.5f, -0.5f,
	                                0.5f, 0.0f, 0.0f, -1.0f,
	                                0.0f, 0.0f, 0.0f,  1.0f, EPSILON);
	
	matrix = Matrix_identity();
	Matrix_invert(&matrix);
	assertMatrixApproximate(matrix, 1.0f, 0.0f, 0.0f, 0.0f,
	                                0.0f, 1.0f, 0.0f, 0.0f,
	                                0.0f, 0.0f, 1.0f, 0.0f,
	                                0.0f, 0.0f, 0.0f, 1.0f, EPSILON);
	
	matrix = Matrix_init(0.0f, 0.0f, 2.0f, 2.0f,
	                     2.0f, 0.0f, 0.0f, 3.0f,
	                     0.0f, 2.0f, 0.0f, 1.0f,
	                     0.0f, 0.0f, 0.0f, 1.0f);
	Matrix_invert(&matrix);
	assertMatrixApproximate(matrix, 0.0f, 0.5f, 0.0f, -1.5f,
	                                0.0f, 0.0f, 0.5f, -0.5f,
	                                0.5f, 0.0f, 0.0f, -1.0f,
	                                0.0f, 0.0f, 0.0f,  1.0f, EPSILON);
}
Example #3
0
/* ************************************************************************ */
static
void
allocateMatrices (struct calculation_arguments* arguments, struct options* options)
{
	int i;//, j;

	//int N = arguments->N;

	//arguments->M = allocateMemory(arguments->num_matrices * (N + 1) * (N + 1) * sizeof(double));
	//arguments->Matrix = allocateMemory(arguments->num_matrices * sizeof(double**));
  // neu
  arguments->Mat = allocateMemory(arguments->num_matrices * sizeof(**(arguments->Mat))); 
  
	for (i = 0; i < arguments->num_matrices; i++)
	{
		//arguments->Matrix[i] = allocateMemory((N + 1) * sizeof(double*));
    // neu
    arguments->Mat[i] = allocateMemory(arguments->num_matrices * sizeof(*(arguments->Mat)));
    arguments->Mat[i] = Matrix_init(arguments->N, options->method, options->inf_func);
    
		//for (j = 0; j <= N; j++)
		//{
		//	arguments->Matrix[i][j] = (double*)(arguments->M + (i * (N + 1) * (N + 1)) + (j * (N + 1)));
		//}
	}
}
Example #4
0
void main()
{
	
	Matrix *mx;
	Matrix_init(mx,4,3);
	Matrix_set(mx,3,3,2);

	Scanline *s;
	Instruction ist;


	Instruction_Init(&ist,mx);
	Scanline_Init(&ist);
	Instruction_Do(&ist);
	Instruction_Getname(&ist);


	Instruction_Destroy(&ist);






}
Example #5
0
static void testMultiplyVector() {
	Matrix matrix;
	Vector2 vector2;
	Vector3 vector3;
	Vector4 vector4;
	
	matrix = Matrix_identity();
	vector2 = Matrix_multiplyVector2(matrix, Vector2_init(1.0f, 0.0f));
	assertVector2Approximate(vector2, 1.0f, 0.0f, EPSILON);
	
	vector3 = Matrix_multiplyVector3(matrix, Vector3_init(0.0f, 1.0f, 0.0f));
	assertVector3Approximate(vector3, 0.0f, 1.0f, 0.0f, EPSILON);
	
	vector3 = Matrix_multiplyVector3_rotationOnly(matrix, Vector3_init(0.0f, 1.0f, 0.0f));
	assertVector3Approximate(vector3, 0.0f, 1.0f, 0.0f, EPSILON);
	
	vector4 = Matrix_multiplyVector4(matrix, Vector4_init(0.0f, 0.0f, 1.0f, 0.0f));
	assertVector4Approximate(vector4, 0.0f, 0.0f, 1.0f, 0.0f, EPSILON);
	
	matrix = Matrix_init(0.0f, 2.0f,  0.0f, -1.0f,
	                     2.0f, 0.0f,  0.0f,  1.0f,
	                     0.0f, 0.0f, -2.0f,  2.0f,
	                     0.0f, 0.0f,  0.0f,  1.0f);
	vector2 = Matrix_multiplyVector2(matrix, Vector2_init(-1.0f, 0.0f));
	assertVector2Approximate(vector2, -1.0f, -1.0f, EPSILON);
	
	vector3 = Matrix_multiplyVector3(matrix, Vector3_init(0.0f, -1.0f, 0.0f));
	assertVector3Approximate(vector3, -3.0f, 1.0f, 2.0f, EPSILON);
	
	vector3 = Matrix_multiplyVector3_rotationOnly(matrix, Vector3_init(0.0f, -1.0f, 0.0f));
	assertVector3Approximate(vector3, -2.0f, 0.0f, 0.0f, EPSILON);
	
	vector4 = Matrix_multiplyVector4(matrix, Vector4_init(0.0f, 0.0f, -1.0f, 1.0f));
	assertVector4Approximate(vector4, -1.0f, 1.0f, 4.0f, 1.0f, EPSILON);
}
Example #6
0
class_methods_end

Ltas Ltas_create (long nx, double dx) {
	Ltas me = Thing_new (Ltas);
	if (! me || ! Matrix_init (me, 0, nx * dx, nx, dx, 0.5 * dx, 1, 1, 1, 1, 1)) return NULL;
	return me;
}
Example #7
0
void Activation_init (I, long ny, long nx) {
	iam (Activation);
	double xmin = 1, xmax = nx, dx = 1, x1 = 1, ymin = 1, ymax = ny;
	double dy = 1, y1 = 1;
	my ny = ny; my nx = nx;
	Matrix_init (me, xmin, xmax, nx, dx, x1, ymin, ymax, ny, dy, y1);
}
Example #8
0
int Pattern_init (I, long ny, long nx)
{
    iam (Pattern);
    my ny = ny;
    my nx = nx;
    if (! Matrix_init (me, 1, nx, nx, 1, 1, 1, ny, ny, 1, 1)) return 0;
    return 1;
}
Example #9
0
class_methods_end

Sound Sound_create (long numberOfChannels, double xmin, double xmax, long nx, double dx, double x1) {
	Sound me = Thing_new (Sound);
	if (! me || ! Matrix_init (me, xmin, xmax, nx, dx, x1, 1, numberOfChannels, numberOfChannels, 1, 1))
		forget (me);
	return me;
}
Example #10
0
static void testMultiply() {
	Matrix matrix;
	
	matrix = Matrix_multiplied(Matrix_init(2.0f, 0.0f, 0.0f, 0.0f,
	                                       0.0f, 2.0f, 0.0f, 0.0f,
	                                       0.0f, 0.0f, 2.0f, 0.0f,
	                                       0.0f, 0.0f, 0.0f, 2.0f),
	                           Matrix_init(2.0f, 0.0f, 0.0f, 0.0f,
	                                       0.0f, 2.0f, 0.0f, 0.0f,
	                                       0.0f, 0.0f, 2.0f, 0.0f,
	                                       0.0f, 0.0f, 0.0f, 2.0f));
	assertMatrixApproximate(matrix, 4.0f, 0.0f, 0.0f, 0.0f,
	                                0.0f, 4.0f, 0.0f, 0.0f,
	                                0.0f, 0.0f, 4.0f, 0.0f,
	                                0.0f, 0.0f, 0.0f, 4.0f, EPSILON);
	
	matrix = Matrix_multiplied(Matrix_init(0.0f, 4.0f, 8.0f,  12.0f,
	                                       1.0f, 5.0f, 9.0f,  13.0f,
	                                       2.0f, 6.0f, 10.0f, 14.0f,
	                                       3.0f, 7.0f, 11.0f, 15.0f),
	                           Matrix_init(1.0f, 7.0f,  19.0f, 37.0f,
	                                       2.0f, 11.0f, 23.0f, 41.0f,
	                                       3.0f, 13.0f, 29.0f, 43.0f,
	                                       5.0f, 17.0f, 31.0f, 47.0f));
	assertMatrixApproximate(matrix, 92.0f,  352.0f, 696.0f,  1072.0f,
	                                103.0f, 400.0f, 798.0f,  1240.0f,
	                                114.0f, 448.0f, 900.0f,  1408.0f,
	                                125.0f, 496.0f, 1002.0f, 1576.0f, EPSILON);
	
	matrix = Matrix_init(2.0f, 0.0f, 0.0f, 0.0f,
	                     0.0f, 2.0f, 0.0f, 0.0f,
	                     0.0f, 0.0f, 2.0f, 0.0f,
	                     0.0f, 0.0f, 0.0f, 2.0f),
	Matrix_multiply(&matrix, Matrix_init(2.0f, 0.0f, 0.0f, 0.0f,
	                                     0.0f, 2.0f, 0.0f, 0.0f,
	                                     0.0f, 0.0f, 2.0f, 0.0f,
	                                     0.0f, 0.0f, 0.0f, 2.0f));
	assertMatrixApproximate(matrix, 4.0f, 0.0f, 0.0f, 0.0f,
	                                0.0f, 4.0f, 0.0f, 0.0f,
	                                0.0f, 0.0f, 4.0f, 0.0f,
	                                0.0f, 0.0f, 0.0f, 4.0f, EPSILON);
	
	matrix = Matrix_init(0.0f, 4.0f, 8.0f,  12.0f,
	                     1.0f, 5.0f, 9.0f,  13.0f,
	                     2.0f, 6.0f, 10.0f, 14.0f,
	                     3.0f, 7.0f, 11.0f, 15.0f),
	Matrix_multiply(&matrix, Matrix_init(1.0f, 7.0f,  19.0f, 37.0f,
	                                     2.0f, 11.0f, 23.0f, 41.0f,
	                                     3.0f, 13.0f, 29.0f, 43.0f,
	                                     5.0f, 17.0f, 31.0f, 47.0f));
	assertMatrixApproximate(matrix, 92.0f,  352.0f, 696.0f,  1072.0f,
	                                103.0f, 400.0f, 798.0f,  1240.0f,
	                                114.0f, 448.0f, 900.0f,  1408.0f,
	                                125.0f, 496.0f, 1002.0f, 1576.0f, EPSILON);
}
Example #11
0
Excitation Excitation_create (double df, long nf) {
	try {
		autoExcitation me = Thing_new (Excitation);
		Matrix_init (me.peek(), 0.0, nf * df, nf, df, 0.5 * df, 1, 1, 1, 1, 1);
		return me.transfer();
	} catch (MelderError) {
		Melder_throw ("Excitation not created.");
	}
}
autoBarkSpectrogram BarkSpectrogram_create (double tmin, double tmax, long nt, double dt, double t1, double fmin, double fmax, long nf, double df, double f1) {
	try {
		autoBarkSpectrogram me = Thing_new (BarkSpectrogram);
		Matrix_init (me.get(), tmin, tmax, nt, dt, t1, fmin, fmax, nf, df, f1);
		return me;
	} catch (MelderError) {
		Melder_throw (U"BarkSpectrogram not created.");
	}
}
Example #13
0
Ltas Ltas_create (long nx, double dx) {
	try {
		autoLtas me = Thing_new (Ltas);
		Matrix_init (me.peek(), 0.0, nx * dx, nx, dx, 0.5 * dx, 1.0, 1.0, 1, 1.0, 1.0);
		return me.transfer();
	} catch (MelderError) {
		Melder_throw ("Ltas not created.");
	}
}
Example #14
0
Spectrum Spectrum_create (double fmax, long nf) {
	try {
		autoSpectrum me = Thing_new (Spectrum);
		Matrix_init (me.peek(), 0.0, fmax, nf, fmax / (nf - 1), 0.0, 1, 2, 2, 1, 1);
		return me.transfer();
	} catch (MelderError) {
		Melder_throw ("Spectrum not created.");
	}
}
MelSpectrogram MelSpectrogram_create (double tmin, double tmax, long nt, double dt, double t1, double fmin, double fmax, long nf, double df, double f1) {
	try {
		autoMelSpectrogram me = Thing_new (MelSpectrogram);
		Matrix_init (me.peek(), tmin, tmax, nt, dt, t1, fmin, fmax, nf, df, f1);
		return me.transfer();
	} catch (MelderError) {
		Melder_throw (U"MelSpectrogram not created.");
	}
}
Example #16
0
Sound Sound_create (long numberOfChannels, double xmin, double xmax, long nx, double dx, double x1) {
	try {
		autoSound me = Thing_new (Sound);
		Matrix_init (me.peek(), xmin, xmax, nx, dx, x1, 1, numberOfChannels, numberOfChannels, 1, 1);
		return me.transfer();
	} catch (MelderError) {
		Melder_throw (U"Sound not created.");
	}
}
Example #17
0
autoVocalTract VocalTract_create (long nx, double dx) {
    try {
        autoVocalTract me = Thing_new (VocalTract);
        Matrix_init (me.get(), 0.0, nx * dx, nx, dx, 0.5 * dx, 1.0, 1.0, 1, 1.0, 1.0);
        return me;
    } catch (MelderError) {
        Melder_throw (U"VocalTract not created.");
    }
}
Example #18
0
FormantFilter FormantFilter_create (double tmin, double tmax, long nt,
                                    double dt, double t1, double fmin, double fmax, long nf, double df, double f1) {
	try {
		autoFormantFilter me = Thing_new (FormantFilter);
		Matrix_init (me.peek(), tmin, tmax, nt, dt, t1, fmin, fmax, nf, df, f1);
		return me.transfer();
	} catch (MelderError) {
		Melder_throw (U"FormantFilter not created.");
	}
}
Example #19
0
autoMatrix Matrix_createSimple (long numberOfRows, long numberOfColumns) {
	try {
		autoMatrix me = Thing_new (Matrix);
		Matrix_init (me.peek(), 0.5, numberOfColumns + 0.5, numberOfColumns, 1, 1,
			0.5, numberOfRows + 0.5, numberOfRows, 1, 1);
		return me;
	} catch (MelderError) {
		Melder_throw (U"Matrix object not created.");
	}
}
Example #20
0
int Activation_init (I, long ny, long nx)
{
    iam (Activation); 
	double xmin = 1, xmax = nx, dx = 1, x1 = 1, ymin = 1, ymax = ny;
	double dy = 1, y1 = 1;
    my ny = ny;
    my nx = nx;
    if (! Matrix_init (me, xmin, xmax, nx, dx, x1, ymin, ymax, ny, dy, y1)) return 0;
    return 1;
}
Example #21
0
Ltas Spectrum_to_Ltas_1to1 (Spectrum me) {
	long iband;
	Ltas thee = Thing_new (Ltas); cherror
	Matrix_init (thee, my xmin, my xmax, my nx, my dx, my x1, 1, 1, 1, 1, 1); cherror
	for (iband = 1; iband <= my nx; iband ++) {
		thy z [1] [iband] = Sampled_getValueAtSample (me, iband, 0, 2);
	}
end:
	iferror forget (thee);
	return thee;
}
Example #22
0
autoCepstrogram Cepstrogram_create (double tmin, double tmax, long nt, double dt, double t1,
	double qmin, double qmax, long nq, double dq, double q1) {
	try {
		autoCepstrogram me = Thing_new (Cepstrogram);

		Matrix_init (me.get(), tmin, tmax, nt, dt, t1, qmin, qmax, nq, dq, q1);
		return me;
	} catch (MelderError) {
		Melder_throw (U"Cepstrogram not created.");
	}
}
Example #23
0
autoComplexSpectrogram ComplexSpectrogram_create (double tmin, double tmax, long nt, double dt,
	double t1, double fmin, double fmax, long nf, double df, double f1) {
	try {
		autoComplexSpectrogram me = Thing_new (ComplexSpectrogram);
		Matrix_init (me.get(), tmin, tmax, nt, dt, t1, fmin, fmax, nf, df, f1);
		my phase = NUMmatrix <double> (1, my ny, 1, my nx);
		return me;
	} catch (MelderError) {
		Melder_throw (U"ComplexSpectrogram not created.");
	}
}
PowerCepstrogram PowerCepstrogram_create (double tmin, double tmax, long nt, double dt, double t1,
	double qmin, double qmax, long nq, double dq, double q1) {
	try {
		autoPowerCepstrogram me = Thing_new (PowerCepstrogram);

		Matrix_init (me.peek(), tmin, tmax, nt, dt, t1, qmin, qmax, nq, dq, q1);
		return me.transfer();
	} catch (MelderError) {
		Melder_throw ("PowerCepstrogram not created.");
	}
}
Example #25
0
autoPowerCepstrum PowerCepstrum_create (double qmax, long nq) {
	try {
		autoPowerCepstrum me = Thing_new (PowerCepstrum);
		double dq = qmax / (nq - 1);

		Matrix_init (me.get(), 0.0, qmax, nq, dq, 0.0, 1.0, 1.0, 1, 1, 1.0);
		return me;
	} catch (MelderError) {
		Melder_throw (U"PowerCepstrum not created.");
	}
}
Example #26
0
Cepstrum Cepstrum_create (double qmin, double qmax, long nq) {
	try {
		autoCepstrum me = Thing_new (Cepstrum);
		double dx = (qmax - qmin) / nq;

		Matrix_init (me.peek(), qmin, qmax, nq, dx, qmin + dx / 2, 1, 1, 1, 1, 1);
		return me.transfer();
	} catch (MelderError) {
		Melder_throw ("Cepstrum not created.");
	}
}
Example #27
0
static void testTranspose() {
	Matrix matrix;
	
	matrix = Matrix_transposed(Matrix_init(1.0f, 0.0f, 0.0f, 0.0f,
	                                       1.0f, 1.0f, 0.0f, 0.0f,
	                                       1.0f, 1.0f, 1.0f, 0.0f,
	                                       1.0f, 1.0f, 1.0f, 1.0f));
	assertMatrixExact(matrix, 1.0f, 1.0f, 1.0f, 1.0f,
	                          0.0f, 1.0f, 1.0f, 1.0f,
	                          0.0f, 0.0f, 1.0f, 1.0f,
	                          0.0f, 0.0f, 0.0f, 1.0f);
	
	matrix = Matrix_transposed(Matrix_init(0.0f, 0.4f, 0.8f, 1.2f,
	                                       0.1f, 0.5f, 0.9f, 1.3f,
	                                       0.2f, 0.6f, 1.0f, 1.4f,
	                                       0.3f, 0.7f, 1.1f, 1.5f));
	assertMatrixExact(matrix, 0.0f, 0.1f, 0.2f, 0.3f,
	                          0.4f, 0.5f, 0.6f, 0.7f,
	                          0.8f, 0.9f, 1.0f, 1.1f,
	                          1.2f, 1.3f, 1.4f, 1.5f);
	
	matrix = Matrix_init(1.0f, 0.0f, 0.0f, 0.0f,
	                     1.0f, 1.0f, 0.0f, 0.0f,
	                     1.0f, 1.0f, 1.0f, 0.0f,
	                     1.0f, 1.0f, 1.0f, 1.0f);
	Matrix_transpose(&matrix);
	assertMatrixExact(matrix, 1.0f, 1.0f, 1.0f, 1.0f,
	                          0.0f, 1.0f, 1.0f, 1.0f,
	                          0.0f, 0.0f, 1.0f, 1.0f,
	                          0.0f, 0.0f, 0.0f, 1.0f);
	
	matrix = Matrix_init(0.0f, 0.4f, 0.8f, 1.2f,
	                     0.1f, 0.5f, 0.9f, 1.3f,
	                     0.2f, 0.6f, 1.0f, 1.4f,
	                     0.3f, 0.7f, 1.1f, 1.5f);
	Matrix_transpose(&matrix);
	assertMatrixExact(matrix, 0.0f, 0.1f, 0.2f, 0.3f,
	                          0.4f, 0.5f, 0.6f, 0.7f,
	                          0.8f, 0.9f, 1.0f, 1.1f,
	                          1.2f, 1.3f, 1.4f, 1.5f);
}
Example #28
0
autoMatrix Matrix_create
	(double xmin, double xmax, long nx, double dx, double x1,
	 double ymin, double ymax, long ny, double dy, double y1)
{
	try {
		autoMatrix me = Thing_new (Matrix);
		Matrix_init (me.peek(), xmin, xmax, nx, dx, x1, ymin, ymax, ny, dy, y1);
		return me;
	} catch (MelderError) {
		Melder_throw (U"Matrix object not created.");
	}
}
Example #29
0
Ltas Spectrum_to_Ltas_1to1 (Spectrum me) {
	try {
		autoLtas thee = Thing_new (Ltas);
		Matrix_init (thee.peek(), my xmin, my xmax, my nx, my dx, my x1, 1.0, 1.0, 1, 1.0, 1.0);
		for (long iband = 1; iband <= my nx; iband ++) {
			thy z [1] [iband] = Sampled_getValueAtSample (me, iband, 0, 2);
		}
		return thee.transfer();
	} catch (MelderError) {
		Melder_throw (me, ": not converted to Ltas.");
	}
}
Example #30
0
static void testDeterminant() {
	float determinant;
	
	determinant = Matrix_determinant(Matrix_identity());
	TestCase_assert(fabs(determinant - 1.0f) < EPSILON, "Expected 1.0 but got %f", determinant);
	
	determinant = Matrix_determinant(Matrix_init(0.0f, 0.0f, 2.0f, 2.0f,
	                                             2.0f, 0.0f, 0.0f, 3.0f,
	                                             0.0f, 2.0f, 0.0f, 1.0f,
	                                             0.0f, 0.0f, 0.0f, 1.0f));
	TestCase_assert(fabs(determinant - 8.0f) < EPSILON, "Expected 8.0 but got %f", determinant);
}