Skip to content

Commit 3f09f39

Browse files
committed
add OffsetArrays interface
1 parent 5221953 commit 3f09f39

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

Project.toml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
1-
21
name = "Polynomials"
32
uuid = "f27b6e38-b328-58d1-80ce-0feddd5e7a45"
43
license = "MIT"
54
author = "JuliaMath"
6-
version = "1.1.3"
5+
version = "1.1.4"
76

87
[deps]
98
Intervals = "d8418881-c3e1-53bb-8760-2df7ec849ed5"
109
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
10+
OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
1111
RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"
1212

1313
[compat]
14-
Intervals = "0.5, 1"
14+
Intervals = "0.5, 1.0, 1.3"
1515
RecipesBase = "0.7, 0.8, 1"
1616
julia = "1"
1717

18-
1918
[extras]
2019
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
2120
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"

src/Polynomials.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ module Polynomials
22

33
using LinearAlgebra
44
using Intervals
5+
using OffsetArrays
56

67
include("abstract.jl")
78
include("show.jl")

src/polynomials/LaurentPolynomial.jl

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export LaurentPolynomial
55
66
A [Laurent](https://en.wikipedia.org/wiki/Laurent_polynomial) polynomial is of the form `a_{m}x^m + ... + a_{n}x^n` where `m,n` are integers (not necessarily positive) with ` m <= n`.
77
8-
The `coeffs` specify `a_{m}, a_{m-1}, ..., a_{n}`. Rhe range specified is of the form `m:n`, if left empty, `0:length(coeffs)-1` is used (i.e., the coefficients refer to the standard basis).
8+
The `coeffs` specify `a_{m}, a_{m-1}, ..., a_{n}`. The range specified is of the form `m:n`, if left empty, `0:length(coeffs)-1` is used (i.e., the coefficients refer to the standard basis). Alternatively, the coefficients can be specified using an `OffsetVector` from the `OffsetArrays` package.
99
1010
Laurent polynomials and standard basis polynomials promote to Laurent polynomials. Laurent polynomials may be converted to a standard basis polynomial when `m >= 0`
1111
.
@@ -94,6 +94,17 @@ end
9494

9595
@register LaurentPolynomial
9696

97+
# Add interface for OffsetArray
98+
function LaurentPolynomial{T}(coeffs::OffsetArray{S, 1, Array{S,1}}, var::SymbolLike=:x) where {T, S}
99+
m,n = axes(coeffs, 1)
100+
LaurentPolynomial{T}(T.(coeffs.parent), m:n, Symbol(var))
101+
end
102+
function LaurentPolynomial(coeffs::OffsetArray{S, 1, Array{S,1}}, var::SymbolLike=:x) where {S}
103+
LaurentPolynomial{S}(coeffs, var)
104+
end
105+
106+
107+
97108
function LaurentPolynomial{T}(coeffs::AbstractVector{S},
98109
rng::UnitRange{Int64}=0:length(coeffs)-1,
99110
var::Symbol=:x) where {T <: Number, S <: Number}
@@ -109,11 +120,11 @@ function LaurentPolynomial(coeffs::AbstractVector{T}, var::SymbolLike=:x) where
109120
end
110121

111122
## Alternate interface
112-
Polynomial(coeffs::AbstractVector{T}, rng::UnitRange, var::SymbolLike=:x) where {T <: Number} =
113-
LaurentPolynomial{T}(coeffs, rng, Symbol(var))
123+
Polynomial(coeffs::OffsetArray{T,1,Array{T,1}}, var::SymbolLike=:x) where {T <: Number} =
124+
LaurentPolynomial{T}(coeffs, var)
114125

115-
Polynomial{T}(coeffs::AbstractVector{S}, rng::UnitRange, var::SymbolLike=:x) where {T <: Number, S <: Number} =
116-
LaurentPolynomial{T}(T.(coeffs), rng, Symbol(var))
126+
Polynomial{T}(coeffs::OffsetArray{S,1,Array{S,1}}, var::SymbolLike=:x) where {T <: Number, S <: Number} =
127+
LaurentPolynomial{T}(coeffs, var)
117128

118129
##
119130
## conversion

0 commit comments

Comments
 (0)