Skip to content

Commit 9fadb2e

Browse files
author
William Hart
committed
Added mpfr_vec module, init/clear and test.
1 parent b4641c9 commit 9fadb2e

File tree

7 files changed

+258
-1
lines changed

7 files changed

+258
-1
lines changed

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,6 @@ library-recursive:
6060
%.o: %.c
6161
$(CC) -fPIC $(CFLAGS) $(INCS) -c $< -o $@
6262

63-
BUILD_DIRS = ulong_extras fmpz fmpz_vec fmpz_poly fmpz_mat mpfr_mat LLL
63+
BUILD_DIRS = ulong_extras fmpz fmpz_vec fmpz_poly fmpz_mat mpfr_vec mpfr_mat \
64+
LLL
6465

mpfr_vec.h

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*============================================================================
2+
3+
This file is part of FLINT.
4+
5+
FLINT is free software; you can redistribute it and/or modify
6+
it under the terms of the GNU General Public License as published by
7+
the Free Software Foundation; either version 2 of the License, or
8+
(at your option) any later version.
9+
10+
FLINT is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU General Public License for more details.
14+
15+
You should have received a copy of the GNU General Public License
16+
along with FLINT; if not, write to the Free Software
17+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18+
19+
===============================================================================*/
20+
/******************************************************************************
21+
22+
Copyright (C) 2010 William Hart
23+
24+
******************************************************************************/
25+
26+
#ifndef MFPR_VEC_H
27+
#define MPFR_VEC_H
28+
29+
#include <mpir.h>
30+
#include <mpfr.h>
31+
32+
__mpfr_struct * _mpfr_vec_init(ulong length, mp_bitcnt_t prec);
33+
34+
void _mpfr_vec_clear(__mpfr_struct * vec, ulong length);
35+
36+
#endif
37+
38+
39+
40+
41+
42+

mpfr_vec/Makefile

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
SOURCES = $(wildcard *.c)
2+
3+
OBJS = $(patsubst %.c, %.o, $(SOURCES))
4+
5+
LIB_OBJS = $(patsubst %.c, %.lo, $(SOURCES))
6+
7+
TEST_SOURCES = $(wildcard test/*.c)
8+
9+
PROF_SOURCES = $(wildcard profile/*.c)
10+
11+
TESTS = $(patsubst %.c, %, $(TEST_SOURCES))
12+
13+
PROFS = $(patsubst %.c, %, $(PROF_SOURCES))
14+
15+
all: $(OBJS)
16+
17+
library: $(LIB_OBJS)
18+
19+
profile:
20+
$(foreach prog, $(PROFS), $(CC) -O2 -std=c99 $(INCS) $(prog).c ../profiler.o -o $(prog) $(LIBS) -lflint;)
21+
22+
%.o: %.c
23+
$(CC) $(CFLAGS) -c $(INCS) $< -o $@
24+
25+
%.lo: %.c
26+
$(CC) -fPIC $(CFLAGS) $(INCS) -c $< -o $@
27+
28+
clean:
29+
rm -f $(OBJS) $(LIB_OBJS) $(TESTS)
30+
31+
check: library
32+
$(foreach prog, $(TESTS), $(CC) $(CFLAGS) $(INCS) $(prog).c -o $(prog) -lflint $(LIBS);)
33+
$(foreach prog, $(TESTS), $(prog);)
34+
35+
.PHONY: profile clean check all

mpfr_vec/clear.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*============================================================================
2+
3+
This file is part of FLINT.
4+
5+
FLINT is free software; you can redistribute it and/or modify
6+
it under the terms of the GNU General Public License as published by
7+
the Free Software Foundation; either version 2 of the License, or
8+
(at your option) any later version.
9+
10+
FLINT is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU General Public License for more details.
14+
15+
You should have received a copy of the GNU General Public License
16+
along with FLINT; if not, write to the Free Software
17+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18+
19+
===============================================================================*/
20+
/****************************************************************************
21+
22+
Copyright (C) 2010 William Hart
23+
24+
*****************************************************************************/
25+
26+
#include <stdlib.h>
27+
#include <mpir.h>
28+
#include <mpfr.h>
29+
#include "flint.h"
30+
#include "mpfr_vec.h"
31+
32+
void _mpfr_vec_clear(__mpfr_struct * vec, ulong length)
33+
{
34+
ulong i;
35+
36+
for (i = 0; i < length; i++)
37+
mpfr_clear(vec + i);
38+
39+
free(vec);
40+
}
41+

mpfr_vec/doc/mpfr_vec.txt

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*============================================================================
2+
3+
Copyright (C) 2010 William Hart
4+
Copyright (C) 2010 Andy Novocin
5+
6+
This file is part of FLINT.
7+
8+
FLINT is free software; you can redistribute it and/or modify
9+
it under the terms of the GNU General Public License as published by
10+
the Free Software Foundation; either version 2 of the License, or
11+
(at your option) any later version.
12+
13+
FLINT is distributed in the hope that it will be useful,
14+
but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
GNU General Public License for more details.
17+
18+
You should have received a copy of the GNU General Public License
19+
along with FLINT; if not, write to the Free Software
20+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21+
22+
===============================================================================*/
23+
24+
********************************************************************************
25+
26+
Memory management
27+
28+
********************************************************************************
29+
30+
__mpfr_struct * _mpfr_vec_init(ulong length, mp_bitcnt_t prec)
31+
32+
Return a vector of the given length of initialised mpfr's with the
33+
given exact precision.
34+
35+
void _mpfr_vec_clear(__mpfr_struct * vec, ulong length)
36+
37+
Clear the given vector.

mpfr_vec/init.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*============================================================================
2+
3+
This file is part of FLINT.
4+
5+
FLINT is free software; you can redistribute it and/or modify
6+
it under the terms of the GNU General Public License as published by
7+
the Free Software Foundation; either version 2 of the License, or
8+
(at your option) any later version.
9+
10+
FLINT is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU General Public License for more details.
14+
15+
You should have received a copy of the GNU General Public License
16+
along with FLINT; if not, write to the Free Software
17+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18+
19+
===============================================================================*/
20+
/****************************************************************************
21+
22+
Copyright (C) 2010 William Hart
23+
24+
*****************************************************************************/
25+
26+
#include <stdlib.h>
27+
#include <mpir.h>
28+
#include <mpfr.h>
29+
#include "flint.h"
30+
#include "mpfr_vec.h"
31+
32+
__mpfr_struct * _mpfr_vec_init(ulong length, mp_bitcnt_t prec)
33+
{
34+
ulong i;
35+
36+
__mpfr_struct * vec = (__mpfr_struct *) malloc(length*sizeof(__mpfr_struct));
37+
38+
for (i = 0; i < length; i++)
39+
mpfr_init2(vec + i, prec);
40+
41+
return vec;
42+
}
43+

mpfr_vec/test/t-init_clear.c

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*============================================================================
2+
3+
This file is part of FLINT.
4+
5+
FLINT is free software; you can redistribute it and/or modify
6+
it under the terms of the GNU General Public License as published by
7+
the Free Software Foundation; either version 2 of the License, or
8+
(at your option) any later version.
9+
10+
FLINT is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU General Public License for more details.
14+
15+
You should have received a copy of the GNU General Public License
16+
along with FLINT; if not, write to the Free Software
17+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18+
19+
===============================================================================*/
20+
/****************************************************************************
21+
22+
Copyright (C) 2010 William Hart
23+
24+
*****************************************************************************/
25+
26+
#include <stdio.h>
27+
#include <stdlib.h>
28+
#include <mpir.h>
29+
#include <mpfr.h>
30+
#include "flint.h"
31+
#include "mpfr_vec.h"
32+
#include "ulong_extras.h"
33+
34+
int main(void)
35+
{
36+
int result;
37+
printf("init/clear....");
38+
fflush(stdout);
39+
40+
for (ulong i = 0; i < 10000UL; i++)
41+
{
42+
__mpfr_struct * a;
43+
ulong j;
44+
45+
ulong length = n_randint(100);
46+
ulong prec = n_randint(200) + MPFR_PREC_MIN;
47+
48+
a = _mpfr_vec_init(length, prec);
49+
50+
for (j = 0; j < length; j++)
51+
mpfr_set_ui(a + j, 0, GMP_RNDN);
52+
53+
_mpfr_vec_clear(a, length);
54+
}
55+
56+
printf("PASS\n");
57+
return 0;
58+
}

0 commit comments

Comments
 (0)