-
Notifications
You must be signed in to change notification settings - Fork 0
Theory
Tomasz Nehring edited this page May 5, 2022
·
3 revisions
This is a procedural API for dealing with mathematical vectors.
It treats []float64
as a vector, thus []float64
is a main argument of most functions in this package.
-
Applies to Go standard:
- UpperCamelCase for API
- lowerCamelCase for internal implementation
- ...
-
My own naming for go libraries since 2022-05:
- Prefix "Unchecked"
- function expects correct values and may panic or misbehave if wrong ones are supplied.
- It's usually the lowest level of abstraction.
- Prefix "Force"
- It is weak form of function with larger domain than mathematician would expect.
- It accepts abnormal arguments and treats
them intuitively by extending context.
Eg.: Forcing operation on slices with different length the missing values in shorter slice are assumed to be zeros.ForceDotProd([]float64{1,2,3}, []float64{6}) == 6
Because 1·6 + 2·0 + 3·0 = 6 - Extension of mathematical context usually has no overhead. No additional check are made.
- It's usually low or medium level of abstraction.
- Prefix "Nilable"
- It's a safe form of the function if you ONLY make nil-check on returned value.
- It's usually medium level of abstraction.
- No prefix
- It targets unaware end users of an API.
- Getting the second returned value impossible ==
true
is a clear sign that in narrow mathematical definition, which is commonly known, this operation on given arguments is undefined. - In this library, it is usually because
len(vec1) != len(vec2)
, so addition, multiplication, ... between vectors are not defined.
- Prefix "Unchecked"