Skip to content
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,355 changes: 4,192 additions & 163 deletions pixi.lock

Large diffs are not rendered by default.

43 changes: 27 additions & 16 deletions pixi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,28 @@ channels = [
platforms = ["osx-arm64", "linux-64"]
preview = ["pixi-build"]

[dependencies]
modular = ">=26.2.0.dev2026022717,<27"
numojo = { git = "https://github.com/shivasankarka/NuMojo.git", branch = "pre-0.9"}

[feature.test.dependencies]
python = ">=3.13,<3.14"
scipy = ">=1.14"

[feature.test.tasks]
t = "clear && pixi run --environment test package && bash ./tests/test_all.sh"
test = "pixi run --environment test package && bash ./tests/test_all.sh"

[environments]
test = ["test"]

[tasks]
format = "mojo format ./scijo && mojo format ./tests && mojo format ./benchmark"
tests = "mojo package scijo && cp scijo.mojopkg tests/ && bash tests/test_all.sh"
package = "mojo package scijo && cp scijo.mojopkg tests/"
final = "pixi run format && mojo package scijo && cp scijo.mojopkg tests/ && bash tests/test_all.sh"
build = "mojo build"

[package]
name = "scijo"
version = "0.2.0"
Expand All @@ -20,23 +42,12 @@ backend = { name = "pixi-build-mojo", version = "0.*"}
name = "scijo"

[package.host-dependencies]
modular = ">=26.2.0.dev2026021805,<27"
modular = ">=26.2.0.dev2026022717,<27"

[package.build-dependencies]
modular = ">=26.2.0.dev2026021805,<27"
numojo = { git = "https://github.com/shivasankarka/NuMojo.git", branch = "refcounting"}
modular = ">=26.2.0.dev2026022717,<27"
numojo = { git = "https://github.com/shivasankarka/NuMojo.git", branch = "pre-0.9"}

[package.run-dependencies]
modular = ">=26.2.0.dev2026021805,<27"
numojo = { git = "https://github.com/shivasankarka/NuMojo.git", branch = "refcounting"}

[dependencies]
modular = ">=26.2.0.dev2026021805,<27"
numojo = { git = "https://github.com/shivasankarka/NuMojo.git", branch = "refcounting"}
python = ">=3.14.3,<3.15"

[tasks]
format = "mojo format ./scijo && mojo format ./tests && mojo format ./benchmark"
tests = "pixi run package && bash tests/test_all.sh"
build = "mojo build"
package = "mojo package scijo && cp scijo.mojopkg tests/"
modular = ">=26.2.0.dev2026022717,<27"
numojo = { git = "https://github.com/shivasankarka/NuMojo.git", branch = "pre-0.9"}
53 changes: 4 additions & 49 deletions scijo/__init__.mojo
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# ===----------------------------------------------------------------------=== #
# Scijo: A Scientific Computing Library for Mojo
# Scijo: A Scientific Computation Library for Mojo
# Distributed under the Apache 2.0 License with LLVM Exceptions.
# See LICENSE and the LLVM License for more information.
# https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/blob/main/LICENSE
# https://llvm.org/LICENSE.txt
# ===----------------------------------------------------------------------=== #
"""
SciJo Top-Level Package (`numojo`)
SciJo Top-Level Package (`scijo`)
==================================

Welcome to SciJo, a scientific computing library built for the Mojo programming language.
Welcome to SciJo, a scientific computation library built for the Mojo programming language.

This top-level package exposes the core components of SciJo, including array types, error handling, and type definitions,
as well as a suite of modules for advanced numerical tasks.
Expand All @@ -26,50 +26,5 @@ Available Modules
Explore the documentation for each module to get started with scientific computing in Mojo using SciJo.
"""

from numojo.prelude import *
from numojo.core.error import NumojoError
from numojo.core import NDArray, Item, NDArrayShape, NDArrayStrides, Shape

from numojo.core import (
i8,
i64,
i128,
i256,
int,
u8,
u16,
u32,
u64,
u128,
u256,
uint,
bf16,
f16,
f32,
f64,
boolean,
)

from numojo.core.type_aliases import CScalar, ComplexScalar
from numojo.core import ComplexDType

from numojo.core import (
ComplexSIMD,
ci8,
ci64,
ci128,
ci256,
cint,
cu8,
cu16,
cu32,
cu64,
cu128,
cu256,
cuint,
cbf16,
cf16,
cf32,
cf64,
cboolean,
cinvalid,
)
28 changes: 27 additions & 1 deletion scijo/constants/__init__.mojo
Original file line number Diff line number Diff line change
@@ -1,2 +1,28 @@
from .codata import physical_constants
# ===----------------------------------------------------------------------=== #
# Scijo: Constants
# Distributed under the Apache 2.0 License with LLVM Exceptions.
# See LICENSE and the LLVM License for more information.
# https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/blob/main/LICENSE
# https://llvm.org/LICENSE.txt
# ===----------------------------------------------------------------------=== #
"""Constants Module (scijo.constants)

The `constants` module provides a collection of physical and mathematical constants.
"""

from .codata import (
physical_constants,
)
from .constants import *
from .utils import (
value,
list_all_constants,
get_constant_tuple,
find,
value,
unit,
precision,
nulambda,
lambdanu,
convert_temperature,
)
161 changes: 26 additions & 135 deletions scijo/constants/codata.mojo
Original file line number Diff line number Diff line change
@@ -1,34 +1,36 @@
# ===----------------------------------------------------------------------=== #
# Scijo: CODATA Physical Constants
# Distributed under the Apache 2.0 License with LLVM Exceptions.
# See LICENSE and the LLVM License for more information.
# https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/blob/main/LICENSE
# https://llvm.org/LICENSE.txt
# ===----------------------------------------------------------------------=== #
"""
CODATA Physical Constants Module

This module provides access to the CODATA 2022 recommended values of fundamental
physical constants as published by the Committee on Data for Science and Technology.
Provides access to the CODATA 2022 recommended values for fundamental
physical constants. Constants are stored in a global dictionary, similar to
SciPy's constants module.

The constants are organized in a global dictionary structure following the same
format as SciPy's constants module, ensuring compatibility and familiarity for
scientific computing applications.
Examples:
```mojo
import scijo.constants as const

Author: Shivasankar K.A
Version: 0.1.0
Date: July 2025

Usage:
The constants can be accessed through the global dictionary and used in
scientific calculations requiring precise physical constants.
var c = const.value("speed_of_light_in_vacuum")
var h = const.value("Planck_constant")
var e = const.value("elementary_charge")
```

References:
- CODATA 2022 Internationally Recommended Values
- CODATA 2022 Recommended Values
- https://github.com/scipy/scipy/blob/main/scipy/constants/_codata.py

Note:
This implementation is based on the official CODATA 2022 adjustment of
fundamental physical constants, ensuring the highest accuracy for
scientific computations.
Based on the official CODATA 2022 adjustment for maximum accuracy.
"""

from builtin.value import materialize

from numojo.core import f64
# ===----------------------------------------------------------------------=== #
# Data structure for physical constants
# ===----------------------------------------------------------------------=== #


struct PhysicalConstant[dtype: DType = DType.float64](
Expand Down Expand Up @@ -72,6 +74,10 @@ struct PhysicalConstant[dtype: DType = DType.float64](
print("Error writing to writer: ", e)


# ===----------------------------------------------------------------------=== #
# Global dictionary of physical constants (CODATA 2022 recommended values)
# ===----------------------------------------------------------------------=== #

comptime physical_constants: Dict[String, PhysicalConstant[f64]] = {
"speed_of_light_in_vacuum": PhysicalConstant[f64](
299792458.0, "m s^-1", 0.0
Expand Down Expand Up @@ -374,118 +380,3 @@ comptime physical_constants: Dict[String, PhysicalConstant[f64]] = {
1.920155716e-10, "m", 3.2e-18
),
}


fn value(key: String) raises -> Scalar[DType.float64]:
"""
Get the value of a physical constant.

Args:
key: Name of the physical constant.

Returns:
The numerical value of the constant.
"""
var physical_constants = materialize[physical_constants]()
if key in physical_constants:
return physical_constants[key].value
else:
print("Warning: Unknown constant '" + key + "'")
return 0.0


fn unit(key: String) raises -> String:
"""
Get the unit of a physical constant.

Args:
key: Name of the physical constant.

Returns:
The unit string of the constant.
"""
var physical_constants = materialize[physical_constants]()
if key in physical_constants:
return physical_constants[key].unit
else:
print("Warning: Unknown constant '" + key + "'")
return ""


fn precision(key: String) raises -> Scalar[DType.float64]:
"""
Get the relative precision (uncertainty/value) of a physical constant.

Args:
key: Name of the physical constant.

Returns:
The relative precision of the constant.
"""
var physical_constants = materialize[physical_constants]()
if key in physical_constants:
var constant = physical_constants[key]
if constant.value != 0.0:
return constant.uncertainty / constant.value
else:
return 0.0
else:
print("Warning: Unknown constant '" + key + "'")
return 0.0


fn find(substring: String = "") raises -> List[String]:
"""
Find physical constants containing a substring in their name.

Args:
substring: Substring to search for (empty returns all constants).

Returns:
List of constant names containing the substring.
"""
var physical_constants = materialize[physical_constants]()
var result = List[String]()

for item in physical_constants.items():
var key = item.key
if substring == "" or substring in key:
result.append(key)

return result^


# Additional helper functions for common access patterns
fn get_constant_tuple(
key: String,
) raises -> Tuple[Scalar[DType.float64], String, Scalar[DType.float64]]:
"""
Get a physical constant as a tuple (value, unit, uncertainty).

Args:
key: Name of the physical constant.

Returns:
Tuple containing (value, unit, uncertainty).
"""
var physical_constants = materialize[physical_constants]()
if key in physical_constants:
var constant = physical_constants[key]
return (constant.value, constant.unit, constant.uncertainty)
else:
print("Warning: Unknown constant '" + key + "'")
return (0.0, "", 0.0)


fn list_all_constants() raises -> List[String]:
"""
Get a list of all available physical constant names.

Returns:
List of all constant names in the database.
"""
var physical_constants = materialize[physical_constants]()
var result = List[String]()
for item in physical_constants.items():
result.append(item.key)
return result^
Loading