pyroid 0.2.5__tar.gz → 0.2.7__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pyroid-0.2.5 → pyroid-0.2.7}/.gitignore +1 -0
- {pyroid-0.2.5 → pyroid-0.2.7}/Cargo.lock +1 -1
- {pyroid-0.2.5 → pyroid-0.2.7}/Cargo.toml +1 -1
- {pyroid-0.2.5 → pyroid-0.2.7}/PKG-INFO +1 -1
- {pyroid-0.2.5 → pyroid-0.2.7}/pyproject.toml +1 -1
- {pyroid-0.2.5 → pyroid-0.2.7}/python/pyroid/__init__.py +9 -12
- pyroid-0.2.7/python/pyroid/core/__init__.py +78 -0
- pyroid-0.2.7/python/pyroid/data/__init__.py +99 -0
- pyroid-0.2.7/python/pyroid/image/__init__.py +16 -0
- pyroid-0.2.7/python/pyroid/image/basic/__init__.py +133 -0
- pyroid-0.2.7/python/pyroid/io/__init__.py +139 -0
- pyroid-0.2.7/python/pyroid/math/__init__.py +141 -0
- pyroid-0.2.7/python/pyroid/math/stats.py +108 -0
- pyroid-0.2.7/python/pyroid/ml/__init__.py +16 -0
- pyroid-0.2.7/python/pyroid/ml/basic/__init__.py +254 -0
- pyroid-0.2.7/python/pyroid/text/__init__.py +111 -0
- {pyroid-0.2.5 → pyroid-0.2.7}/src/core/config.rs +6 -2
- {pyroid-0.2.5 → pyroid-0.2.7}/src/core/error.rs +22 -21
- {pyroid-0.2.5 → pyroid-0.2.7}/src/core/types.rs +5 -1
- pyroid-0.2.7/test_pyroid.py +72 -0
- pyroid-0.2.5/python/pyroid/core/__init__.py +0 -48
- pyroid-0.2.5/python/pyroid/data/__init__.py +0 -40
- pyroid-0.2.5/python/pyroid/io/__init__.py +0 -43
- pyroid-0.2.5/python/pyroid/math/__init__.py +0 -51
- {pyroid-0.2.5 → pyroid-0.2.7}/.github/workflows/publish.yml +0 -0
- {pyroid-0.2.5 → pyroid-0.2.7}/.github/workflows/semantic-release.yml +0 -0
- {pyroid-0.2.5 → pyroid-0.2.7}/README.md +0 -0
- {pyroid-0.2.5 → pyroid-0.2.7}/benchmarks/README.md +0 -0
- {pyroid-0.2.5 → pyroid-0.2.7}/benchmarks/README_update.md +0 -0
- {pyroid-0.2.5 → pyroid-0.2.7}/benchmarks/__init__.py +0 -0
- {pyroid-0.2.5 → pyroid-0.2.7}/benchmarks/benchmark_plan.md +0 -0
- {pyroid-0.2.5 → pyroid-0.2.7}/benchmarks/core/__init__.py +0 -0
- {pyroid-0.2.5 → pyroid-0.2.7}/benchmarks/core/benchmark.py +0 -0
- {pyroid-0.2.5 → pyroid-0.2.7}/benchmarks/core/reporter.py +0 -0
- {pyroid-0.2.5 → pyroid-0.2.7}/benchmarks/core/visualizer.py +0 -0
- {pyroid-0.2.5 → pyroid-0.2.7}/benchmarks/demo.py +0 -0
- {pyroid-0.2.5 → pyroid-0.2.7}/benchmarks/generate_notebook.py +0 -0
- {pyroid-0.2.5 → pyroid-0.2.7}/benchmarks/pyroid_benchmarks.ipynb +0 -0
- {pyroid-0.2.5 → pyroid-0.2.7}/benchmarks/run_benchmarks.py +0 -0
- {pyroid-0.2.5 → pyroid-0.2.7}/benchmarks/suites/__init__.py +0 -0
- {pyroid-0.2.5 → pyroid-0.2.7}/benchmarks/suites/async_benchmarks.py +0 -0
- {pyroid-0.2.5 → pyroid-0.2.7}/benchmarks/suites/data_benchmarks.py +0 -0
- {pyroid-0.2.5 → pyroid-0.2.7}/benchmarks/suites/math_benchmarks.py +0 -0
- {pyroid-0.2.5 → pyroid-0.2.7}/benchmarks/suites/scenarios/__init__.py +0 -0
- {pyroid-0.2.5 → pyroid-0.2.7}/benchmarks/suites/scenarios/data_pipeline.py +0 -0
- {pyroid-0.2.5 → pyroid-0.2.7}/benchmarks/suites/scenarios/scientific_computing.py +0 -0
- {pyroid-0.2.5 → pyroid-0.2.7}/benchmarks/suites/scenarios/text_processing.py +0 -0
- {pyroid-0.2.5 → pyroid-0.2.7}/benchmarks/suites/scenarios/web_scraping.py +0 -0
- {pyroid-0.2.5 → pyroid-0.2.7}/benchmarks/suites/string_benchmarks.py +0 -0
- {pyroid-0.2.5 → pyroid-0.2.7}/build.rs +0 -0
- {pyroid-0.2.5 → pyroid-0.2.7}/docs/api/dataframe_ops.md +0 -0
- {pyroid-0.2.5 → pyroid-0.2.7}/docs/api/image_ops.md +0 -0
- {pyroid-0.2.5 → pyroid-0.2.7}/docs/api/index.md +0 -0
- {pyroid-0.2.5 → pyroid-0.2.7}/docs/api/io_ops.md +0 -0
- {pyroid-0.2.5 → pyroid-0.2.7}/docs/api/ml_ops.md +0 -0
- {pyroid-0.2.5 → pyroid-0.2.7}/docs/api/text_nlp_ops.md +0 -0
- {pyroid-0.2.5 → pyroid-0.2.7}/docs/guides/getting_started.md +0 -0
- {pyroid-0.2.5 → pyroid-0.2.7}/docs/guides/index.md +0 -0
- {pyroid-0.2.5 → pyroid-0.2.7}/docs/guides/performance.md +0 -0
- {pyroid-0.2.5 → pyroid-0.2.7}/docs/index.md +0 -0
- {pyroid-0.2.5 → pyroid-0.2.7}/examples/async_examples.py +0 -0
- {pyroid-0.2.5 → pyroid-0.2.7}/examples/data_examples.py +0 -0
- {pyroid-0.2.5 → pyroid-0.2.7}/examples/dataframe_examples.py +0 -0
- {pyroid-0.2.5 → pyroid-0.2.7}/examples/image_examples.py +0 -0
- {pyroid-0.2.5 → pyroid-0.2.7}/examples/io_examples.py +0 -0
- {pyroid-0.2.5 → pyroid-0.2.7}/examples/math_examples.py +0 -0
- {pyroid-0.2.5 → pyroid-0.2.7}/examples/ml_examples.py +0 -0
- {pyroid-0.2.5 → pyroid-0.2.7}/examples/requirements.txt +0 -0
- {pyroid-0.2.5 → pyroid-0.2.7}/examples/string_examples.py +0 -0
- {pyroid-0.2.5 → pyroid-0.2.7}/examples/test_async_file.txt +0 -0
- {pyroid-0.2.5 → pyroid-0.2.7}/examples/text_nlp_examples.py +0 -0
- {pyroid-0.2.5 → pyroid-0.2.7}/python/__init__.py +0 -0
- {pyroid-0.2.5 → pyroid-0.2.7}/python/tests/__init__.py +0 -0
- {pyroid-0.2.5 → pyroid-0.2.7}/python/tests/test_basic.py +0 -0
- {pyroid-0.2.5 → pyroid-0.2.7}/setup.py +0 -0
- {pyroid-0.2.5 → pyroid-0.2.7}/src/async_ops.rs +0 -0
- {pyroid-0.2.5 → pyroid-0.2.7}/src/core/conversion.rs +0 -0
- {pyroid-0.2.5 → pyroid-0.2.7}/src/core/mod.rs +0 -0
- {pyroid-0.2.5 → pyroid-0.2.7}/src/data/collections.rs +0 -0
- {pyroid-0.2.5 → pyroid-0.2.7}/src/data/dataframe.rs +0 -0
- {pyroid-0.2.5 → pyroid-0.2.7}/src/data/mod.rs +0 -0
- {pyroid-0.2.5 → pyroid-0.2.7}/src/data_ops.rs +0 -0
- {pyroid-0.2.5 → pyroid-0.2.7}/src/dataframe_ops.rs +0 -0
- {pyroid-0.2.5 → pyroid-0.2.7}/src/image/basic.rs +0 -0
- {pyroid-0.2.5 → pyroid-0.2.7}/src/image/mod.rs +0 -0
- {pyroid-0.2.5 → pyroid-0.2.7}/src/image_ops.rs +0 -0
- {pyroid-0.2.5 → pyroid-0.2.7}/src/io/async_io.rs +0 -0
- {pyroid-0.2.5 → pyroid-0.2.7}/src/io/file.rs +0 -0
- {pyroid-0.2.5 → pyroid-0.2.7}/src/io/mod.rs +0 -0
- {pyroid-0.2.5 → pyroid-0.2.7}/src/io/network.rs +0 -0
- {pyroid-0.2.5 → pyroid-0.2.7}/src/io_ops.rs +0 -0
- {pyroid-0.2.5 → pyroid-0.2.7}/src/lib.rs +0 -0
- {pyroid-0.2.5 → pyroid-0.2.7}/src/math/matrix.rs +0 -0
- {pyroid-0.2.5 → pyroid-0.2.7}/src/math/mod.rs +0 -0
- {pyroid-0.2.5 → pyroid-0.2.7}/src/math/stats.rs +0 -0
- {pyroid-0.2.5 → pyroid-0.2.7}/src/math/vector.rs +0 -0
- {pyroid-0.2.5 → pyroid-0.2.7}/src/math_ops.rs +0 -0
- {pyroid-0.2.5 → pyroid-0.2.7}/src/ml/basic.rs +0 -0
- {pyroid-0.2.5 → pyroid-0.2.7}/src/ml/mod.rs +0 -0
- {pyroid-0.2.5 → pyroid-0.2.7}/src/ml_ops.rs +0 -0
- {pyroid-0.2.5 → pyroid-0.2.7}/src/string_ops.rs +0 -0
- {pyroid-0.2.5 → pyroid-0.2.7}/src/text/mod.rs +0 -0
- {pyroid-0.2.5 → pyroid-0.2.7}/src/text_nlp_ops.rs +0 -0
- {pyroid-0.2.5 → pyroid-0.2.7}/src/utils/conversions.rs +0 -0
- {pyroid-0.2.5 → pyroid-0.2.7}/src/utils/mod.rs +0 -0
|
@@ -25,17 +25,14 @@ Examples:
|
|
|
25
25
|
"""
|
|
26
26
|
|
|
27
27
|
# Import core functionality
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
ConfigContext,
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
MemoryError,
|
|
36
|
-
ConversionError,
|
|
37
|
-
IoError,
|
|
38
|
-
)
|
|
28
|
+
try:
|
|
29
|
+
# Try to import directly from the pyroid module
|
|
30
|
+
from .pyroid import Config, ConfigContext, SharedData
|
|
31
|
+
from .pyroid import PyroidError, InputError, ComputationError, MemoryError, ConversionError, IoError
|
|
32
|
+
except ImportError:
|
|
33
|
+
# Fallback to importing from the core module
|
|
34
|
+
from .core import Config, ConfigContext, SharedData
|
|
35
|
+
from .core import PyroidError, InputError, ComputationError, MemoryError, ConversionError, IoError
|
|
39
36
|
|
|
40
37
|
# Import submodules
|
|
41
38
|
from . import core
|
|
@@ -64,7 +61,7 @@ def config(**kwargs):
|
|
|
64
61
|
return ConfigContext(Config(kwargs))
|
|
65
62
|
|
|
66
63
|
# Version information
|
|
67
|
-
__version__ = "
|
|
64
|
+
__version__ = "0.2.5"
|
|
68
65
|
|
|
69
66
|
__all__ = [
|
|
70
67
|
# Core classes
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Pyroid Core Module
|
|
3
|
+
=================
|
|
4
|
+
|
|
5
|
+
This module provides core functionality and shared utilities for Pyroid.
|
|
6
|
+
|
|
7
|
+
Classes:
|
|
8
|
+
Config: Configuration management
|
|
9
|
+
ConfigContext: Context manager for temporary configuration
|
|
10
|
+
SharedData: Wrapper for shared data
|
|
11
|
+
|
|
12
|
+
Exceptions:
|
|
13
|
+
PyroidError: Base exception for all Pyroid errors
|
|
14
|
+
InputError: Input validation error
|
|
15
|
+
ComputationError: Computation error
|
|
16
|
+
MemoryError: Memory error
|
|
17
|
+
ConversionError: Type conversion error
|
|
18
|
+
IoError: I/O error
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
# Try to import directly from the pyroid module
|
|
22
|
+
try:
|
|
23
|
+
from ..pyroid import Config, ConfigContext, SharedData
|
|
24
|
+
from ..pyroid import PyroidError, InputError, ComputationError, MemoryError, ConversionError, IoError
|
|
25
|
+
except ImportError:
|
|
26
|
+
# Fallback to importing from the core module
|
|
27
|
+
try:
|
|
28
|
+
from ..pyroid.core import Config, ConfigContext, SharedData
|
|
29
|
+
from ..pyroid.core.error import PyroidError, InputError, ComputationError, MemoryError, ConversionError, IoError
|
|
30
|
+
except ImportError:
|
|
31
|
+
# If all else fails, create dummy classes for documentation purposes
|
|
32
|
+
class Config:
|
|
33
|
+
"""Configuration management class (not available)."""
|
|
34
|
+
pass
|
|
35
|
+
|
|
36
|
+
class ConfigContext:
|
|
37
|
+
"""Context manager for temporary configuration (not available)."""
|
|
38
|
+
pass
|
|
39
|
+
|
|
40
|
+
class SharedData:
|
|
41
|
+
"""Wrapper for shared data (not available)."""
|
|
42
|
+
pass
|
|
43
|
+
|
|
44
|
+
class PyroidError(Exception):
|
|
45
|
+
"""Base exception for all Pyroid errors (not available)."""
|
|
46
|
+
pass
|
|
47
|
+
|
|
48
|
+
class InputError(PyroidError):
|
|
49
|
+
"""Input validation error (not available)."""
|
|
50
|
+
pass
|
|
51
|
+
|
|
52
|
+
class ComputationError(PyroidError):
|
|
53
|
+
"""Computation error (not available)."""
|
|
54
|
+
pass
|
|
55
|
+
|
|
56
|
+
class MemoryError(PyroidError):
|
|
57
|
+
"""Memory error (not available)."""
|
|
58
|
+
pass
|
|
59
|
+
|
|
60
|
+
class ConversionError(PyroidError):
|
|
61
|
+
"""Type conversion error (not available)."""
|
|
62
|
+
pass
|
|
63
|
+
|
|
64
|
+
class IoError(PyroidError):
|
|
65
|
+
"""I/O error (not available)."""
|
|
66
|
+
pass
|
|
67
|
+
|
|
68
|
+
__all__ = [
|
|
69
|
+
'Config',
|
|
70
|
+
'ConfigContext',
|
|
71
|
+
'SharedData',
|
|
72
|
+
'PyroidError',
|
|
73
|
+
'InputError',
|
|
74
|
+
'ComputationError',
|
|
75
|
+
'MemoryError',
|
|
76
|
+
'ConversionError',
|
|
77
|
+
'IoError',
|
|
78
|
+
]
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Pyroid Data Module
|
|
3
|
+
================
|
|
4
|
+
|
|
5
|
+
This module provides high-performance data operations.
|
|
6
|
+
|
|
7
|
+
Classes:
|
|
8
|
+
DataFrame: DataFrame class for data operations
|
|
9
|
+
|
|
10
|
+
Functions:
|
|
11
|
+
filter: Filter a list using a predicate function in parallel
|
|
12
|
+
map: Map a function over a list in parallel
|
|
13
|
+
reduce: Reduce a list using a binary function
|
|
14
|
+
sort: Sort a list in parallel
|
|
15
|
+
apply: Apply a function to a DataFrame
|
|
16
|
+
groupby_aggregate: Group by and aggregate a DataFrame
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
# Try to import directly from the pyroid module
|
|
20
|
+
try:
|
|
21
|
+
from ..pyroid import (
|
|
22
|
+
# DataFrame operations
|
|
23
|
+
DataFrame,
|
|
24
|
+
apply,
|
|
25
|
+
groupby_aggregate,
|
|
26
|
+
|
|
27
|
+
# Collection operations
|
|
28
|
+
filter,
|
|
29
|
+
map,
|
|
30
|
+
reduce,
|
|
31
|
+
sort,
|
|
32
|
+
)
|
|
33
|
+
except ImportError:
|
|
34
|
+
# Fallback to importing from the data module
|
|
35
|
+
try:
|
|
36
|
+
from ..pyroid.data import (
|
|
37
|
+
# DataFrame operations
|
|
38
|
+
DataFrame,
|
|
39
|
+
apply,
|
|
40
|
+
groupby_aggregate,
|
|
41
|
+
|
|
42
|
+
# Collection operations
|
|
43
|
+
filter,
|
|
44
|
+
map,
|
|
45
|
+
reduce,
|
|
46
|
+
sort,
|
|
47
|
+
)
|
|
48
|
+
except ImportError:
|
|
49
|
+
# If all else fails, create dummy classes and functions for documentation purposes
|
|
50
|
+
class DataFrame:
|
|
51
|
+
"""DataFrame class for data operations (not available)."""
|
|
52
|
+
def __init__(self, data=None):
|
|
53
|
+
self.data = data or {}
|
|
54
|
+
|
|
55
|
+
def __repr__(self):
|
|
56
|
+
return f"DataFrame({self.data})"
|
|
57
|
+
|
|
58
|
+
def apply(df, func, axis=0):
|
|
59
|
+
"""Apply a function to a DataFrame (not available)."""
|
|
60
|
+
return df
|
|
61
|
+
|
|
62
|
+
def groupby_aggregate(df, by, agg_dict):
|
|
63
|
+
"""Group by and aggregate a DataFrame (not available)."""
|
|
64
|
+
return df
|
|
65
|
+
|
|
66
|
+
def filter(items, predicate):
|
|
67
|
+
"""Filter a list using a predicate function (not available)."""
|
|
68
|
+
return [item for item in items if predicate(item)]
|
|
69
|
+
|
|
70
|
+
def map(items, func):
|
|
71
|
+
"""Map a function over a list (not available)."""
|
|
72
|
+
return [func(item) for item in items]
|
|
73
|
+
|
|
74
|
+
def reduce(items, func, initial=None):
|
|
75
|
+
"""Reduce a list using a binary function (not available)."""
|
|
76
|
+
if not items:
|
|
77
|
+
return initial
|
|
78
|
+
if initial is None:
|
|
79
|
+
result = items[0]
|
|
80
|
+
items = items[1:]
|
|
81
|
+
else:
|
|
82
|
+
result = initial
|
|
83
|
+
for item in items:
|
|
84
|
+
result = func(result, item)
|
|
85
|
+
return result
|
|
86
|
+
|
|
87
|
+
def sort(items, key=None, reverse=False):
|
|
88
|
+
"""Sort a list (not available)."""
|
|
89
|
+
return sorted(items, key=key, reverse=reverse)
|
|
90
|
+
|
|
91
|
+
__all__ = [
|
|
92
|
+
'DataFrame',
|
|
93
|
+
'apply',
|
|
94
|
+
'groupby_aggregate',
|
|
95
|
+
'filter',
|
|
96
|
+
'map',
|
|
97
|
+
'reduce',
|
|
98
|
+
'sort',
|
|
99
|
+
]
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Pyroid Image Module
|
|
3
|
+
================
|
|
4
|
+
|
|
5
|
+
This module provides high-performance image processing operations.
|
|
6
|
+
|
|
7
|
+
Submodules:
|
|
8
|
+
basic: Basic image processing operations
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
# Import submodules
|
|
12
|
+
from . import basic
|
|
13
|
+
|
|
14
|
+
__all__ = [
|
|
15
|
+
'basic',
|
|
16
|
+
]
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Pyroid Image Basic Module
|
|
3
|
+
======================
|
|
4
|
+
|
|
5
|
+
This module provides basic image processing operations.
|
|
6
|
+
|
|
7
|
+
Functions:
|
|
8
|
+
create_image: Create a new image
|
|
9
|
+
from_bytes: Create an image from raw bytes
|
|
10
|
+
to_grayscale: Convert an image to grayscale
|
|
11
|
+
resize: Resize an image
|
|
12
|
+
blur: Apply a blur filter to an image
|
|
13
|
+
adjust_brightness: Adjust the brightness of an image
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
# Try to import directly from the pyroid module
|
|
17
|
+
try:
|
|
18
|
+
from ...pyroid import (
|
|
19
|
+
# Image creation
|
|
20
|
+
create_image,
|
|
21
|
+
from_bytes,
|
|
22
|
+
|
|
23
|
+
# Image operations
|
|
24
|
+
Image,
|
|
25
|
+
)
|
|
26
|
+
except ImportError:
|
|
27
|
+
# Fallback to importing from the image module
|
|
28
|
+
try:
|
|
29
|
+
from ...pyroid.image import (
|
|
30
|
+
# Image creation
|
|
31
|
+
create_image,
|
|
32
|
+
from_bytes,
|
|
33
|
+
|
|
34
|
+
# Image operations
|
|
35
|
+
Image,
|
|
36
|
+
)
|
|
37
|
+
except ImportError:
|
|
38
|
+
# If all else fails, create dummy classes and functions for documentation purposes
|
|
39
|
+
class Image:
|
|
40
|
+
"""Image class for image processing operations (not available)."""
|
|
41
|
+
def __init__(self, width, height, channels):
|
|
42
|
+
self.width = width
|
|
43
|
+
self.height = height
|
|
44
|
+
self.channels = channels
|
|
45
|
+
self.data = bytearray(width * height * channels)
|
|
46
|
+
|
|
47
|
+
def __repr__(self):
|
|
48
|
+
return f"Image({self.width}, {self.height}, {self.channels})"
|
|
49
|
+
|
|
50
|
+
def set_pixel(self, x, y, color):
|
|
51
|
+
"""Set a pixel color."""
|
|
52
|
+
if 0 <= x < self.width and 0 <= y < self.height:
|
|
53
|
+
idx = (y * self.width + x) * self.channels
|
|
54
|
+
for i, c in enumerate(color[:self.channels]):
|
|
55
|
+
self.data[idx + i] = c
|
|
56
|
+
|
|
57
|
+
def get_pixel(self, x, y):
|
|
58
|
+
"""Get a pixel color."""
|
|
59
|
+
if 0 <= x < self.width and 0 <= y < self.height:
|
|
60
|
+
idx = (y * self.width + x) * self.channels
|
|
61
|
+
return list(self.data[idx:idx + self.channels])
|
|
62
|
+
return [0] * self.channels
|
|
63
|
+
|
|
64
|
+
def to_grayscale(self):
|
|
65
|
+
"""Convert to grayscale."""
|
|
66
|
+
if self.channels == 1:
|
|
67
|
+
return self
|
|
68
|
+
result = Image(self.width, self.height, 1)
|
|
69
|
+
for y in range(self.height):
|
|
70
|
+
for x in range(self.width):
|
|
71
|
+
color = self.get_pixel(x, y)
|
|
72
|
+
gray = int(0.299 * color[0] + 0.587 * color[1] + 0.114 * color[2])
|
|
73
|
+
result.set_pixel(x, y, [gray])
|
|
74
|
+
return result
|
|
75
|
+
|
|
76
|
+
def resize(self, width, height):
|
|
77
|
+
"""Resize the image."""
|
|
78
|
+
result = Image(width, height, self.channels)
|
|
79
|
+
x_ratio = self.width / width
|
|
80
|
+
y_ratio = self.height / height
|
|
81
|
+
for y in range(height):
|
|
82
|
+
for x in range(width):
|
|
83
|
+
src_x = int(x * x_ratio)
|
|
84
|
+
src_y = int(y * y_ratio)
|
|
85
|
+
result.set_pixel(x, y, self.get_pixel(src_x, src_y))
|
|
86
|
+
return result
|
|
87
|
+
|
|
88
|
+
def blur(self, radius):
|
|
89
|
+
"""Apply a blur filter."""
|
|
90
|
+
result = Image(self.width, self.height, self.channels)
|
|
91
|
+
for y in range(self.height):
|
|
92
|
+
for x in range(self.width):
|
|
93
|
+
r = min(radius, min(x, self.width - x - 1, y, self.height - y - 1))
|
|
94
|
+
count = 0
|
|
95
|
+
color_sum = [0] * self.channels
|
|
96
|
+
for dy in range(-r, r + 1):
|
|
97
|
+
for dx in range(-r, r + 1):
|
|
98
|
+
nx, ny = x + dx, y + dy
|
|
99
|
+
if 0 <= nx < self.width and 0 <= ny < self.height:
|
|
100
|
+
pixel = self.get_pixel(nx, ny)
|
|
101
|
+
for i in range(self.channels):
|
|
102
|
+
color_sum[i] += pixel[i]
|
|
103
|
+
count += 1
|
|
104
|
+
avg_color = [int(c / count) for c in color_sum]
|
|
105
|
+
result.set_pixel(x, y, avg_color)
|
|
106
|
+
return result
|
|
107
|
+
|
|
108
|
+
def adjust_brightness(self, factor):
|
|
109
|
+
"""Adjust the brightness."""
|
|
110
|
+
result = Image(self.width, self.height, self.channels)
|
|
111
|
+
for y in range(self.height):
|
|
112
|
+
for x in range(self.width):
|
|
113
|
+
color = self.get_pixel(x, y)
|
|
114
|
+
new_color = [min(255, int(c * factor)) for c in color]
|
|
115
|
+
result.set_pixel(x, y, new_color)
|
|
116
|
+
return result
|
|
117
|
+
|
|
118
|
+
def create_image(width, height, channels):
|
|
119
|
+
"""Create a new image."""
|
|
120
|
+
return Image(width, height, channels)
|
|
121
|
+
|
|
122
|
+
def from_bytes(data, width, height, channels):
|
|
123
|
+
"""Create an image from raw bytes."""
|
|
124
|
+
img = Image(width, height, channels)
|
|
125
|
+
img.data = bytearray(data[:width * height * channels])
|
|
126
|
+
return img
|
|
127
|
+
|
|
128
|
+
# Export the Image class and functions
|
|
129
|
+
__all__ = [
|
|
130
|
+
'Image',
|
|
131
|
+
'create_image',
|
|
132
|
+
'from_bytes',
|
|
133
|
+
]
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Pyroid I/O Module
|
|
3
|
+
===============
|
|
4
|
+
|
|
5
|
+
This module provides high-performance I/O operations.
|
|
6
|
+
|
|
7
|
+
Functions:
|
|
8
|
+
read_file: Read a file
|
|
9
|
+
write_file: Write a file
|
|
10
|
+
read_files: Read multiple files in parallel
|
|
11
|
+
get: HTTP GET request
|
|
12
|
+
post: HTTP POST request
|
|
13
|
+
sleep: Async sleep
|
|
14
|
+
read_file_async: Async read file
|
|
15
|
+
write_file_async: Async write file
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
# Try to import directly from the pyroid module
|
|
19
|
+
try:
|
|
20
|
+
from ..pyroid import (
|
|
21
|
+
# File operations
|
|
22
|
+
read_file,
|
|
23
|
+
write_file,
|
|
24
|
+
read_files,
|
|
25
|
+
|
|
26
|
+
# Network operations
|
|
27
|
+
get,
|
|
28
|
+
post,
|
|
29
|
+
|
|
30
|
+
# Async operations
|
|
31
|
+
sleep,
|
|
32
|
+
read_file_async,
|
|
33
|
+
write_file_async,
|
|
34
|
+
)
|
|
35
|
+
except ImportError:
|
|
36
|
+
# Fallback to importing from the io module
|
|
37
|
+
try:
|
|
38
|
+
from ..pyroid.io import (
|
|
39
|
+
# File operations
|
|
40
|
+
read_file,
|
|
41
|
+
write_file,
|
|
42
|
+
read_files,
|
|
43
|
+
|
|
44
|
+
# Network operations
|
|
45
|
+
get,
|
|
46
|
+
post,
|
|
47
|
+
|
|
48
|
+
# Async operations
|
|
49
|
+
sleep,
|
|
50
|
+
read_file_async,
|
|
51
|
+
write_file_async,
|
|
52
|
+
)
|
|
53
|
+
except ImportError:
|
|
54
|
+
# If all else fails, create dummy functions for documentation purposes
|
|
55
|
+
def read_file(path):
|
|
56
|
+
"""Read a file (not available)."""
|
|
57
|
+
try:
|
|
58
|
+
with open(path, 'r') as f:
|
|
59
|
+
return f.read()
|
|
60
|
+
except Exception as e:
|
|
61
|
+
return f"Error reading file: {e}"
|
|
62
|
+
|
|
63
|
+
def write_file(path, content):
|
|
64
|
+
"""Write a file (not available)."""
|
|
65
|
+
try:
|
|
66
|
+
with open(path, 'w') as f:
|
|
67
|
+
f.write(content)
|
|
68
|
+
return True
|
|
69
|
+
except Exception as e:
|
|
70
|
+
return f"Error writing file: {e}"
|
|
71
|
+
|
|
72
|
+
def read_files(paths):
|
|
73
|
+
"""Read multiple files in parallel (not available)."""
|
|
74
|
+
return {path: read_file(path) for path in paths}
|
|
75
|
+
|
|
76
|
+
def get(url, headers=None):
|
|
77
|
+
"""HTTP GET request (not available)."""
|
|
78
|
+
try:
|
|
79
|
+
import urllib.request
|
|
80
|
+
req = urllib.request.Request(url, headers=headers or {})
|
|
81
|
+
with urllib.request.urlopen(req) as response:
|
|
82
|
+
return response.read().decode('utf-8')
|
|
83
|
+
except Exception as e:
|
|
84
|
+
return f"Error making GET request: {e}"
|
|
85
|
+
|
|
86
|
+
def post(url, data=None, headers=None):
|
|
87
|
+
"""HTTP POST request (not available)."""
|
|
88
|
+
try:
|
|
89
|
+
import urllib.request
|
|
90
|
+
import json
|
|
91
|
+
if isinstance(data, dict):
|
|
92
|
+
data = json.dumps(data).encode('utf-8')
|
|
93
|
+
req = urllib.request.Request(url, data=data, headers=headers or {}, method='POST')
|
|
94
|
+
with urllib.request.urlopen(req) as response:
|
|
95
|
+
return response.read().decode('utf-8')
|
|
96
|
+
except Exception as e:
|
|
97
|
+
return f"Error making POST request: {e}"
|
|
98
|
+
|
|
99
|
+
async def sleep(seconds):
|
|
100
|
+
"""Async sleep (not available)."""
|
|
101
|
+
try:
|
|
102
|
+
import asyncio
|
|
103
|
+
await asyncio.sleep(seconds)
|
|
104
|
+
except Exception as e:
|
|
105
|
+
return f"Error sleeping: {e}"
|
|
106
|
+
|
|
107
|
+
async def read_file_async(path):
|
|
108
|
+
"""Async read file (not available)."""
|
|
109
|
+
try:
|
|
110
|
+
import aiofiles
|
|
111
|
+
async with aiofiles.open(path, 'r') as f:
|
|
112
|
+
return await f.read()
|
|
113
|
+
except ImportError:
|
|
114
|
+
return read_file(path)
|
|
115
|
+
except Exception as e:
|
|
116
|
+
return f"Error reading file asynchronously: {e}"
|
|
117
|
+
|
|
118
|
+
async def write_file_async(path, content):
|
|
119
|
+
"""Async write file (not available)."""
|
|
120
|
+
try:
|
|
121
|
+
import aiofiles
|
|
122
|
+
async with aiofiles.open(path, 'w') as f:
|
|
123
|
+
await f.write(content)
|
|
124
|
+
return True
|
|
125
|
+
except ImportError:
|
|
126
|
+
return write_file(path, content)
|
|
127
|
+
except Exception as e:
|
|
128
|
+
return f"Error writing file asynchronously: {e}"
|
|
129
|
+
|
|
130
|
+
__all__ = [
|
|
131
|
+
'read_file',
|
|
132
|
+
'write_file',
|
|
133
|
+
'read_files',
|
|
134
|
+
'get',
|
|
135
|
+
'post',
|
|
136
|
+
'sleep',
|
|
137
|
+
'read_file_async',
|
|
138
|
+
'write_file_async',
|
|
139
|
+
]
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Pyroid Math Module
|
|
3
|
+
================
|
|
4
|
+
|
|
5
|
+
This module provides high-performance mathematical operations.
|
|
6
|
+
|
|
7
|
+
Classes:
|
|
8
|
+
Vector: Vector class for mathematical operations
|
|
9
|
+
Matrix: Matrix class for mathematical operations
|
|
10
|
+
|
|
11
|
+
Functions:
|
|
12
|
+
sum: Sum a list of numbers in parallel
|
|
13
|
+
multiply: Matrix multiplication function
|
|
14
|
+
mean: Calculate the mean of a list of numbers
|
|
15
|
+
median: Calculate the median of a list of numbers
|
|
16
|
+
std: Calculate the standard deviation of a list of numbers
|
|
17
|
+
variance: Calculate the variance of a list of numbers
|
|
18
|
+
correlation: Calculate the correlation coefficient between two lists of numbers
|
|
19
|
+
describe: Calculate descriptive statistics for a list of numbers
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
# Try to import directly from the pyroid module
|
|
23
|
+
try:
|
|
24
|
+
from ..pyroid import (
|
|
25
|
+
# Vector operations
|
|
26
|
+
Vector,
|
|
27
|
+
sum,
|
|
28
|
+
|
|
29
|
+
# Matrix operations
|
|
30
|
+
Matrix,
|
|
31
|
+
multiply,
|
|
32
|
+
|
|
33
|
+
# Statistical operations
|
|
34
|
+
mean,
|
|
35
|
+
median,
|
|
36
|
+
std,
|
|
37
|
+
variance,
|
|
38
|
+
correlation,
|
|
39
|
+
describe,
|
|
40
|
+
)
|
|
41
|
+
except ImportError:
|
|
42
|
+
# Fallback to importing from the math module
|
|
43
|
+
try:
|
|
44
|
+
from ..pyroid.math import (
|
|
45
|
+
# Vector operations
|
|
46
|
+
Vector,
|
|
47
|
+
sum,
|
|
48
|
+
|
|
49
|
+
# Matrix operations
|
|
50
|
+
Matrix,
|
|
51
|
+
multiply,
|
|
52
|
+
|
|
53
|
+
# Statistical operations
|
|
54
|
+
mean,
|
|
55
|
+
median,
|
|
56
|
+
std,
|
|
57
|
+
variance,
|
|
58
|
+
correlation,
|
|
59
|
+
describe,
|
|
60
|
+
)
|
|
61
|
+
except ImportError:
|
|
62
|
+
# If all else fails, create dummy classes for documentation purposes
|
|
63
|
+
class Vector:
|
|
64
|
+
"""Vector class for mathematical operations (not available)."""
|
|
65
|
+
def __init__(self, values):
|
|
66
|
+
self.values = values
|
|
67
|
+
|
|
68
|
+
def __add__(self, other):
|
|
69
|
+
return self
|
|
70
|
+
|
|
71
|
+
def dot(self, other):
|
|
72
|
+
return 0
|
|
73
|
+
|
|
74
|
+
class Matrix:
|
|
75
|
+
"""Matrix class for mathematical operations (not available)."""
|
|
76
|
+
def __init__(self, values):
|
|
77
|
+
self.values = values
|
|
78
|
+
|
|
79
|
+
def __mul__(self, other):
|
|
80
|
+
return self
|
|
81
|
+
|
|
82
|
+
# Dummy functions
|
|
83
|
+
def sum(values):
|
|
84
|
+
"""Sum a list of numbers (not available)."""
|
|
85
|
+
return 0
|
|
86
|
+
|
|
87
|
+
def multiply(a, b):
|
|
88
|
+
"""Matrix multiplication function (not available)."""
|
|
89
|
+
return [[0]]
|
|
90
|
+
|
|
91
|
+
def mean(values):
|
|
92
|
+
"""Calculate the mean of a list of numbers (not available)."""
|
|
93
|
+
return 0
|
|
94
|
+
|
|
95
|
+
def median(values):
|
|
96
|
+
"""Calculate the median of a list of numbers (not available)."""
|
|
97
|
+
return 0
|
|
98
|
+
|
|
99
|
+
def std(values):
|
|
100
|
+
"""Calculate the standard deviation of a list of numbers (not available)."""
|
|
101
|
+
return 0
|
|
102
|
+
|
|
103
|
+
def variance(values):
|
|
104
|
+
"""Calculate the variance of a list of numbers (not available)."""
|
|
105
|
+
return 0
|
|
106
|
+
|
|
107
|
+
def correlation(x, y):
|
|
108
|
+
"""Calculate the correlation coefficient between two lists of numbers (not available)."""
|
|
109
|
+
return 0
|
|
110
|
+
|
|
111
|
+
def describe(values):
|
|
112
|
+
"""Calculate descriptive statistics for a list of numbers (not available)."""
|
|
113
|
+
return {}
|
|
114
|
+
|
|
115
|
+
# Import submodules
|
|
116
|
+
try:
|
|
117
|
+
from . import stats
|
|
118
|
+
except ImportError:
|
|
119
|
+
# Create a dummy stats module if it's not available
|
|
120
|
+
import types
|
|
121
|
+
stats = types.ModuleType('stats')
|
|
122
|
+
stats.mean = mean
|
|
123
|
+
stats.median = median
|
|
124
|
+
stats.calc_std = std
|
|
125
|
+
stats.variance = variance
|
|
126
|
+
stats.correlation = correlation
|
|
127
|
+
stats.describe = describe
|
|
128
|
+
|
|
129
|
+
__all__ = [
|
|
130
|
+
'Vector',
|
|
131
|
+
'sum',
|
|
132
|
+
'Matrix',
|
|
133
|
+
'multiply',
|
|
134
|
+
'mean',
|
|
135
|
+
'median',
|
|
136
|
+
'std',
|
|
137
|
+
'variance',
|
|
138
|
+
'correlation',
|
|
139
|
+
'describe',
|
|
140
|
+
'stats',
|
|
141
|
+
]
|