Math::Libgsl::Sort

An interface to libgsl, the Gnu Scientific Library - Sort.

NAME

Math::Libgsl::Sort - An interface to libgsl, the Gnu Scientific Library - Sort.

SYNOPSIS

use Math::Libgsl::Raw::Sort :ALL;

use Math::Libgsl::Sort;

DESCRIPTION

Math::Libgsl::Sort provides an interface to the sort functions of libgsl, the GNU Scientific Library.

This package provides both the low-level interface to the C library (Raw) and a more comfortable interface layer for the Raku programmer.

This package comes with the Sort module tailored to all the real and integer types:

  • Math::Libgsl::Sort - default, corresponding to a Math::Libgsl::Sort::Num64

  • Math::Libgsl::Sort::Num32

  • Math::Libgsl::Sort::Int32

  • Math::Libgsl::Sort::UInt32

  • Math::Libgsl::Sort::Int64

  • Math::Libgsl::Sort::UInt64

  • Math::Libgsl::Sort::Int16

  • Math::Libgsl::Sort::UInt16

  • Math::Libgsl::Sort::Int8

  • Math::Libgsl::Sort::UInt8

All the subs of each package have their name prefixed by the relative data type:

Math::Libgsl::Sort has a sub num64sort, while Math::Libgsl::Sort::Int8 has a sub int8sort, and so on.

num64sort(:@data, Int :$stride? = 1 --> List)

This sub takes two named arguments: the data array and the stride. The sub returns a List of values: the element of the original array sorted in ascending order.

For example:

my @data = (10ā€¦0)Ā».Num;
say @data; # output: [10 9 8 7 6 5 4 3 2 1 0]
my @out = num64sort(:@data, :stride(2)); # sort the elements of @data, with a stride of 2: 10, 8, 6, 4, 2
say @out;  # output: [0 9 2 7 4 5 6 3 8 1 10]

num64sort2(:@data1, Int :stride2? = 1 --> List)

This sub takes four named arguments: two data arrays and the relative strides. The sub returns a List of Pairs: 'data1' and the element of the first array taken with a stride stride2, rearranged as the first array.

For example:

my @data1 = (10ā€¦0)Ā».Num;
my @data2 = (20ā€¦0)Ā».Num;
say @data1; # output: [10 9 8 7 6 5 4 3 2 1 0]
say @data2; # output: [20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0]
my %out = num64sort2(:@data1, :stride1(2), :@data2, :stride2(3));
say %out<data1>; # output: (0 9 2 7 4 5 6 3 8 1 10)
say %out<data2>; # output: (5 19 18 8 16 15 11 13 12 14 10 9 17 7 6 20 4 3 2 1 0)

num64sort-index(:@data, Int :$stride? = 1 --> List)

This sub indirectly sorts the elements of the array with stride into ascending order, returning the resulting permutation.

num64sort-vector(Math::Libgsl::Vector $v)

This sub sorts in place the elements of the Math::Libgsl::Vector $v into ascending numerical order.

num64sort2-vector(Math::Libgsl::Vector v2)

This sub sorts the elements of the Math::Libgsl::Vector v2.

num64sort-vector-index(Math::Libgsl::Vector p where p.p.size)

This sub indirectly sorts the elements of the Math::Libgsl::Vector p. The vector and the permutation must have the same number of elements.

num64smallest(:@data, Int :k? where * ā‰¤ (@data.elems / $stride).ceiling = @data.elems --> List)

This sub returns the stride, in ascending numerical order.

num64largest(:@data, Int :k? where * ā‰¤ (@data.elems / $stride).ceiling = @data.elems --> List)

This sub returns the stride, in ascending numerical order.

num64smallest-index(:@data, Int :k? where * ā‰¤ (@data.elems / $stride).ceiling = @data.elems --> List)

This sub returns the indices of the stride, in ascending numerical order.

num64largest-index(:@data, Int :k? where * ā‰¤ (@data.elems / $stride).ceiling = @data.elems --> List)

This sub returns the indices of the stride, in ascending numerical order.

num64vector-smallest(Math::Libgsl::Vector k? where * < v.vector.size --> List)

This sub returns the stride, in ascending numerical order.

num64vector-largest(Math::Libgsl::Vector k? where * < v.vector.size --> List)

This sub returns the stride, in ascending numerical order.

num64vector-smallest-index(Math::Libgsl::Vector k? where * < v.vector.size --> List)

This sub returns the indices of the stride, in ascending numerical order.

num64vector-largest-index(Math::Libgsl::Vector k? where * < v.vector.size --> List)

This sub returns the indices of the stride, in ascending numerical order.

C Library Documentation

For more details on libgsl see https://www.gnu.org/software/gsl/. The excellent C Library manual is available here https://www.gnu.org/software/gsl/doc/html/index.html, or here https://www.gnu.org/software/gsl/doc/latex/gsl-ref.pdf in PDF format.

Prerequisites

This module requires the libgsl library to be installed. Please follow the instructions below based on your platform:

Debian Linux and Ubuntu 20.04+

sudo apt install libgsl23 libgsl-dev libgslcblas0

That command will install libgslcblas0 as well, since it's used by the GSL.

Ubuntu 18.04

libgsl23 and libgslcblas0 have a missing symbol on Ubuntu 18.04. I solved the issue installing the Debian Buster version of those three libraries:

Installation

To install it using zef (a module management tool):

$ zef install Math::Libgsl::Sort

AUTHOR

Fernando Santagata [email protected]

COPYRIGHT AND LICENSE

Copyright 2020 Fernando Santagata

This library is free software; you can redistribute it and/or modify it under the Artistic License 2.0.

Math::Libgsl::Sort v0.0.3

An interface to libgsl, the Gnu Scientific Library - Sort.

Authors

  • Fernando Santagata

License

Artistic-2.0

Dependencies

Math::Libgsl::ConstantsMath::Libgsl::MatrixMath::Libgsl::Permutation

Test Dependencies

Provides

  • Math::Libgsl::Raw::Sort
  • Math::Libgsl::Raw::Sort::Int16
  • Math::Libgsl::Raw::Sort::Int32
  • Math::Libgsl::Raw::Sort::Int64
  • Math::Libgsl::Raw::Sort::Int8
  • Math::Libgsl::Raw::Sort::Num32
  • Math::Libgsl::Raw::Sort::UInt16
  • Math::Libgsl::Raw::Sort::UInt32
  • Math::Libgsl::Raw::Sort::UInt64
  • Math::Libgsl::Raw::Sort::UInt8
  • Math::Libgsl::Sort
  • Math::Libgsl::Sort::Int16
  • Math::Libgsl::Sort::Int32
  • Math::Libgsl::Sort::Int64
  • Math::Libgsl::Sort::Int8
  • Math::Libgsl::Sort::Num32
  • Math::Libgsl::Sort::UInt16
  • Math::Libgsl::Sort::UInt32
  • Math::Libgsl::Sort::UInt64
  • Math::Libgsl::Sort::UInt8

Documentation

The Camelia image is copyright 2009 by Larry Wall. "Raku" is trademark of the Yet Another Society. All rights reserved.