Skip to content

Commit

Permalink
refactor: renaming class file and imports
Browse files Browse the repository at this point in the history
  • Loading branch information
edelveart committed Jul 20, 2024
1 parent 9638e18 commit 4f05798
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/figuratenum/MultidimensionalFigurateNum.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .instance_methods_figuratenum import InstanceMethodsFigurateNum
from .TakeMethods import TakeMethods

from .multidimensional_figuratenum import (
pentatope_numbers, hypertetrahedral_numbers, triangulotriangular_numbers, k_hypertetrahedron_numbers,
Expand Down Expand Up @@ -56,7 +56,7 @@
)


class MultidimensionalFigurateNum(InstanceMethodsFigurateNum):
class MultidimensionalFigurateNum(TakeMethods):

@classmethod
def pentatope_numbers(cls) -> "MultidimensionalFigurateNum":
Expand Down
4 changes: 2 additions & 2 deletions src/figuratenum/PlaneFigurateNum.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .instance_methods_figuratenum import InstanceMethodsFigurateNum
from .TakeMethods import TakeMethods

from .plane_figuratenum import (
polygonal_numbers, centered_square_numbers, diamond_numbers,
Expand Down Expand Up @@ -26,7 +26,7 @@
)


class PlaneFigurateNum(InstanceMethodsFigurateNum):
class PlaneFigurateNum(TakeMethods):

@classmethod
def polygonal_numbers(cls, k: int) -> "PlaneFigurateNum":
Expand Down
4 changes: 2 additions & 2 deletions src/figuratenum/SpaceFigurateNum.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .instance_methods_figuratenum import InstanceMethodsFigurateNum
from .TakeMethods import TakeMethods

from .space_figuratenum import (
m_pyramidal_numbers, cubic_numbers, tetrahedral_numbers,
Expand Down Expand Up @@ -42,7 +42,7 @@
)


class SpaceFigurateNum(InstanceMethodsFigurateNum):
class SpaceFigurateNum(TakeMethods):

@classmethod
def m_pyramidal_numbers(cls, m: int) -> "SpaceFigurateNum":
Expand Down
97 changes: 97 additions & 0 deletions src/figuratenum/TakeMethods.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
from typing import List, Tuple
from array import array
from itertools import islice


class TakeMethods():
def take(self, n: int) -> List[int]:
"""
Takes the first n generated figurate numbers from the sequence and returns them as a list.
Parameters
----------
n : int
Number of elements to take.
Returns
-------
list
List of the first n generated figurate numbers.
"""
return [next(self.generator) for _ in range(n)]

def take_to_list(self, stop: int, start: int = 0, step: int = 1) -> List[int]:
"""
Takes n generated figurate numbers from the sequence and returns them as a list.
Parameters
----------
stop : int
Ending position.
start : int
Start position.
step : int
Interval between elements
Returns
-------
list
List of the first n generated figurate numbers.
"""
return list(islice(self.generator, start, stop, step))

def take_to_array(self, stop: int, start: int = 0, step: int = 1) -> array:
"""
Takes n generated figurate numbers from the sequence and returns them as an array.
Parameters
----------
stop : int
Number of elements to take.
start : int
Number of elements to take.
step : int
I between elements
Returns
-------
array('i')
Array of double float containing the first n generated figurate numbers.
"""
return array('d', islice(self.generator, start, stop, step))

def take_to_tuple(self, stop: int, start: int = 0, step: int = 1) -> Tuple[int, ...]:
"""
Takes n generated figurate numbers from the sequence and returns them as a tuple.
Parameters
----------
stop : int
Ending position.
start : int
Start position.
step : int
I between elements
Returns
-------
tuple
Tuple of the first n generated figurate numbers.
"""
return tuple(islice(self.generator, start, stop, step))

def pick(self, n: int) -> int:
"""
Pick one figurate number at index n.
Parameters
----------
n : int
Index in the generated sequence, start at 0.
Returns
-------
int
Number selected by index in the generated sequence.
"""
return next(islice(self.generator, n, None))

0 comments on commit 4f05798

Please sign in to comment.