Skip to content
Tomasz Nehring edited this page May 5, 2022 · 3 revisions

Go package: vector

Short description

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.

Naming convention

  1. Applies to Go standard:

    • UpperCamelCase for API
    • lowerCamelCase for internal implementation
    • ...
  2. My own naming for go libraries since 2022-05:

    1. Prefix "Unchecked"
      • function expects correct values and may panic or misbehave if wrong ones are supplied.
      • It's usually the lowest level of abstraction.
    2. 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.
    3. 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.
    4. 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.
Clone this wiki locally