Macaulay2 Engine
Loading...
Searching...
No Matches
ntl-internal.cpp
Go to the documentation of this file.
1
// Copyright 2005, Michael Stillman
2
3
// This file contains routines which often conflict with our names
4
5
#include <cstdio>
6
7
#include <M2/config.h>
8
#include <M2/gc-include.h>
9
#include <stddef.h>
10
#include "
ntl-interface.hpp
"
11
12
void
ntl_ZZ_to_mpz
(mpz_t
result
,
const
NTL::ZZ &a)
13
// Assumption: 'result' is already 'init'ed
14
// I could imagine there is a faster way to do this, but currently the only
15
// place
16
// this code is used is with NTL LLL, and even then, only to transfer elements
17
// to/from ntl integers
18
// at the beginning and at the end.
19
{
20
if
(a == 0)
21
{
22
mpz_set_ui(
result
, 0);
23
return
;
24
}
25
26
long
len = NTL::NumBytes(a);
27
unsigned
char
*byte_array =
new
unsigned
char
[len];
28
bool
is_neg = (a < 0);
29
NTL::BytesFromZZ(byte_array, a, len);
30
mpz_import(
result
, len, -1,
sizeof
(byte_array[0]), 0, 0, byte_array);
31
delete
[] byte_array;
32
if
(is_neg) mpz_neg(
result
,
result
);
33
}
34
35
NTL::ZZ
ntl_ZZ_from_mpz
(mpz_srcptr a)
36
{
37
int
sgn = mpz_sgn(a);
38
if
(sgn == 0)
return
NTL::ZZ::zero();
39
long
len = mpz_sizeinbase(a, 8);
40
unsigned
char
*byte_array =
new
unsigned
char
[len];
41
size_t
written_len;
42
mpz_export(byte_array, &written_len, -1,
sizeof
(byte_array[0]), 0, 0, a);
43
NTL::ZZ
result
= NTL::ZZFromBytes(byte_array, written_len);
44
delete
[] byte_array;
45
return
(sgn > 0 ?
result
: -
result
);
46
}
47
48
NTL::mat_ZZ *
makeNTLMatrixZZ
(
int
nrows,
int
ncols)
49
{
50
NTL::mat_ZZ *X =
new
NTL::mat_ZZ;
51
X->SetDims(nrows, ncols);
52
return
X;
53
}
54
55
void
mat_ZZ_set_entry
(NTL::mat_ZZ *A,
long
i,
long
j, mpz_srcptr a)
56
{
57
NTL::ZZ b =
ntl_ZZ_from_mpz
(a);
58
(*A)(i + 1, j + 1) = b;
59
}
60
61
void
mat_ZZ_get_entry
(
const
NTL::mat_ZZ *A,
long
i,
long
j, mpz_t
result
)
62
{
63
NTL::ZZ t = (*A)(i + 1, j + 1);
64
ntl_ZZ_to_mpz
(
result
, t);
65
}
66
67
// Local Variables:
68
// compile-command: "make -C $M2BUILDDIR/Macaulay2/e "
69
// indent-tabs-mode: nil
70
// End:
result
VALGRIND_MAKE_MEM_DEFINED & result(result)
ntl-interface.hpp
Engine bridge into NTL — type conversions and the NTL-backed LLL entry point.
ntl_ZZ_from_mpz
NTL::ZZ ntl_ZZ_from_mpz(mpz_srcptr a)
Definition
ntl-internal.cpp:35
mat_ZZ_get_entry
void mat_ZZ_get_entry(const NTL::mat_ZZ *A, long i, long j, mpz_t result)
Definition
ntl-internal.cpp:61
mat_ZZ_set_entry
void mat_ZZ_set_entry(NTL::mat_ZZ *A, long i, long j, mpz_srcptr a)
Definition
ntl-internal.cpp:55
makeNTLMatrixZZ
NTL::mat_ZZ * makeNTLMatrixZZ(int nrows, int ncols)
Definition
ntl-internal.cpp:48
ntl_ZZ_to_mpz
void ntl_ZZ_to_mpz(mpz_t result, const NTL::ZZ &a)
Definition
ntl-internal.cpp:12
Macaulay2
e
ntl-internal.cpp
Generated on
for Macaulay2 Engine by
1.15.0