Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Mojo 0.6 port, and first pass at traits implementation. #11

Merged
merged 11 commits into from
Dec 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ jobs:

- name: "Install mojo"
run: |
curl https://get.modular.com | MODULAR_AUTH=${{ secrets.MODULAR_AUTH }} sh -
modular auth ${{ secrets.MODULAR_AUTH }}
curl https://get.modular.com | sh - && \
modular auth ${{secrets.MODULAR_AUTH}} && \
modular install mojo

- name: "Setup conda env (geo-features)"
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ install-py-packages:
conda env create -p venv --file environment.yml

clean:
rm -rf ~/.modular/.mojo_cache
rm -rf ~/.modular/.mojo_cache build/geo_features.mojopkg

test:
pytest -W error
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ If you are interested in contributing or discussing, please first contact me by

## requirements

- [Mojo](https://github.com/modularml/mojo) >= 0.5.0
- [Mojo](https://github.com/modularml/mojo) >= 0.6
- [Python](https://www.python.org/) >= 3.9
- [Conda](https://docs.conda.io/en/latest/)

Expand Down
Binary file added docs/docstrings.monopic
Binary file not shown.
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ dependencies:
- pip:
- geoarrow-pyarrow
- geoarrow-pandas
- git+https://github.com/guidorice/mojo-pytest.git@v0.2.0
- git+https://github.com/guidorice/mojo-pytest.git@v0.6.0
22 changes: 11 additions & 11 deletions geo_features/__init__.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
Core Geometric / Geographic structs and aliases.
"""

from geo_features.geom.envelope import (
Envelope,
Envelope2,
EnvelopeM,
EnvelopeZ,
EnvelopeZM,
)
from geo_features.geom.layout import Layout
from geo_features.geom.line_string import LineString
from geo_features.geom.multi_point import MultiPoint
from geo_features.geom.point import Point, Point2, PointZ, PointM, PointZM
# from geo_features.geom.envelope import (
# Envelope,
# Envelope2,
# EnvelopeM,
# EnvelopeZ,
# EnvelopeZM,
# )
# from geo_features.geom.layout import Layout
# from geo_features.geom.line_string import LineString
# from geo_features.geom.multi_point import MultiPoint
# from geo_features.geom.point import Point, Point2, PointZ, PointM, PointZM
13 changes: 8 additions & 5 deletions geo_features/geom/__init__.mojo
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from .point import Point, Point2, PointM, PointZ, PointZM
from .envelope import Envelope, Envelope2, EnvelopeZ, EnvelopeM, EnvelopeZM
from .layout import Layout
from .line_string import LineString
from .multi_point import MultiPoint
# from .point import Point
# from .envelope import Envelope
# from .layout import Layout
# from .enums import CoordDims
# from .traits import *

# # from .line_string import *
# # from .multi_point import *
29 changes: 29 additions & 0 deletions geo_features/geom/empty.mojo
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from math import nan, isnan
from math.limit import max_finite


@always_inline
fn empty_value[dtype: DType]() -> SIMD[dtype, 1]:
"""
Define a special value to mark empty slots or dimensions in structs. Required because SIMD must be power of two.
"""

@parameter
if dtype.is_floating_point():
return nan[dtype]()
else:
return max_finite[dtype]()


@always_inline
fn is_empty[dtype: DType, simd_width: Int](value: SIMD[dtype, simd_width]) -> Bool:
"""
Check for empty value. Note: NaN cannot be compared by equality. This helper function calls isnan() if the dtype
is floating point.
"""

@parameter
if dtype.is_floating_point():
return isnan[dtype, simd_width](value)
else:
return value == max_finite[dtype]()
69 changes: 69 additions & 0 deletions geo_features/geom/enums.mojo
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
@value
@register_passable("trivial")
struct CoordDims(Stringable, Sized):
"""
Enum for encoding the OGC/WKT variants of Points.
"""

# TODO: use a real enum here, when mojo supports.

var value: SIMD[DType.uint8, 1]

alias Point = CoordDims(100)
"""
2 dimensional Point.
"""
alias PointZ = CoordDims(101)
"""
3 dimensional Point, has height or altitude (Z).
"""
alias PointM = CoordDims(102)
"""
3 dimensional Point, has measure (M).
"""
alias PointZM = CoordDims(103)
"""
4 dimensional Point, has height and measure (ZM)
"""

alias PointND = CoordDims(104)
"""
N-dimensional Point, number of dimensions from constructor.
"""

fn __eq__(self, other: Self) -> Bool:
return self.value == other.value

fn __ne__(self, other: Self) -> Bool:
return not self.__eq__(other)

fn __str__(self) -> String:
"""
Convert to string, using WKT point variants.
"""
if self == CoordDims.Point:
return "Point"
elif self == CoordDims.PointZ:
return "Point Z"
elif self == CoordDims.PointM:
return "Point M"
elif self == CoordDims.PointZM:
return "Point ZM"
else:
return "Point ND"

fn __len__(self) -> Int:
if self == CoordDims.Point:
return 2
elif self == CoordDims.PointM or self == CoordDims.PointZ:
return 3
elif self == CoordDims.PointZM:
return 4
else:
return self.value.to_int()

fn has_height(self) -> Bool:
return (self == CoordDims.PointZ) or (self == CoordDims.PointZM)

fn has_measure(self) -> Bool:
return (self == CoordDims.PointM) or (self == CoordDims.PointZM)
Loading