start of a matrix module

This commit is contained in:
Fredrik Johansson 2012-09-26 14:19:13 +02:00
parent 281c51ca8a
commit 30949eedc1
21 changed files with 964 additions and 3 deletions

View file

@ -102,5 +102,5 @@ build/%.lo: %.c
build/%.o: %.c
$(CC) -fPIC $(CFLAGS) $(INCS) -c $< -o $@
BUILD_DIRS = fmpr fmprb fmprb_poly
BUILD_DIRS = fmpr fmprb fmprb_poly fmprb_mat

View file

@ -171,6 +171,7 @@ docs = [
("fmpr.txt", "fmpr.h (floating-point arithmetic)", True),
("fmprb.txt", "fmprb.h (real ball arithmetic)", True),
("fmprb_poly.txt", "fmprb_poly.h (polynomials of real balls)", True),
("fmprb_mat.txt", "fmprb_mat.h (matrices of real balls)", True),
("history.txt", "History", False),
("credits.txt", "Credits", False),
]

140
doc/fmprb_mat.txt Normal file
View file

@ -0,0 +1,140 @@
An <tt>fmprb_mat_t</tt> represents a dense matrix over the real numbers,
implemented as an array of entries of type <tt>fmprb_struct</tt>.
The dimension (number of rows and columns) of a matrix is fixed at
initialization, and the user must ensure that inputs and outputs to
an operation have compatible dimensions. The number of rows or columns
in a matrix can be zero.
*******************************************************************************
Types, macros and constants
*******************************************************************************
fmprb_mat_struct
fmprb_mat_t
Contains a pointer to a flat array of the entries (entries), an array of
pointers to the start of each row (rows), and the number of rows (r)
and columns (c).
An <tt>fmprb_mat_t</tt> is defined as an array of length one of type
<tt>fmprb_mat_struct</tt>, permitting an <tt>fmprb_mat_t</tt> to
be passed by reference.
fmprb_mat_entry(mat, i, j)
Macro giving a pointer to the entry at row i and column j.
fmprb_mat_nrows(mat)
Returns the number of rows of the matrix.
fmprb_mat_ncols(mat)
Returns the number of columns of the matrix.
*******************************************************************************
Memory management
*******************************************************************************
void fmprb_mat_init(fmprb_mat_t mat, long r, long c)
Initializes the matrix, setting it to the zero matrix with the given
number of rows and columns.
void fmprb_mat_clear(fmprb_mat_t mat)
Clears the matrix, deallocating all entries.
*******************************************************************************
Conversions
*******************************************************************************
void fmprb_mat_set(fmprb_mat_t dest, const fmprb_mat_t src)
void fmprb_mat_set_fmpz_mat(fmprb_mat_t dest, const fmpz_mat_t src)
void fmprb_mat_set_fmpq_mat(fmprb_mat_t dest, const fmpq_mat_t src, long prec)
Sets dest to src. The operands must have identical dimensions.
*******************************************************************************
Input and output
*******************************************************************************
void fmprb_mat_printd(const fmprb_mat_t mat, long digits)
Prints each entry in the matrix with the specified number of decimal digits.
*******************************************************************************
Comparisons
*******************************************************************************
int fmprb_mat_equal(const fmprb_mat_t mat1, const fmprb_mat_t mat2)
Returns nonzero iff the matrices have the same dimensions
and identical entries.
int fmprb_mat_contains_fmpq_mat(const fmprb_mat_t mat1, const fmpq_mat_t mat2)
Returns nonzero iff the matrices have the same dimensions and each entry
in mat2 is contained in the corresponding entry in mat1.
*******************************************************************************
Special matrices
*******************************************************************************
void fmprb_mat_zero(fmprb_mat_t mat)
Sets all entries in mat to zero.
void fmprb_mat_one(fmprb_mat_t mat)
Sets the entries on the main diagonal to ones,
and all other entries to zero.
*******************************************************************************
Arithmetic
*******************************************************************************
void fmprb_mat_neg(fmprb_mat_t dest, const fmprb_mat_t src)
Sets dest to the exact negation of src. The operands must have
the same dimensions.
void fmprb_mat_add(fmprb_mat_t res, const fmprb_mat_t mat1,
const fmprb_mat_t mat2, long prec)
Sets res to the sum of mat1 and mat2. The operands must have
the same dimensions.
void fmprb_mat_sub(fmprb_mat_t res, const fmprb_mat_t mat1,
const fmprb_mat_t mat2, long prec)
Sets res to the difference of mat1 and mat2. The operands must have
the same dimensions.
void fmprb_mat_mul(fmprb_mat_t res, const fmprb_mat_t mat1,
const fmprb_mat_t mat2, long prec)
Sets res to the matrix product of mat1 and mat2. The operands must have
compatible dimensions for matrix multiplication. Aliasing of input
and output is currently not supported.

View file

@ -8,10 +8,11 @@
<li>A module (fmpr) for correctly rounded arbitrary-precision floating-point arithmetic. Arb numbers have a few special features, such as arbitrary-size exponents (useful for combinatorics and asymptotics) and dynamic allocation (facilitating implementation of hybrid integer/floating-point and mixed-precision algorithms).</li>
<li>A module (fmprb) for real ball arithmetic, where a ball is implemented as a pair of fmpr numbers.</li>
<li>Functions for fast high-precision computation of some mathematical constants, based on ball arithmetic.</li>
<li>A rudimentary module (fmprb_poly) for polynomials or power series over the real numbers, implemented using balls as coefficients, with fast polynomial multiplication.</li>
<li>A module (fmprb_poly) for polynomials or power series over the real numbers, implemented using balls as coefficients, with fast polynomial multiplication.</li>
<li>A rudimentary module (fmprb_mat) for matrices over the real numbers, implemented using balls as coefficients.</li>
</ul>
<p>Planned features include: transcendental functions, more extensive polynomial functionality, matrices, and complex balls (and polynomials and matrices thereof).</p>
<p>Planned features include: transcendental functions, more extensive polynomial and matrix functionality, and complex balls (and polynomials and matrices thereof).</p>
<p>Arb uses <a href="http://mpir.org/">MPIR</a> and <a href="http://flintlib.org/">FLINT</a> for the underlying integer arithmetic. The code conventions borrow from FLINT, and the project might get merged back into FLINT when the code stabilizes in the future. Arb also uses <a href="http://mpfr.org">MPFR</a> for some fallback code and for testing purposes.</p>

90
fmprb_mat.h Normal file
View file

@ -0,0 +1,90 @@
/*=============================================================================
This file is part of ARB.
ARB is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
ARB is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with ARB; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2012 Fredrik Johansson
******************************************************************************/
#ifndef FMPRB_MAT_H
#define FMPRB_MAT_H
#include "fmprb.h"
#include "fmpz_mat.h"
#include "fmpq_mat.h"
typedef struct
{
fmprb_struct * entries;
long r;
long c;
fmprb_struct ** rows;
}
fmprb_mat_struct;
typedef fmprb_mat_struct fmprb_mat_t[1];
#define fmprb_mat_entry(mat,i,j) ((mat)->rows[i] + (j))
#define fmprb_mat_nrows(mat) ((mat)->r)
#define fmprb_mat_ncols(mat) ((mat)->c)
/* Memory management */
void fmprb_mat_init(fmprb_mat_t mat, long r, long c);
void fmprb_mat_clear(fmprb_mat_t mat);
/* Conversions */
void fmprb_mat_set(fmprb_mat_t dest, const fmprb_mat_t src);
void fmprb_mat_set_fmpz_mat(fmprb_mat_t dest, const fmpz_mat_t src);
void fmprb_mat_set_fmpq_mat(fmprb_mat_t dest, const fmpq_mat_t src, long prec);
/* I/O */
void fmprb_mat_printd(const fmprb_mat_t mat, long digits);
/* Comparisons */
int fmprb_mat_equal(const fmprb_mat_t mat1, const fmprb_mat_t mat2);
int fmprb_mat_contains_fmpq_mat(const fmprb_mat_t mat1, const fmpq_mat_t mat2);
/* Special matrices */
void fmprb_mat_zero(fmprb_mat_t mat);
void fmprb_mat_one(fmprb_mat_t mat);
/* Arithmetic */
void fmprb_mat_neg(fmprb_mat_t dest, const fmprb_mat_t src);
void fmprb_mat_add(fmprb_mat_t res, const fmprb_mat_t mat1, const fmprb_mat_t mat2, long prec);
void fmprb_mat_sub(fmprb_mat_t res, const fmprb_mat_t mat1, const fmprb_mat_t mat2, long prec);
void fmprb_mat_mul(fmprb_mat_t res, const fmprb_mat_t mat1, const fmprb_mat_t mat2, long prec);
#endif

43
fmprb_mat/Makefile Normal file
View file

@ -0,0 +1,43 @@
SOURCES = $(wildcard *.c)
OBJS = $(patsubst %.c, $(BUILD_DIR)/%.o, $(SOURCES))
LIB_OBJS = $(patsubst %.c, $(BUILD_DIR)/%.lo, $(SOURCES))
TEST_SOURCES = $(wildcard test/*.c)
PROF_SOURCES = $(wildcard profile/*.c)
TUNE_SOURCES = $(wildcard tune/*.c)
TESTS = $(patsubst %.c, %, $(TEST_SOURCES))
PROFS = $(patsubst %.c, %, $(PROF_SOURCES))
TUNE = $(patsubst %.c, %, $(TUNE_SOURCES))
all: $(OBJS)
library: $(LIB_OBJS)
profile:
$(foreach prog, $(PROFS), $(CC) -O2 -std=c99 $(INCS) $(prog).c ../profiler.o -o $(BUILD_DIR)/$(prog) $(LIBS) -lflint;)
tune: $(TUNE_SOURCES)
$(foreach prog, $(TUNE), $(CC) -O2 -std=c99 $(INCS) $(prog).c -o $(BUILD_DIR)/$(prog) $(LIBS) -lflint;)
$(BUILD_DIR)/%.o: %.c
$(CC) $(CFLAGS) -c $(INCS) $< -o $@
$(BUILD_DIR)/%.lo: %.c
$(CC) -fPIC $(CFLAGS) $(INCS) -c $< -o $@
clean:
rm -rf $(BUILD_DIR)
check: library
$(foreach prog, $(TESTS), $(CC) $(CFLAGS) $(INCS) $(prog).c -o $(BUILD_DIR)/$(prog) $(LIBS) -lflint;)
$(foreach prog, $(TESTS), $(BUILD_DIR)/$(prog);)
.PHONY: profile clean check all

39
fmprb_mat/add.c Normal file
View file

@ -0,0 +1,39 @@
/*=============================================================================
This file is part of ARB.
ARB is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
ARB is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with ARB; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2012 Fredrik Johansson
******************************************************************************/
#include "fmprb_mat.h"
void
fmprb_mat_add(fmprb_mat_t res,
const fmprb_mat_t mat1, const fmprb_mat_t mat2, long prec)
{
long i, j;
for (i = 0; i < fmprb_mat_nrows(mat1); i++)
for (j = 0; j < fmprb_mat_ncols(mat1); j++)
fmprb_add(fmprb_mat_entry(res, i, j),
fmprb_mat_entry(mat1, i, j),
fmprb_mat_entry(mat2, i, j), prec);
}

36
fmprb_mat/clear.c Normal file
View file

@ -0,0 +1,36 @@
/*=============================================================================
This file is part of ARB.
ARB is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
ARB is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with ARB; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2012 Fredrik Johansson
******************************************************************************/
#include "fmprb_mat.h"
void
fmprb_mat_clear(fmprb_mat_t mat)
{
if (mat->entries != NULL)
{
_fmprb_vec_clear(mat->entries, mat->r * mat->c);
flint_free(mat->rows);
}
}

View file

@ -0,0 +1,44 @@
/*=============================================================================
This file is part of ARB.
ARB is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
ARB is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with ARB; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2012 Fredrik Johansson
******************************************************************************/
#include "fmprb_mat.h"
int
fmprb_mat_contains_fmpq_mat(const fmprb_mat_t mat1, const fmpq_mat_t mat2)
{
long i, j;
if ((fmprb_mat_nrows(mat1) != fmprb_mat_nrows(mat2)) ||
(fmprb_mat_ncols(mat1) != fmprb_mat_ncols(mat2)))
return 0;
for (i = 0; i < fmprb_mat_nrows(mat1); i++)
for (j = 0; j < fmprb_mat_ncols(mat1); j++)
if (!fmprb_contains_fmpq(fmprb_mat_entry(mat1, i, j),
fmpq_mat_entry(mat2, i, j)))
return 0;
return 1;
}

44
fmprb_mat/equal.c Normal file
View file

@ -0,0 +1,44 @@
/*=============================================================================
This file is part of ARB.
ARB is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
ARB is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with ARB; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2012 Fredrik Johansson
******************************************************************************/
#include "fmprb_mat.h"
int
fmprb_mat_equal(const fmprb_mat_t mat1, const fmprb_mat_t mat2)
{
long i, j;
if ((fmprb_mat_nrows(mat1) != fmprb_mat_nrows(mat2)) ||
(fmprb_mat_ncols(mat1) != fmprb_mat_ncols(mat2)))
return 0;
for (i = 0; i < fmprb_mat_nrows(mat1); i++)
for (j = 0; j < fmprb_mat_ncols(mat1); j++)
if (!fmprb_equal(fmprb_mat_entry(mat1, i, j),
fmprb_mat_entry(mat2, i, j)))
return 0;
return 1;
}

46
fmprb_mat/init.c Normal file
View file

@ -0,0 +1,46 @@
/*=============================================================================
This file is part of ARB.
ARB is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
ARB is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with ARB; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2012 Fredrik Johansson
******************************************************************************/
#include "fmprb_mat.h"
void
fmprb_mat_init(fmprb_mat_t mat, long r, long c)
{
if (r != 0 && c != 0)
{
long i;
mat->entries = _fmprb_vec_init(r * c);
mat->rows = (fmprb_struct **) flint_malloc(r * sizeof(fmprb_struct *));
for (i = 0; i < r; i++)
mat->rows[i] = mat->entries + i * c;
}
else
mat->entries = NULL;
mat->r = r;
mat->c = c;
}

59
fmprb_mat/mul.c Normal file
View file

@ -0,0 +1,59 @@
/*=============================================================================
This file is part of ARB.
ARB is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
ARB is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with ARB; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2012 Fredrik Johansson
******************************************************************************/
#include "fmprb_mat.h"
void
fmprb_mat_mul(fmprb_mat_t C, const fmprb_mat_t A, const fmprb_mat_t B, long prec)
{
long ar, bc, br, i, j, k;
ar = fmprb_mat_nrows(A);
br = fmprb_mat_nrows(B);
bc = fmprb_mat_ncols(B);
if (br == 0)
{
fmprb_mat_zero(C);
return;
}
for (i = 0; i < ar; i++)
{
for (j = 0; j < bc; j++)
{
fmprb_mul(fmprb_mat_entry(C, i, j),
fmprb_mat_entry(A, i, 0),
fmprb_mat_entry(B, 0, j), prec);
for (k = 1; k < br; k++)
{
fmprb_addmul(fmprb_mat_entry(C, i, j),
fmprb_mat_entry(A, i, k),
fmprb_mat_entry(B, k, j), prec);
}
}
}
}

37
fmprb_mat/neg.c Normal file
View file

@ -0,0 +1,37 @@
/*=============================================================================
This file is part of ARB.
ARB is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
ARB is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with ARB; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2012 Fredrik Johansson
******************************************************************************/
#include "fmprb_mat.h"
void
fmprb_mat_neg(fmprb_mat_t dest, const fmprb_mat_t src)
{
long i, j;
for (i = 0; i < fmprb_mat_nrows(src); i++)
for (j = 0; j < fmprb_mat_ncols(src); j++)
fmprb_neg(fmprb_mat_entry(dest, i, j),
fmprb_mat_entry(src, i, j));
}

39
fmprb_mat/one.c Normal file
View file

@ -0,0 +1,39 @@
/*=============================================================================
This file is part of ARB.
ARB is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
ARB is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with ARB; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2012 Fredrik Johansson
******************************************************************************/
#include "fmprb_mat.h"
void
fmprb_mat_one(fmprb_mat_t mat)
{
long i, j;
for (i = 0; i < fmprb_mat_nrows(mat); i++)
for (j = 0; j < fmprb_mat_ncols(mat); j++)
if (i == j)
fmprb_one(fmprb_mat_entry(mat, i, j));
else
fmprb_zero(fmprb_mat_entry(mat, i, j));
}

47
fmprb_mat/printd.c Normal file
View file

@ -0,0 +1,47 @@
/*=============================================================================
This file is part of ARB.
ARB is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
ARB is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with ARB; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2012 Fredrik Johansson
******************************************************************************/
#include "fmprb_mat.h"
void
fmprb_mat_printd(const fmprb_mat_t mat, long digits)
{
long i, j;
for (i = 0; i < fmprb_mat_nrows(mat); i++)
{
printf("[");
for (j = 0; j < fmprb_mat_ncols(mat); j++)
{
fmprb_printd(fmprb_mat_entry(mat, i, j), digits);
if (j < fmprb_mat_ncols(mat) - 1)
printf(", ");
}
printf("]\n");
}
}

40
fmprb_mat/set.c Normal file
View file

@ -0,0 +1,40 @@
/*=============================================================================
This file is part of ARB.
ARB is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
ARB is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with ARB; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2012 Fredrik Johansson
******************************************************************************/
#include "fmprb_mat.h"
void
fmprb_mat_set(fmprb_mat_t dest, const fmprb_mat_t src)
{
long i, j;
if (dest != src && fmprb_mat_ncols(src) != 0)
{
for (i = 0; i < fmprb_mat_nrows(src); i++)
for (j = 0; j < fmprb_mat_ncols(src); j++)
fmprb_set(fmprb_mat_entry(dest, i, j),
fmprb_mat_entry(src, i, j));
}
}

40
fmprb_mat/set_fmpq_mat.c Normal file
View file

@ -0,0 +1,40 @@
/*=============================================================================
This file is part of ARB.
ARB is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
ARB is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with ARB; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2012 Fredrik Johansson
******************************************************************************/
#include "fmprb_mat.h"
void
fmprb_mat_set_fmpq_mat(fmprb_mat_t dest, const fmpq_mat_t src, long prec)
{
long i, j;
if (fmprb_mat_ncols(dest) != 0)
{
for (i = 0; i < fmprb_mat_nrows(dest); i++)
for (j = 0; j < fmprb_mat_ncols(dest); j++)
fmprb_set_fmpq(fmprb_mat_entry(dest, i, j),
fmpz_mat_entry(src, i, j), prec);
}
}

40
fmprb_mat/set_fmpz_mat.c Normal file
View file

@ -0,0 +1,40 @@
/*=============================================================================
This file is part of ARB.
ARB is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
ARB is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with ARB; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2012 Fredrik Johansson
******************************************************************************/
#include "fmprb_mat.h"
void
fmprb_mat_set_fmpz_mat(fmprb_mat_t dest, const fmpz_mat_t src)
{
long i, j;
if (fmprb_mat_ncols(dest) != 0)
{
for (i = 0; i < fmprb_mat_nrows(dest); i++)
for (j = 0; j < fmprb_mat_ncols(dest); j++)
fmprb_set_fmpz(fmprb_mat_entry(dest, i, j),
fmpz_mat_entry(src, i, j));
}
}

39
fmprb_mat/sub.c Normal file
View file

@ -0,0 +1,39 @@
/*=============================================================================
This file is part of ARB.
ARB is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
ARB is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with ARB; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2012 Fredrik Johansson
******************************************************************************/
#include "fmprb_mat.h"
void
fmprb_mat_sub(fmprb_mat_t res,
const fmprb_mat_t mat1, const fmprb_mat_t mat2, long prec)
{
long i, j;
for (i = 0; i < fmprb_mat_nrows(mat1); i++)
for (j = 0; j < fmprb_mat_ncols(mat1); j++)
fmprb_sub(fmprb_mat_entry(res, i, j),
fmprb_mat_entry(mat1, i, j),
fmprb_mat_entry(mat2, i, j), prec);
}

100
fmprb_mat/test/t-mul.c Normal file
View file

@ -0,0 +1,100 @@
/*=============================================================================
This file is part of ARB.
ARB is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
ARB is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with ARB; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2012 Fredrik Johansson
******************************************************************************/
#include "fmprb_mat.h"
int main()
{
long iter;
flint_rand_t state;
printf("mul....");
fflush(stdout);
flint_randinit(state);
for (iter = 0; iter < 10000; iter++)
{
long m, n, k, qbits1, qbits2, rbits1, rbits2, rbits3;
fmpq_mat_t A, B, C;
fmprb_mat_t a, b, c;
qbits1 = 2 + n_randint(state, 200);
qbits2 = 2 + n_randint(state, 200);
rbits1 = 2 + n_randint(state, 200);
rbits2 = 2 + n_randint(state, 200);
rbits3 = 2 + n_randint(state, 200);
m = n_randint(state, 10);
n = n_randint(state, 10);
k = n_randint(state, 10);
fmpq_mat_init(A, m, n);
fmpq_mat_init(B, n, k);
fmpq_mat_init(C, m, k);
fmprb_mat_init(a, m, n);
fmprb_mat_init(b, n, k);
fmprb_mat_init(c, m, k);
fmpq_mat_randtest(A, state, qbits1);
fmpq_mat_randtest(B, state, qbits2);
fmpq_mat_mul(C, A, B);
fmprb_mat_set_fmpq_mat(a, A, rbits1);
fmprb_mat_set_fmpq_mat(b, B, rbits2);
fmprb_mat_mul(c, a, b, rbits3);
if (!fmprb_mat_contains_fmpq_mat(c, C))
{
printf("FAIL\n\n");
printf("m = %ld, n = %ld, k = %ld, bits3 = %ld\n", m, n, k, rbits3);
printf("A = "); fmpq_mat_print(A); printf("\n\n");
printf("B = "); fmpq_mat_print(B); printf("\n\n");
printf("C = "); fmpq_mat_print(C); printf("\n\n");
printf("a = "); fmprb_mat_printd(a, 15); printf("\n\n");
printf("b = "); fmprb_mat_printd(b, 15); printf("\n\n");
printf("c = "); fmprb_mat_printd(c, 15); printf("\n\n");
abort();
}
fmpq_mat_clear(A);
fmpq_mat_clear(B);
fmpq_mat_clear(C);
fmprb_mat_clear(a);
fmprb_mat_clear(b);
fmprb_mat_clear(c);
}
flint_randclear(state);
_fmpz_cleanup();
printf("PASS\n");
return EXIT_SUCCESS;
}

36
fmprb_mat/zero.c Normal file
View file

@ -0,0 +1,36 @@
/*=============================================================================
This file is part of ARB.
ARB is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
ARB is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with ARB; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2012 Fredrik Johansson
******************************************************************************/
#include "fmprb_mat.h"
void
fmprb_mat_zero(fmprb_mat_t mat)
{
long i, j;
for (i = 0; i < fmprb_mat_nrows(mat); i++)
for (j = 0; j < fmprb_mat_ncols(mat); j++)
fmprb_zero(fmprb_mat_entry(mat, i, j));
}