Dimension#

class saiunit.Dimension(dims)#

Store the exponents of the 7 basic SI unit dimensions.

Represents a physical dimension as a combination of the 7 SI base dimensions: length, mass, time, electric current, temperature, amount of substance, and luminous intensity.

Provides arithmetic operations appropriate to dimensions: multiplication, division, powers, and equality testing.

Parameters:

dims (sequence of float) – The exponents of the 7 basic SI unit dimensions, in order: [length, mass, time, current, temperature, substance, luminosity].

See also

get_or_create_dimension

Factory function (preferred over direct construction).

DIMENSIONLESS

Singleton for dimensionless quantities.

Notes

Users should not use this class directly. Use get_or_create_dimension instead, which ensures only one Dimension instance exists for every combination of exponents, allowing fast dimensionality checks with is.

Examples

>>> import saiunit as u
>>> length_dim = u.meter.dim
>>> length_dim.get_dimension('m')
1.0
>>> length_dim.is_dimensionless
False
>>> u.DIMENSIONLESS.is_dimensionless
True
property dim#

Return the Dimension object itself.

This property allows uniform access to the dimension of an object via the dim attribute, which works for Quantity, Unit, and Dimension objects alike.

Returns:

This Dimension instance.

Return type:

Dimension

Examples

>>> import saiunit as u
>>> d = u.meter.dim
>>> d.dim is d
True
get_dimension(d)[source]#

Return a specific dimension.

Parameters:

d (str) – A string identifying the SI basic unit dimension. Can be either a description like “length” or a basic unit like “m” or “metre”.

Returns:

dim – The dimensionality of the dimension d.

Return type:

float

property hash#

Calculate and return the hash value of the dimension.

This property memoizes the hash value for efficiency. Once calculated, the hash value is stored in the _hash attribute for future access. The hash is based on the binary representation of the dimensions array.

Returns:

The hash value of the dimensions array.

Return type:

int

Notes

The hash is only calculated once and then cached. This allows Dimension objects with the same dimensional values to have the same hash, supporting their use as dictionary keys and in sets.

property is_dimensionless#

Check whether this Dimension is dimensionless.

Returns:

True if all dimensional exponents are zero.

Return type:

bool

See also

DIMENSIONLESS

Singleton dimensionless Dimension.

Notes

For performance, prefer checking dim is DIMENSIONLESS instead.

Examples

>>> import saiunit as u
>>> u.DIMENSIONLESS.is_dimensionless
True
>>> u.meter.dim.is_dimensionless
False