Skip to content

Commit 3feed4c

Browse files
committed
Remove custom code for Col/Colrev/Vec/Vecrev/Vecsmall
1 parent 551a527 commit 3feed4c

File tree

1 file changed

+0
-305
lines changed

1 file changed

+0
-305
lines changed

cypari2/gen.pyx

Lines changed: 0 additions & 305 deletions
Original file line numberDiff line numberDiff line change
@@ -2294,112 +2294,6 @@ cdef class Gen(Gen_base):
22942294
sig_on()
22952295
return new_gen(vecmin(x.g))
22962296

2297-
def Col(x, long n = 0):
2298-
"""
2299-
Transform the object `x` into a column vector with minimal size `|n|`.
2300-
2301-
INPUT:
2302-
2303-
- ``x`` -- gen
2304-
2305-
- ``n`` -- Make the column vector of minimal length `|n|`. If `n > 0`,
2306-
append zeros; if `n < 0`, prepend zeros.
2307-
2308-
OUTPUT:
2309-
2310-
A PARI column vector (type ``t_COL``)
2311-
2312-
Examples:
2313-
2314-
>>> from cypari2 import Pari
2315-
>>> pari = Pari()
2316-
2317-
>>> pari(1.5).Col()
2318-
[1.50000000000000]~
2319-
>>> pari([1,2,3,4]).Col()
2320-
[1, 2, 3, 4]~
2321-
>>> pari('[1,2; 3,4]').Col()
2322-
[[1, 2], [3, 4]]~
2323-
>>> pari('"CyPari"').Col()
2324-
["C", "y", "P", "a", "r", "i"]~
2325-
>>> pari('x + 3*x^3').Col()
2326-
[3, 0, 1, 0]~
2327-
>>> pari('x + 3*x^3 + O(x^5)').Col()
2328-
[1, 0, 3, 0]~
2329-
2330-
We demonstate the `n` argument:
2331-
2332-
>>> pari([1,2,3,4]).Col(2)
2333-
[1, 2, 3, 4]~
2334-
>>> pari([1,2,3,4]).Col(-2)
2335-
[1, 2, 3, 4]~
2336-
>>> pari([1,2,3,4]).Col(6)
2337-
[1, 2, 3, 4, 0, 0]~
2338-
>>> pari([1,2,3,4]).Col(-6)
2339-
[0, 0, 1, 2, 3, 4]~
2340-
2341-
See also :meth:`Vec` (create a row vector) for more examples
2342-
and :meth:`Colrev` (create a column in reversed order).
2343-
"""
2344-
sig_on()
2345-
return new_gen(_Vec_append(gtocol(x.g), gen_0, n))
2346-
2347-
def Colrev(x, long n = 0):
2348-
"""
2349-
Transform the object `x` into a column vector with minimal size `|n|`.
2350-
The order of the resulting vector is reversed compared to :meth:`Col`.
2351-
2352-
INPUT:
2353-
2354-
- ``x`` -- gen
2355-
2356-
- ``n`` -- Make the vector of minimal length `|n|`. If `n > 0`,
2357-
prepend zeros; if `n < 0`, append zeros.
2358-
2359-
OUTPUT:
2360-
2361-
A PARI column vector (type ``t_COL``)
2362-
2363-
Examples:
2364-
2365-
>>> from cypari2 import Pari
2366-
>>> pari = Pari()
2367-
2368-
>>> pari(1.5).Colrev()
2369-
[1.50000000000000]~
2370-
>>> pari([1,2,3,4]).Colrev()
2371-
[4, 3, 2, 1]~
2372-
>>> pari('[1,2; 3,4]').Colrev()
2373-
[[3, 4], [1, 2]]~
2374-
>>> pari('x + 3*x^3').Colrev()
2375-
[0, 1, 0, 3]~
2376-
2377-
We demonstate the `n` argument:
2378-
2379-
>>> pari([1,2,3,4]).Colrev(2)
2380-
[4, 3, 2, 1]~
2381-
>>> pari([1,2,3,4]).Colrev(-2)
2382-
[4, 3, 2, 1]~
2383-
>>> pari([1,2,3,4]).Colrev(6)
2384-
[0, 0, 4, 3, 2, 1]~
2385-
>>> pari([1,2,3,4]).Colrev(-6)
2386-
[4, 3, 2, 1, 0, 0]~
2387-
"""
2388-
sig_on()
2389-
# Create a non-reversed column vector
2390-
cdef GEN v = _Vec_append(gtocol(x.g), gen_0, n)
2391-
# Reverse it in-place
2392-
cdef GEN L = v + 1
2393-
cdef GEN R = v + (lg(v)-1)
2394-
cdef long t
2395-
while (L < R):
2396-
t = L[0]
2397-
L[0] = R[0]
2398-
R[0] = t
2399-
L += 1
2400-
R -= 1
2401-
return new_gen(v)
2402-
24032297
def Ser(f, v=None, long precision=-1):
24042298
"""
24052299
Return a power series or Laurent series in the variable `v`
@@ -2590,160 +2484,6 @@ cdef class Gen(Gen_base):
25902484
sig_on()
25912485
return new_gen(Strtex(x.g))
25922486

2593-
def Vec(x, long n = 0):
2594-
"""
2595-
Transform the object `x` into a vector with minimal size `|n|`.
2596-
2597-
INPUT:
2598-
2599-
- ``x`` -- gen
2600-
2601-
- ``n`` -- Make the vector of minimal length `|n|`. If `n > 0`,
2602-
append zeros; if `n < 0`, prepend zeros.
2603-
2604-
OUTPUT:
2605-
2606-
A PARI vector (type ``t_VEC``)
2607-
2608-
Examples:
2609-
2610-
>>> from cypari2 import Pari
2611-
>>> pari = Pari()
2612-
2613-
>>> pari(1).Vec()
2614-
[1]
2615-
>>> pari('x^3').Vec()
2616-
[1, 0, 0, 0]
2617-
>>> pari('x^3 + 3*x - 2').Vec()
2618-
[1, 0, 3, -2]
2619-
>>> pari([1,2,3]).Vec()
2620-
[1, 2, 3]
2621-
>>> pari('[1, 2; 3, 4]').Vec()
2622-
[[1, 3]~, [2, 4]~]
2623-
>>> pari('"CyPari"').Vec()
2624-
["C", "y", "P", "a", "r", "i"]
2625-
>>> pari('2*x^2 + 3*x^3 + O(x^5)').Vec()
2626-
[2, 3, 0]
2627-
>>> pari('2*x^-2 + 3*x^3 + O(x^5)').Vec()
2628-
[2, 0, 0, 0, 0, 3, 0]
2629-
2630-
Note the different term ordering for polynomials and series:
2631-
2632-
>>> pari('1 + x + 3*x^3 + O(x^5)').Vec()
2633-
[1, 1, 0, 3, 0]
2634-
>>> pari('1 + x + 3*x^3').Vec()
2635-
[3, 0, 1, 1]
2636-
2637-
We demonstate the `n` argument:
2638-
2639-
>>> pari([1,2,3,4]).Vec(2)
2640-
[1, 2, 3, 4]
2641-
>>> pari([1,2,3,4]).Vec(-2)
2642-
[1, 2, 3, 4]
2643-
>>> pari([1,2,3,4]).Vec(6)
2644-
[1, 2, 3, 4, 0, 0]
2645-
>>> pari([1,2,3,4]).Vec(-6)
2646-
[0, 0, 1, 2, 3, 4]
2647-
2648-
See also :meth:`Col` (create a column vector) and :meth:`Vecrev`
2649-
(create a vector in reversed order).
2650-
"""
2651-
sig_on()
2652-
return new_gen(_Vec_append(gtovec(x.g), gen_0, n))
2653-
2654-
def Vecrev(x, long n = 0):
2655-
"""
2656-
Transform the object `x` into a vector with minimal size `|n|`.
2657-
The order of the resulting vector is reversed compared to :meth:`Vec`.
2658-
2659-
INPUT:
2660-
2661-
- ``x`` -- gen
2662-
2663-
- ``n`` -- Make the vector of minimal length `|n|`. If `n > 0`,
2664-
prepend zeros; if `n < 0`, append zeros.
2665-
2666-
OUTPUT:
2667-
2668-
A PARI vector (type ``t_VEC``)
2669-
2670-
Examples:
2671-
2672-
>>> from cypari2 import Pari
2673-
>>> pari = Pari()
2674-
2675-
>>> pari(1).Vecrev()
2676-
[1]
2677-
>>> pari('x^3').Vecrev()
2678-
[0, 0, 0, 1]
2679-
>>> pari('x^3 + 3*x - 2').Vecrev()
2680-
[-2, 3, 0, 1]
2681-
>>> pari([1, 2, 3]).Vecrev()
2682-
[3, 2, 1]
2683-
>>> pari('Col([1, 2, 3])').Vecrev()
2684-
[3, 2, 1]
2685-
>>> pari('[1, 2; 3, 4]').Vecrev()
2686-
[[2, 4]~, [1, 3]~]
2687-
>>> pari('"CyPari"').Vecrev()
2688-
["i", "r", "a", "P", "y", "C"]
2689-
2690-
We demonstate the `n` argument:
2691-
2692-
>>> pari([1,2,3,4]).Vecrev(2)
2693-
[4, 3, 2, 1]
2694-
>>> pari([1,2,3,4]).Vecrev(-2)
2695-
[4, 3, 2, 1]
2696-
>>> pari([1,2,3,4]).Vecrev(6)
2697-
[0, 0, 4, 3, 2, 1]
2698-
>>> pari([1,2,3,4]).Vecrev(-6)
2699-
[4, 3, 2, 1, 0, 0]
2700-
"""
2701-
sig_on()
2702-
return new_gen(_Vec_append(gtovecrev(x.g), gen_0, -n))
2703-
2704-
def Vecsmall(x, long n = 0):
2705-
"""
2706-
Transform the object `x` into a ``t_VECSMALL`` with minimal size `|n|`.
2707-
2708-
INPUT:
2709-
2710-
- ``x`` -- gen
2711-
2712-
- ``n`` -- Make the vector of minimal length `|n|`. If `n > 0`,
2713-
append zeros; if `n < 0`, prepend zeros.
2714-
2715-
OUTPUT:
2716-
2717-
A PARI vector of small integers (type ``t_VECSMALL``)
2718-
2719-
Examples:
2720-
2721-
>>> from cypari2 import Pari
2722-
>>> pari = Pari()
2723-
2724-
>>> pari([1,2,3]).Vecsmall()
2725-
Vecsmall([1, 2, 3])
2726-
>>> pari('"CyPari"').Vecsmall()
2727-
Vecsmall([67, 121, 80, 97, 114, 105])
2728-
>>> pari(1234).Vecsmall()
2729-
Vecsmall([1234])
2730-
>>> pari('x^2 + 2*x + 3').Vecsmall()
2731-
Vecsmall([1, 2, 3])
2732-
2733-
We demonstate the `n` argument:
2734-
2735-
>>> pari([1,2,3]).Vecsmall(2)
2736-
Vecsmall([1, 2, 3])
2737-
>>> pari([1,2,3]).Vecsmall(-2)
2738-
Vecsmall([1, 2, 3])
2739-
>>> pari([1,2,3]).Vecsmall(6)
2740-
Vecsmall([1, 2, 3, 0, 0, 0])
2741-
>>> pari([1,2,3]).Vecsmall(-6)
2742-
Vecsmall([0, 0, 0, 1, 2, 3])
2743-
"""
2744-
sig_on()
2745-
return new_gen(_Vec_append(gtovecsmall(x.g), <GEN>0, n))
2746-
27472487
def bittest(x, long n):
27482488
"""
27492489
bittest(x, long n): Returns bit number n (coefficient of
@@ -4994,48 +4734,3 @@ cpdef Gen objtogen(s):
49944734

49954735
# Simply use the string representation
49964736
return objtogen(str(s))
4997-
4998-
4999-
cdef GEN _Vec_append(GEN v, GEN a, long n):
5000-
"""
5001-
This implements appending zeros (or another constant GEN ``a``) to
5002-
the result of :meth:`Vec` and similar functions.
5003-
5004-
This is a shallow function, copying ``a`` and entries of ``v`` to
5005-
the result. The result is simply stored on the PARI stack.
5006-
5007-
INPUT:
5008-
5009-
- ``v`` -- GEN of type ``t_VEC`` or ``t_COL``
5010-
5011-
- ``a`` -- GEN which will be used for the added entries.
5012-
Normally, this would be ``gen_0``.
5013-
5014-
- ``n`` -- Make the vector of minimal length `|n|`. If `n > 0`,
5015-
append zeros; if `n < 0`, prepend zeros.
5016-
5017-
OUTPUT:
5018-
5019-
A GEN of the same type as ``v``.
5020-
"""
5021-
cdef long lenv = lg(v)-1
5022-
cdef GEN w
5023-
cdef long i
5024-
# Do we need to extend the vector with zeros?
5025-
if n > lenv:
5026-
w = cgetg(n+1, typ(v))
5027-
for i from 1 <= i <= lenv:
5028-
set_gel(w, i, gel(v, i))
5029-
for i from 1 <= i <= n-lenv:
5030-
set_gel(w, i+lenv, a)
5031-
return w
5032-
elif n < -lenv:
5033-
n = -n # Make n positive
5034-
w = cgetg(n+1, typ(v))
5035-
for i from 1 <= i <= lenv:
5036-
set_gel(w, i+(n-lenv), gel(v, i))
5037-
for i from 1 <= i <= n-lenv:
5038-
set_gel(w, i, a)
5039-
return w
5040-
else:
5041-
return v

0 commit comments

Comments
 (0)