├── .codecov.yml ├── .github ├── ISSUE_TEMPLATE ├── PULL_REQUEST_TEMPLATE └── workflows │ ├── check-copyright.sh │ ├── check-formatting.sh │ ├── check-generate.sh │ ├── check-imports.sh │ ├── ci.yml │ ├── codecov.yml │ ├── install-openblas.sh │ ├── test-coverage.sh │ └── test.sh ├── .travis.yml ├── .travis ├── check-copyright.sh ├── check-formatting.sh ├── check-generate.sh ├── check-imports.sh ├── linux │ ├── ATLAS │ │ ├── install.sh │ │ └── test.sh │ ├── OpenBLAS │ │ ├── install.sh │ │ └── test.sh │ └── install.sh ├── osx │ ├── Accelerate │ │ ├── install.sh │ │ └── test.sh │ ├── OpenBLAS │ │ ├── install.sh │ │ └── test.sh │ └── install.sh └── test-coverage.sh ├── LICENSE ├── README.md ├── blas └── netlib │ ├── bench_test.go │ ├── blas.go │ ├── cblas.h │ ├── dgemmbench_test.go │ ├── dgemvbench_test.go │ ├── dgerbench_test.go │ ├── doc.go │ ├── dtrmvbench_test.go │ ├── errors.go │ ├── generate_blas.go │ ├── generate_errors.go │ ├── level1cmplx128_test.go │ ├── level1doubleBench_auto_test.go │ ├── level1double_test.go │ ├── level2cmplx128_test.go │ ├── level2double_test.go │ ├── level3cmplx128_test.go │ └── level3double_test.go ├── go.mod ├── go.sum ├── internal └── binding │ └── binding.go └── lapack ├── lapacke ├── generate.go ├── generate_lapacke.go ├── lapacke.go ├── lapacke.h ├── lapacke_config.h ├── lapacke_mangling.h └── lapacke_utils.h └── netlib ├── bench_test.go ├── conv.go ├── conv_test.go ├── errors.go ├── generate.go ├── generate_errors.go ├── lapack.go └── lapack_test.go /.codecov.yml: -------------------------------------------------------------------------------- 1 | fixes: 2 | - "src/gonum.org/v1/netlib/::" 3 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE: -------------------------------------------------------------------------------- 1 | 10 | ### What are you trying to do? 11 | 12 | 13 | ### What did you do? 14 | 15 | 16 | 17 | ### What did you expect to happen? 18 | 19 | 20 | ### What actually happened? 21 | 22 | 23 | ### What version of Go, Gonum, Gonum/netlib and C implementation are you using? 24 | 29 | 30 | 31 | ### Does this issue reproduce with the current master? 32 | 33 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE: -------------------------------------------------------------------------------- 1 | Please take a look. 2 | 3 | 17 | -------------------------------------------------------------------------------- /.github/workflows/check-copyright.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | check-copyright -notice "Copyright ©20[0-9]{2} The Gonum Authors\. All rights reserved\." 5 | -------------------------------------------------------------------------------- /.github/workflows/check-formatting.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | test -z "$(goimports -d .)" 4 | if [[ -n "$(gofmt -s -l .)" ]]; then 5 | echo -e '\e[31mCode not gofmt simplified in:\n\n' 6 | gofmt -s -l . 7 | echo -e "\e[0" 8 | fi 9 | -------------------------------------------------------------------------------- /.github/workflows/check-generate.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -ex 3 | 4 | go generate gonum.org/v1/netlib/blas/netlib 5 | go generate gonum.org/v1/netlib/lapack/lapacke 6 | go generate gonum.org/v1/netlib/lapack/netlib 7 | 8 | git checkout -- go.{mod,sum} 9 | if [ -n "$(git diff)" ]; then 10 | git diff 11 | exit 1 12 | fi 13 | -------------------------------------------------------------------------------- /.github/workflows/check-imports.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | check-imports -b "math/rand,github.com/gonum/.*" 5 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | pull_request: 5 | branches: [ master ] 6 | 7 | jobs: 8 | 9 | build: 10 | name: Build 11 | strategy: 12 | matrix: 13 | go-version: [1.20.x, 1.19.x] 14 | platform: [ubuntu-latest] 15 | 16 | runs-on: ${{ matrix.platform }} 17 | env: 18 | GO111MODULE: on 19 | GOPATH: ${{ github.workspace }} 20 | CGO_LDFLAGS: "-L/usr/lib -lopenblas" 21 | defaults: 22 | run: 23 | working-directory: ${{ env.GOPATH }}/src/gonum.org/v1/netlib 24 | 25 | steps: 26 | - name: Install Go 27 | uses: actions/setup-go@v2 28 | with: 29 | go-version: ${{ matrix.go-version }} 30 | 31 | - name: Cache-Go 32 | uses: actions/cache@v1 33 | with: 34 | path: | 35 | ~/go/pkg/mod # Module download cache 36 | ~/.cache/go-build # Build cache (Linux) 37 | ~/Library/Caches/go-build # Build cache (Mac) 38 | '%LocalAppData%\go-build' # Build cache (Windows) 39 | ~/.cache/OpenBLAS # OpenBLAS build cache 40 | 41 | key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} 42 | restore-keys: | 43 | ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} 44 | 45 | - name: Checkout code 46 | uses: actions/checkout@v2 47 | with: 48 | path: ${{ env.GOPATH }}/src/gonum.org/v1/netlib 49 | 50 | - name: Check copyrights+imports+formatting+generate 51 | if: matrix.platform == 'ubuntu-latest' 52 | run: | 53 | go install golang.org/x/tools/cmd/cover@latest 54 | # Required for format check. 55 | go install golang.org/x/tools/cmd/goimports@latest 56 | # Required for imports check. 57 | go install gonum.org/v1/tools/cmd/check-imports@latest 58 | # Required for copyright header check. 59 | go install gonum.org/v1/tools/cmd/check-copyright@latest 60 | ./.github/workflows/check-copyright.sh 61 | ./.github/workflows/check-formatting.sh 62 | ./.github/workflows/check-generate.sh 63 | ./.github/workflows/check-imports.sh 64 | 65 | - name: Install Dependencies 66 | if: matrix.platform == 'ubuntu-latest' 67 | run: | 68 | sudo apt-get update 69 | sudo apt-get install -qq gfortran 70 | ./.github/workflows/install-openblas.sh 71 | 72 | - name: Test 73 | run: | 74 | ./.github/workflows/test.sh 75 | 76 | - name: Coverage 77 | if: matrix.platform == 'ubuntu-latest' 78 | run: | 79 | ./.github/workflows/test-coverage.sh 80 | 81 | - name: Upload-Coverage 82 | if: matrix.platform == 'ubuntu-latest' 83 | uses: codecov/codecov-action@v1 84 | -------------------------------------------------------------------------------- /.github/workflows/codecov.yml: -------------------------------------------------------------------------------- 1 | name: Codecov 2 | 3 | on: 4 | pull_request: 5 | branches: [ master ] 6 | types: 7 | - closed 8 | 9 | jobs: 10 | 11 | build: 12 | name: Build 13 | if: github.event.pull_request.merged == true 14 | strategy: 15 | matrix: 16 | go-version: [1.18.x, 1.17.x] 17 | platform: [ubuntu-latest] 18 | 19 | runs-on: ${{ matrix.platform }} 20 | env: 21 | GO111MODULE: on 22 | GOPATH: ${{ github.workspace }} 23 | CGO_LDFLAGS: "-L/usr/lib -lopenblas" 24 | defaults: 25 | run: 26 | working-directory: ${{ env.GOPATH }}/src/gonum.org/v1/netlib 27 | 28 | steps: 29 | - name: Install Go 30 | uses: actions/setup-go@v2 31 | with: 32 | go-version: ${{ matrix.go-version }} 33 | 34 | - name: Cache-Go 35 | uses: actions/cache@v1 36 | with: 37 | path: | 38 | ~/go/pkg/mod # Module download cache 39 | ~/.cache/go-build # Build cache (Linux) 40 | ~/Library/Caches/go-build # Build cache (Mac) 41 | '%LocalAppData%\go-build' # Build cache (Windows) 42 | ~/.cache/OpenBLAS # OpenBLAS build cache 43 | 44 | key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} 45 | restore-keys: | 46 | ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} 47 | 48 | - name: Checkout code 49 | uses: actions/checkout@v2 50 | with: 51 | path: ${{ env.GOPATH }}/src/gonum.org/v1/netlib 52 | 53 | - name: Install Dependencies 54 | if: matrix.platform == 'ubuntu-latest' 55 | run: | 56 | sudo apt-get update 57 | sudo apt-get install -qq gfortran 58 | go install golang.org/x/tools/cmd/cover@latest 59 | ./.github/workflows/install-openblas.sh 60 | 61 | - name: Coverage 62 | if: matrix.platform == 'ubuntu-latest' 63 | run: | 64 | ./.github/workflows/test-coverage.sh 65 | 66 | - name: Upload-Coverage 67 | if: matrix.platform == 'ubuntu-latest' 68 | uses: codecov/codecov-action@v1 69 | -------------------------------------------------------------------------------- /.github/workflows/install-openblas.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -ex 4 | 5 | CACHE_DIR="/home/runner/.cache/OpenBLAS" 6 | mkdir -p ${CACHE_DIR} 7 | 8 | # check if cache exists 9 | if [ -e ${CACHE_DIR}/last_commit_id ]; then 10 | echo "Cache $CACHE_DIR hit" 11 | LAST_COMMIT="$(git ls-remote https://github.com/xianyi/OpenBLAS HEAD | grep -o '^\S*')" 12 | CACHED_COMMIT="$(cat ${CACHE_DIR}/last_commit_id)" 13 | # determine current OpenBLAS master commit id and compare 14 | # with commit id in cache directory 15 | if [ "$LAST_COMMIT" != "$CACHED_COMMIT" ]; then 16 | echo "Cache Directory $CACHE_DIR has stale commit" 17 | # if commit is different, delete the cache 18 | rm -rf ${CACHE_DIR}/* 19 | fi 20 | fi 21 | 22 | if [ ! -e ${CACHE_DIR}/last_commit_id ]; then 23 | # Clear cache. 24 | rm -rf ${CACHE_DIR}/* 25 | 26 | # cache generation 27 | echo "Building cache at $CACHE_DIR" 28 | git clone --depth=1 https://github.com/xianyi/OpenBLAS 29 | 30 | pushd OpenBLAS 31 | make FC=gfortran &> /dev/null && make PREFIX=${CACHE_DIR} install 32 | echo $(git rev-parse HEAD) > ${CACHE_DIR}/last_commit_id 33 | popd 34 | fi 35 | 36 | # Instrument the build state 37 | echo OpenBLAS version:$(cat ${CACHE_DIR}/last_commit_id) 38 | cat /proc/cpuinfo 39 | 40 | # copy the cache files into /usr 41 | sudo cp -r ${CACHE_DIR}/* /usr/ 42 | 43 | # install gonum/blas against OpenBLAS 44 | export CGO_LDFLAGS="-L/usr/lib -lopenblas" 45 | go get -v -x gonum.org/v1/netlib/... 46 | -------------------------------------------------------------------------------- /.github/workflows/test-coverage.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | MODE=set 4 | PROFILE_OUT="${PWD}/profile.out" 5 | ACC_OUT="${PWD}/coverage.txt" 6 | 7 | testCover() { 8 | # set the return value to 0 (successful) 9 | retval=0 10 | # get the directory to check from the parameter. Default to '.' 11 | d=${1:-.} 12 | # skip if there are no Go files here 13 | ls $d/*.go &> /dev/null || return $retval 14 | # switch to the directory to check 15 | pushd $d > /dev/null 16 | # create the coverage profile 17 | coverageresult=$(go test -coverprofile="${PROFILE_OUT}" -covermode=${MODE}) 18 | # output the result so we can check the shell output 19 | echo ${coverageresult} 20 | # append the results to acc.out if coverage didn't fail, else set the retval to 1 (failed) 21 | ( [[ ${coverageresult} == *FAIL* ]] && retval=1 ) || ( [ -f "${PROFILE_OUT}" ] && grep -v "mode: ${MODE}" "${PROFILE_OUT}" >> "${ACC_OUT}" ) 22 | # return to our working dir 23 | popd > /dev/null 24 | # return our return value 25 | return $retval 26 | } 27 | 28 | # Init coverage.txt 29 | echo "mode: ${MODE}" > $ACC_OUT 30 | 31 | # Run test coverage on all directories containing go files. 32 | find . -type d | while read d; do testCover $d || exit; done 33 | -------------------------------------------------------------------------------- /.github/workflows/test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -ex 4 | 5 | go env 6 | export CGO_LDFLAGS="-L/usr/lib -lopenblas" 7 | go test -a -v ./... 8 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: required 2 | 3 | language: go 4 | 5 | # Versions of go that are explicitly supported by gonum. 6 | go: 7 | - 1.16.x 8 | - 1.15.x 9 | - master 10 | 11 | go_import_path: gonum.org/v1/netlib 12 | 13 | os: 14 | - linux 15 | - osx 16 | 17 | env: 18 | global: 19 | - GO111MODULE=on 20 | matrix: 21 | - BLAS_LIB=OpenBLAS 22 | # Does not currently link correctly. Note that there is an issue with drotgm in ATLAS. 23 | # - BLAS_LIB=ATLAS 24 | # If we can get multiarch builds on travis. 25 | # There are some issues with the Accellerate implementation. 26 | #- BLAS_LIB=Accellerate 27 | 28 | cache: 29 | directories: 30 | - $HOME/.cache/go-build 31 | - $HOME/gopath/pkg/mod 32 | # Persist the compiled OpenBLAS library between CI calls. 33 | - .travis/OpenBLAS.cache 34 | 35 | git: 36 | depth: 1 37 | 38 | matrix: 39 | fast_finish: true 40 | allow_failures: 41 | - go: master 42 | exclude: 43 | - os: linux 44 | env: BLAS_LIB=Accelerate 45 | - os: linux 46 | env: BLAS_LIB=ATLAS 47 | - os: osx 48 | env: BLAS_LIB=ATLAS 49 | - os: osx 50 | env: BLAS_LIB=OpenBLAS 51 | 52 | before_install: 53 | # Required for format check. 54 | - go get golang.org/x/tools/cmd/goimports 55 | # Required for imports check. 56 | - go get gonum.org/v1/tools/cmd/check-imports 57 | # Required for copyright header check. 58 | - go get gonum.org/v1/tools/cmd/check-copyright 59 | 60 | # Install the appropriate blas library (if any) and associated gonum software. 61 | install: 62 | - travis_wait 20 ${TRAVIS_BUILD_DIR}/.travis/$TRAVIS_OS_NAME/$BLAS_LIB/install.sh 63 | 64 | script: 65 | - ${TRAVIS_BUILD_DIR}/.travis/check-copyright.sh 66 | - ${TRAVIS_BUILD_DIR}/.travis/check-imports.sh 67 | - ${TRAVIS_BUILD_DIR}/.travis/check-formatting.sh 68 | - ${TRAVIS_BUILD_DIR}/.travis/$TRAVIS_OS_NAME/$BLAS_LIB/test.sh 69 | # This is run last since it alters the tree. 70 | - ${TRAVIS_BUILD_DIR}/.travis/check-generate.sh 71 | -------------------------------------------------------------------------------- /.travis/check-copyright.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | check-copyright -notice "Copyright ©20[0-9]{2} The Gonum Authors\. All rights reserved\." 5 | -------------------------------------------------------------------------------- /.travis/check-formatting.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | test -z "$(goimports -d .)" 4 | if [[ -n "$(gofmt -s -l .)" ]]; then 5 | echo -e '\e[31mCode not gofmt simplified in:\n\n' 6 | gofmt -s -l . 7 | echo -e "\e[0" 8 | fi 9 | -------------------------------------------------------------------------------- /.travis/check-generate.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -ex 3 | 4 | go generate gonum.org/v1/netlib/blas/netlib 5 | go generate gonum.org/v1/netlib/lapack/lapacke 6 | go generate gonum.org/v1/netlib/lapack/netlib 7 | 8 | git checkout -- go.{mod,sum} 9 | if [ -n "$(git diff)" ]; then 10 | git diff 11 | exit 1 12 | fi 13 | -------------------------------------------------------------------------------- /.travis/check-imports.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | check-imports -b "math/rand,github.com/gonum/.*" 5 | -------------------------------------------------------------------------------- /.travis/linux/ATLAS/install.sh: -------------------------------------------------------------------------------- 1 | set -ex 2 | 3 | # fetch and install ATLAS libs 4 | sudo apt-get update -qq && sudo apt-get install -qq libatlas-base-dev 5 | 6 | # fetch and install gonum/blas against ATLAS 7 | export CGO_LDFLAGS="-L/usr/lib -lblas" 8 | go get -v -v gonum.org/v1/netlib/... 9 | 10 | # run the OS common installation script 11 | source ${TRAVIS_BUILD_DIR}/.travis/$TRAVIS_OS_NAME/install.sh 12 | 13 | # travis compiles commands in script and then executes in bash. By adding 14 | # set -e we are changing the travis build script's behavior, and the set 15 | # -e lives on past the commands we are providing it. Some of the travis 16 | # commands are supposed to exit with non zero status, but then continue 17 | # executing. set -x makes the travis log files extremely verbose and 18 | # difficult to understand. 19 | # 20 | # see travis-ci/travis-ci#5120 21 | set +ex 22 | -------------------------------------------------------------------------------- /.travis/linux/ATLAS/test.sh: -------------------------------------------------------------------------------- 1 | set -ex 2 | 3 | go env 4 | go get -d -t -v ./... 5 | go test -a -v ./... 6 | if [[ $TRAVIS_SECURE_ENV_VARS = "true" ]]; then bash -c "$GOPATH/src/gonum.org/v1/netlib/.travis/test-coverage.sh"; fi 7 | 8 | # travis compiles commands in script and then executes in bash. By adding 9 | # set -e we are changing the travis build script's behavior, and the set 10 | # -e lives on past the commands we are providing it. Some of the travis 11 | # commands are supposed to exit with non zero status, but then continue 12 | # executing. set -x makes the travis log files extremely verbose and 13 | # difficult to understand. 14 | # 15 | # see travis-ci/travis-ci#5120 16 | set +ex 17 | -------------------------------------------------------------------------------- /.travis/linux/OpenBLAS/install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -ex 4 | 5 | CACHE_DIR=${TRAVIS_BUILD_DIR}/.travis/${BLAS_LIB}.cache 6 | 7 | # fetch fortran to build OpenBLAS 8 | sudo apt-get update -qq && sudo apt-get install -qq gfortran 9 | 10 | # check if cache exists 11 | if [ -e ${CACHE_DIR}/last_commit_id ]; then 12 | echo "Cache $CACHE_DIR hit" 13 | LAST_COMMIT="$(git ls-remote git://github.com/xianyi/OpenBLAS HEAD | grep -o '^\S*')" 14 | CACHED_COMMIT="$(cat ${CACHE_DIR}/last_commit_id)" 15 | # determine current OpenBLAS master commit id and compare 16 | # with commit id in cache directory 17 | if [ "$LAST_COMMIT" != "$CACHED_COMMIT" ]; then 18 | echo "Cache Directory $CACHE_DIR has stale commit" 19 | # if commit is different, delete the cache 20 | rm -rf ${CACHE_DIR} 21 | fi 22 | fi 23 | 24 | if [ ! -e ${CACHE_DIR}/last_commit_id ]; then 25 | # Clear cache. 26 | rm -rf ${CACHE_DIR} 27 | 28 | # cache generation 29 | echo "Building cache at $CACHE_DIR" 30 | mkdir ${CACHE_DIR} 31 | git clone --depth=1 git://github.com/xianyi/OpenBLAS 32 | 33 | pushd OpenBLAS 34 | make FC=gfortran &> /dev/null && make PREFIX=${CACHE_DIR} install 35 | echo $(git rev-parse HEAD) > ${CACHE_DIR}/last_commit_id 36 | popd 37 | fi 38 | 39 | # Instrument the build state 40 | echo OpenBLAS version:$(cat ${CACHE_DIR}/last_commit_id) 41 | cat /proc/cpuinfo 42 | 43 | # copy the cache files into /usr 44 | sudo cp -r ${CACHE_DIR}/* /usr/ 45 | 46 | # install gonum/blas against OpenBLAS 47 | export CGO_LDFLAGS="-L/usr/lib -lopenblas" 48 | go get -v -x gonum.org/v1/netlib/... 49 | 50 | # run the OS common installation script 51 | source ${TRAVIS_BUILD_DIR}/.travis/$TRAVIS_OS_NAME/install.sh 52 | -------------------------------------------------------------------------------- /.travis/linux/OpenBLAS/test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -ex 4 | 5 | go env 6 | go get -d -t -v ./... 7 | export CGO_LDFLAGS="-L/usr/lib -lopenblas" 8 | go test -a -v ./... 9 | if [[ $TRAVIS_SECURE_ENV_VARS = "true" ]]; then bash -c "$GOPATH/src/gonum.org/v1/netlib/.travis/test-coverage.sh"; fi 10 | -------------------------------------------------------------------------------- /.travis/linux/install.sh: -------------------------------------------------------------------------------- 1 | set -ex 2 | 3 | # This script contains common installation commands for linux. It should be run 4 | # prior to more specific installation commands for a particular blas library. 5 | go get golang.org/x/tools/cmd/cover 6 | go get github.com/mattn/goveralls 7 | 8 | # Repositories for code generation. 9 | go get modernc.org/cc 10 | 11 | # travis compiles commands in script and then executes in bash. By adding 12 | # set -e we are changing the travis build script's behavior, and the set 13 | # -e lives on past the commands we are providing it. Some of the travis 14 | # commands are supposed to exit with non zero status, but then continue 15 | # executing. set -x makes the travis log files extremely verbose and 16 | # difficult to understand. 17 | # 18 | # see travis-ci/travis-ci#5120 19 | set +ex 20 | -------------------------------------------------------------------------------- /.travis/osx/Accelerate/install.sh: -------------------------------------------------------------------------------- 1 | set -ex 2 | 3 | export CGO_LDFLAGS="-framework Accelerate" 4 | go get -v -v gonum.org/v1/netlib/... 5 | 6 | # run the OS common installation script 7 | source ${TRAVIS_BUILD_DIR}/.travis/$TRAVIS_OS_NAME/install.sh 8 | 9 | # travis compiles commands in script and then executes in bash. By adding 10 | # set -e we are changing the travis build script's behavior, and the set 11 | # -e lives on past the commands we are providing it. Some of the travis 12 | # commands are supposed to exit with non zero status, but then continue 13 | # executing. set -x makes the travis log files extremely verbose and 14 | # difficult to understand. 15 | # 16 | # see travis-ci/travis-ci#5120 17 | set +ex 18 | -------------------------------------------------------------------------------- /.travis/osx/Accelerate/test.sh: -------------------------------------------------------------------------------- 1 | set -ex 2 | 3 | go env 4 | go get -d -t -v ./... 5 | go test -a -v ./... 6 | if [[ $TRAVIS_SECURE_ENV_VARS = "true" ]]; then bash -c "$GOPATH/src/github.com/netlib/.travis/test-coverage.sh"; fi 7 | 8 | # travis compiles commands in script and then executes in bash. By adding 9 | # set -e we are changing the travis build script's behavior, and the set 10 | # -e lives on past the commands we are providing it. Some of the travis 11 | # commands are supposed to exit with non zero status, but then continue 12 | # executing. set -x makes the travis log files extremely verbose and 13 | # difficult to understand. 14 | # 15 | # see travis-ci/travis-ci#5120 16 | set +ex 17 | -------------------------------------------------------------------------------- /.travis/osx/OpenBLAS/install.sh: -------------------------------------------------------------------------------- 1 | set -ex 2 | 3 | # fetch and install OpenBLAS using homebrew 4 | brew install homebrew/science/openblas 5 | 6 | # fetch and install gonum/blas against OpenBLAS 7 | export CGO_LDFLAGS="-L/usr/local/opt/openblas/lib -lopenblas" 8 | go get -v -x gonum.org/v1/netlib/... 9 | 10 | # run the OS common installation script 11 | source ${TRAVIS_BUILD_DIR}/.travis/$TRAVIS_OS_NAME/install.sh 12 | 13 | # travis compiles commands in script and then executes in bash. By adding 14 | # set -e we are changing the travis build script's behavior, and the set 15 | # -e lives on past the commands we are providing it. Some of the travis 16 | # commands are supposed to exit with non zero status, but then continue 17 | # executing. set -x makes the travis log files extremely verbose and 18 | # difficult to understand. 19 | # 20 | # see travis-ci/travis-ci#5120 21 | set +ex 22 | -------------------------------------------------------------------------------- /.travis/osx/OpenBLAS/test.sh: -------------------------------------------------------------------------------- 1 | set -ex 2 | 3 | go env 4 | go get -d -t -v ./... 5 | go test -a -v ./... 6 | if [[ $TRAVIS_SECURE_ENV_VARS = "true" ]]; then bash -c "$GOPATH/src/github.com/netlib/.travis/test-coverage.sh"; fi 7 | 8 | # travis compiles commands in script and then executes in bash. By adding 9 | # set -e we are changing the travis build script's behavior, and the set 10 | # -e lives on past the commands we are providing it. Some of the travis 11 | # commands are supposed to exit with non zero status, but then continue 12 | # executing. set -x makes the travis log files extremely verbose and 13 | # difficult to understand. 14 | # 15 | # see travis-ci/travis-ci#5120 16 | set +ex 17 | -------------------------------------------------------------------------------- /.travis/osx/install.sh: -------------------------------------------------------------------------------- 1 | set -ex 2 | 3 | # This script contains common installation commands for osx. It should be run 4 | # prior to more specific installation commands for a particular blas library. 5 | go get golang.org/x/tools/cmd/cover 6 | go get github.com/mattn/goveralls 7 | go get gonum.org/v1/gonum/blas 8 | go get gonum.org/v1/gonum/lapack 9 | go get gonum.org/v1/gonum/floats 10 | 11 | # Repositories for code generation. 12 | go get modernc.org/cc 13 | go get gonum.org/v1/netlib/internal/binding 14 | 15 | # travis compiles commands in script and then executes in bash. By adding 16 | # set -e we are changing the travis build script's behavior, and the set 17 | # -e lives on past the commands we are providing it. Some of the travis 18 | # commands are supposed to exit with non zero status, but then continue 19 | # executing. set -x makes the travis log files extremely verbose and 20 | # difficult to understand. 21 | # 22 | # see travis-ci/travis-ci#5120 23 | set +ex 24 | -------------------------------------------------------------------------------- /.travis/test-coverage.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | MODE=set 4 | PROFILE_OUT="${PWD}/profile.out" 5 | ACC_OUT="${PWD}/coverage.txt" 6 | 7 | testCover() { 8 | # set the return value to 0 (successful) 9 | retval=0 10 | # get the directory to check from the parameter. Default to '.' 11 | d=${1:-.} 12 | # skip if there are no Go files here 13 | ls $d/*.go &> /dev/null || return $retval 14 | # switch to the directory to check 15 | pushd $d > /dev/null 16 | # create the coverage profile 17 | coverageresult=$(go test $TAGS -coverprofile="${PROFILE_OUT}" -covermode=${MODE}) 18 | # output the result so we can check the shell output 19 | echo ${coverageresult} 20 | # append the results to acc.out if coverage didn't fail, else set the retval to 1 (failed) 21 | ( [[ ${coverageresult} == *FAIL* ]] && retval=1 ) || ( [ -f "${PROFILE_OUT}" ] && grep -v "mode: ${MODE}" "${PROFILE_OUT}" >> "${ACC_OUT}" ) 22 | # return to our working dir 23 | popd > /dev/null 24 | # return our return value 25 | return $retval 26 | } 27 | 28 | # Init coverage.txt 29 | echo "mode: ${MODE}" > $ACC_OUT 30 | 31 | # Run test coverage on all directories containing go files. 32 | find . -type d | while read d; do testCover $d || exit; done 33 | 34 | # Upload the coverage profile to coveralls.io 35 | [ -n "$COVERALLS_TOKEN" ] && ( goveralls -coverprofile=$ACC_OUT || echo -e '\n\e[31mCoveralls failed.\n' ) 36 | 37 | # Upload to coverage profile to codedov.io 38 | [ -n "$CODECOV_TOKEN" ] && ( bash <(curl -s https://codecov.io/bash) || echo -e '\n\e[31mCodecov failed.\n' ) 39 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright ©2013 The gonum Authors. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are met: 5 | * Redistributions of source code must retain the above copyright 6 | notice, this list of conditions and the following disclaimer. 7 | * Redistributions in binary form must reproduce the above copyright 8 | notice, this list of conditions and the following disclaimer in the 9 | documentation and/or other materials provided with the distribution. 10 | * Neither the name of the gonum project nor the names of its authors and 11 | contributors may be used to endorse or promote products derived from this 12 | software without specific prior written permission. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 15 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Gonum NETLIB [![Build Status](https://travis-ci.org/gonum/netlib.svg?branch=master)](https://travis-ci.org/gonum/netlib) [![codecov.io](https://codecov.io/gh/gonum/netlib/branch/master/graph/badge.svg)](https://codecov.io/gh/gonum/netlib) [![coveralls.io](https://coveralls.io/repos/gonum/netlib/badge.svg?branch=master&service=github)](https://coveralls.io/github/gonum/netlib?branch=master) [![GoDoc](https://godoc.org/gonum.org/v1/netlib?status.svg)](https://godoc.org/gonum.org/v1/netlib) 2 | ====== 3 | 4 | Wrapper packages providing an interface to the NETLIB C BLAS and LAPACKE implementations. 5 | 6 | ## Installation 7 | 8 | ``` 9 | go get -d gonum.org/v1/netlib/... 10 | ``` 11 | 12 | 13 | Install OpenBLAS: 14 | ``` 15 | git clone https://github.com/xianyi/OpenBLAS 16 | cd OpenBLAS 17 | make 18 | ``` 19 | 20 | Then install the CGO BLAS wrapper package: 21 | ```sh 22 | CGO_LDFLAGS="-L/path/to/OpenBLAS -lopenblas" go install gonum.org/v1/netlib/blas/netlib 23 | ``` 24 | or the CGO LAPACKE wrapper package: 25 | ```sh 26 | CGO_LDFLAGS="-L/path/to/OpenBLAS -lopenblas" go install gonum.org/v1/netlib/lapack/netlib 27 | ``` 28 | 29 | For Windows you can download binary packages for OpenBLAS at 30 | http://sourceforge.net/projects/openblas/files/ 31 | 32 | If you want to use a different BLAS package such as the Intel MKL you can 33 | adjust the `CGO_LDFLAGS` variable: 34 | ```sh 35 | CGO_LDFLAGS="-lmkl_rt" go install gonum.org/v1/netlib/... 36 | ``` 37 | 38 | ## Packages 39 | 40 | ### blas/netlib 41 | 42 | Binding to a C implementation of the cblas interface (e.g. ATLAS, OpenBLAS, Intel MKL) 43 | 44 | The recommended (free) option for good performance on both Linux and Darwin is OpenBLAS. 45 | 46 | ### lapack/netlib 47 | 48 | Binding to a C implementation of the lapacke interface (e.g. ATLAS, OpenBLAS, Intel MKL) 49 | 50 | The recommended (free) option for good performance on both Linux and Darwin is OpenBLAS. 51 | 52 | ### lapack/lapacke 53 | 54 | Low level binding to a C implementation of the lapacke interface (e.g. OpenBLAS or intel MKL) 55 | 56 | The linker flags (i.e. path to the BLAS library and library name) might have to be adapted. 57 | 58 | The recommended (free) option for good performance on both linux and darwin is OpenBLAS. 59 | 60 | ## Issues 61 | 62 | If you find any bugs, feel free to file an issue on the github issue tracker. Discussions on API changes, added features, code review, or similar requests are preferred on the gonum-dev Google Group. 63 | 64 | https://groups.google.com/forum/#!forum/gonum-dev 65 | 66 | ## License 67 | 68 | Please see gonum.org/v1/gonum for general license information, contributors, authors, etc on the Gonum suite of packages. 69 | -------------------------------------------------------------------------------- /blas/netlib/bench_test.go: -------------------------------------------------------------------------------- 1 | // Copyright ©2015 The Gonum Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package netlib 6 | 7 | import ( 8 | "gonum.org/v1/gonum/blas" 9 | "gonum.org/v1/gonum/blas/testblas" 10 | ) 11 | 12 | const ( 13 | Sm = testblas.SmallMat 14 | Med = testblas.MediumMat 15 | Lg = testblas.LargeMat 16 | Hg = testblas.HugeMat 17 | ) 18 | 19 | const ( 20 | T = blas.Trans 21 | NT = blas.NoTrans 22 | ) 23 | -------------------------------------------------------------------------------- /blas/netlib/dgemmbench_test.go: -------------------------------------------------------------------------------- 1 | // Copyright ©2014 The Gonum Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package netlib 6 | 7 | import ( 8 | "testing" 9 | 10 | "gonum.org/v1/gonum/blas/testblas" 11 | ) 12 | 13 | func BenchmarkDgemmSmSmSm(b *testing.B) { 14 | testblas.DgemmBenchmark(b, impl, Sm, Sm, Sm, NT, NT) 15 | } 16 | 17 | func BenchmarkDgemmMedMedMed(b *testing.B) { 18 | testblas.DgemmBenchmark(b, impl, Med, Med, Med, NT, NT) 19 | } 20 | 21 | func BenchmarkDgemmMedLgMed(b *testing.B) { 22 | testblas.DgemmBenchmark(b, impl, Med, Lg, Med, NT, NT) 23 | } 24 | 25 | func BenchmarkDgemmLgLgLg(b *testing.B) { 26 | testblas.DgemmBenchmark(b, impl, Lg, Lg, Lg, NT, NT) 27 | } 28 | 29 | func BenchmarkDgemmLgSmLg(b *testing.B) { 30 | testblas.DgemmBenchmark(b, impl, Lg, Sm, Lg, NT, NT) 31 | } 32 | 33 | func BenchmarkDgemmLgLgSm(b *testing.B) { 34 | testblas.DgemmBenchmark(b, impl, Lg, Lg, Sm, NT, NT) 35 | } 36 | 37 | func BenchmarkDgemmHgHgSm(b *testing.B) { 38 | testblas.DgemmBenchmark(b, impl, Hg, Hg, Sm, NT, NT) 39 | } 40 | 41 | func BenchmarkDgemmMedMedMedTNT(b *testing.B) { 42 | testblas.DgemmBenchmark(b, impl, Med, Med, Med, T, NT) 43 | } 44 | 45 | func BenchmarkDgemmMedMedMedNTT(b *testing.B) { 46 | testblas.DgemmBenchmark(b, impl, Med, Med, Med, NT, T) 47 | } 48 | 49 | func BenchmarkDgemmMedMedMedTT(b *testing.B) { 50 | testblas.DgemmBenchmark(b, impl, Med, Med, Med, T, T) 51 | } 52 | -------------------------------------------------------------------------------- /blas/netlib/dgemvbench_test.go: -------------------------------------------------------------------------------- 1 | // Copyright ©2015 The Gonum Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package netlib 6 | 7 | import ( 8 | "testing" 9 | 10 | "gonum.org/v1/gonum/blas/testblas" 11 | ) 12 | 13 | func BenchmarkDgemvSmSmNoTransInc1(b *testing.B) { 14 | testblas.DgemvBenchmark(b, impl, NT, Sm, Sm, 1, 1) 15 | } 16 | 17 | func BenchmarkDgemvSmSmNoTransIncN(b *testing.B) { 18 | testblas.DgemvBenchmark(b, impl, NT, Sm, Sm, 2, 3) 19 | } 20 | 21 | func BenchmarkDgemvSmSmTransInc1(b *testing.B) { 22 | testblas.DgemvBenchmark(b, impl, T, Sm, Sm, 1, 1) 23 | } 24 | 25 | func BenchmarkDgemvSmSmTransIncN(b *testing.B) { 26 | testblas.DgemvBenchmark(b, impl, T, Sm, Sm, 2, 3) 27 | } 28 | 29 | func BenchmarkDgemvMedMedNoTransInc1(b *testing.B) { 30 | testblas.DgemvBenchmark(b, impl, NT, Med, Med, 1, 1) 31 | } 32 | 33 | func BenchmarkDgemvMedMedNoTransIncN(b *testing.B) { 34 | testblas.DgemvBenchmark(b, impl, NT, Med, Med, 2, 3) 35 | } 36 | 37 | func BenchmarkDgemvMedMedTransInc1(b *testing.B) { 38 | testblas.DgemvBenchmark(b, impl, T, Med, Med, 1, 1) 39 | } 40 | 41 | func BenchmarkDgemvMedMedTransIncN(b *testing.B) { 42 | testblas.DgemvBenchmark(b, impl, T, Med, Med, 2, 3) 43 | } 44 | 45 | func BenchmarkDgemvLgLgNoTransInc1(b *testing.B) { 46 | testblas.DgemvBenchmark(b, impl, NT, Lg, Lg, 1, 1) 47 | } 48 | 49 | func BenchmarkDgemvLgLgNoTransIncN(b *testing.B) { 50 | testblas.DgemvBenchmark(b, impl, NT, Lg, Lg, 2, 3) 51 | } 52 | 53 | func BenchmarkDgemvLgLgTransInc1(b *testing.B) { 54 | testblas.DgemvBenchmark(b, impl, T, Lg, Lg, 1, 1) 55 | } 56 | 57 | func BenchmarkDgemvLgLgTransIncN(b *testing.B) { 58 | testblas.DgemvBenchmark(b, impl, T, Lg, Lg, 2, 3) 59 | } 60 | 61 | func BenchmarkDgemvLgSmNoTransInc1(b *testing.B) { 62 | testblas.DgemvBenchmark(b, impl, NT, Lg, Sm, 1, 1) 63 | } 64 | 65 | func BenchmarkDgemvLgSmNoTransIncN(b *testing.B) { 66 | testblas.DgemvBenchmark(b, impl, NT, Lg, Sm, 2, 3) 67 | } 68 | 69 | func BenchmarkDgemvLgSmTransInc1(b *testing.B) { 70 | testblas.DgemvBenchmark(b, impl, T, Lg, Sm, 1, 1) 71 | } 72 | 73 | func BenchmarkDgemvLgSmTransIncN(b *testing.B) { 74 | testblas.DgemvBenchmark(b, impl, T, Lg, Sm, 2, 3) 75 | } 76 | 77 | func BenchmarkDgemvSmLgNoTransInc1(b *testing.B) { 78 | testblas.DgemvBenchmark(b, impl, NT, Sm, Lg, 1, 1) 79 | } 80 | 81 | func BenchmarkDgemvSmLgNoTransIncN(b *testing.B) { 82 | testblas.DgemvBenchmark(b, impl, NT, Sm, Lg, 2, 3) 83 | } 84 | 85 | func BenchmarkDgemvSmLgTransInc1(b *testing.B) { 86 | testblas.DgemvBenchmark(b, impl, T, Sm, Lg, 1, 1) 87 | } 88 | 89 | func BenchmarkDgemvSmLgTransIncN(b *testing.B) { 90 | testblas.DgemvBenchmark(b, impl, T, Sm, Lg, 2, 3) 91 | } 92 | -------------------------------------------------------------------------------- /blas/netlib/dgerbench_test.go: -------------------------------------------------------------------------------- 1 | // Copyright ©2015 The Gonum Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package netlib 6 | 7 | import ( 8 | "testing" 9 | 10 | "gonum.org/v1/gonum/blas/testblas" 11 | ) 12 | 13 | func BenchmarkDgerSmSmInc1(b *testing.B) { 14 | testblas.DgerBenchmark(b, impl, Sm, Sm, 1, 1) 15 | } 16 | 17 | func BenchmarkDgerSmSmIncN(b *testing.B) { 18 | testblas.DgerBenchmark(b, impl, Sm, Sm, 2, 3) 19 | } 20 | 21 | func BenchmarkDgerMedMedInc1(b *testing.B) { 22 | testblas.DgerBenchmark(b, impl, Med, Med, 1, 1) 23 | } 24 | 25 | func BenchmarkDgerMedMedIncN(b *testing.B) { 26 | testblas.DgerBenchmark(b, impl, Med, Med, 2, 3) 27 | } 28 | 29 | func BenchmarkDgerLgLgInc1(b *testing.B) { 30 | testblas.DgerBenchmark(b, impl, Lg, Lg, 1, 1) 31 | } 32 | 33 | func BenchmarkDgerLgLgIncN(b *testing.B) { 34 | testblas.DgerBenchmark(b, impl, Lg, Lg, 2, 3) 35 | } 36 | 37 | func BenchmarkDgerLgSmInc1(b *testing.B) { 38 | testblas.DgerBenchmark(b, impl, Lg, Sm, 1, 1) 39 | } 40 | 41 | func BenchmarkDgerLgSmIncN(b *testing.B) { 42 | testblas.DgerBenchmark(b, impl, Lg, Sm, 2, 3) 43 | } 44 | 45 | func BenchmarkDgerSmLgInc1(b *testing.B) { 46 | testblas.DgerBenchmark(b, impl, Sm, Lg, 1, 1) 47 | } 48 | 49 | func BenchmarkDgerSmLgIncN(b *testing.B) { 50 | testblas.DgerBenchmark(b, impl, Sm, Lg, 2, 3) 51 | } 52 | -------------------------------------------------------------------------------- /blas/netlib/doc.go: -------------------------------------------------------------------------------- 1 | // Copyright ©2015 The Gonum Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:generate go run generate_blas.go 6 | //go:generate go run generate_errors.go 7 | 8 | /* 9 | Package netlib provides bindings to a C BLAS library. This wrapper interface 10 | panics when the input arguments are invalid as per the standard, for example 11 | if a vector increment is zero. Note that the treatment of NaN values 12 | is not specified, and differs among the BLAS implementations. 13 | gonum.org/v1/gonum/blas/blas64 provides helpful wrapper functions to the BLAS 14 | interface. The rest of this text describes the layout of the data for the input types. 15 | 16 | Note that in the function documentation, x[i] refers to the i^th element 17 | of the vector, which will be different from the i^th element of the slice if 18 | incX != 1. 19 | 20 | Vector arguments are effectively strided slices. They have two input arguments, 21 | a number of elements, n, and an increment, incX. The increment specifies the 22 | distance between elements of the vector. The actual Go slice may be longer 23 | than necessary. 24 | The increment may be positive or negative, except in functions with only 25 | a single vector argument where the increment may only be positive. If the increment 26 | is negative, s[0] is the last element in the slice. Note that this is not the same 27 | as counting backward from the end of the slice, as len(s) may be longer than 28 | necessary. So, for example, if n = 5 and incX = 3, the elements of s are 29 | [0 * * 1 * * 2 * * 3 * * 4 * * * ...] 30 | where ∗ elements are never accessed. If incX = -3, the same elements are 31 | accessed, just in reverse order (4, 3, 2, 1, 0). 32 | 33 | Dense matrices are specified by a number of rows, a number of columns, and a stride. 34 | The stride specifies the number of entries in the slice between the first element 35 | of successive rows. The stride must be at least as large as the number of columns 36 | but may be longer. 37 | [a00 ... a0n a0* ... a1stride-1 a21 ... amn am* ... amstride-1] 38 | Thus, dense[i*ld + j] refers to the {i, j}th element of the matrix. 39 | 40 | Symmetric and triangular matrices (non-packed) are stored identically to Dense, 41 | except that only elements in one triangle of the matrix are accessed. 42 | 43 | Packed symmetric and packed triangular matrices are laid out with the entries 44 | condensed such that all of the unreferenced elements are removed. So, the upper triangular 45 | matrix 46 | [ 47 | 1 2 3 48 | 0 4 5 49 | 0 0 6 50 | ] 51 | and the lower-triangular matrix 52 | [ 53 | 1 0 0 54 | 2 3 0 55 | 4 5 6 56 | ] 57 | will both be compacted as [1 2 3 4 5 6]. The (i, j) element of the original 58 | dense matrix can be found at element i*n - (i-1)*i/2 + j for upper triangular, 59 | and at element i * (i+1) /2 + j for lower triangular. 60 | 61 | Banded matrices are laid out in a compact format, constructed by removing the 62 | zeros in the rows and aligning the diagonals. For example, the matrix 63 | [ 64 | 1 2 3 0 0 0 65 | 4 5 6 7 0 0 66 | 0 8 9 10 11 0 67 | 0 0 12 13 14 15 68 | 0 0 0 16 17 18 69 | 0 0 0 0 19 20 70 | ] 71 | 72 | implicitly becomes (∗ entries are never accessed) 73 | [ 74 | * 1 2 3 75 | 4 5 6 7 76 | 8 9 10 11 77 | 12 13 14 15 78 | 16 17 18 * 79 | 19 20 * * 80 | ] 81 | which is given to the BLAS routine as [∗ 1 2 3 4 ...]. 82 | 83 | See http://www.crest.iu.edu/research/mtl/reference/html/banded.html 84 | for more information 85 | 86 | */ 87 | package netlib // import "gonum.org/v1/netlib/blas/netlib" 88 | 89 | // BUG(btracey): The netlib package is intrinsically dependent on the underlying C 90 | // implementation. The BLAS standard is silent on a number of behaviors, including 91 | // but not limited to how NaN values are treated. For this reason the result of 92 | // computations performed by the cgo BLAS package may disagree with the results 93 | // produced by the native BLAS package. The cgo package is tested against OpenBLAS; 94 | // use of other backing BLAS C libraries may result in test failure because of this. 95 | -------------------------------------------------------------------------------- /blas/netlib/dtrmvbench_test.go: -------------------------------------------------------------------------------- 1 | // Copyright ©2017 The Gonum Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package netlib 6 | 7 | import ( 8 | "strconv" 9 | "testing" 10 | 11 | "gonum.org/v1/gonum/blas" 12 | "gonum.org/v1/gonum/blas/testblas" 13 | ) 14 | 15 | func BenchmarkDtrmv(b *testing.B) { 16 | for _, n := range []int{testblas.MediumMat, testblas.LargeMat} { 17 | for _, incX := range []int{1, 5} { 18 | for _, uplo := range []blas.Uplo{blas.Upper, blas.Lower} { 19 | for _, trans := range []blas.Transpose{blas.NoTrans, blas.Trans} { 20 | for _, unit := range []blas.Diag{blas.NonUnit, blas.Unit} { 21 | var str string 22 | if n == testblas.MediumMat { 23 | str += "Med" 24 | } else if n == testblas.LargeMat { 25 | str += "Large" 26 | } 27 | str += "_Inc" + strconv.Itoa(incX) 28 | if uplo == blas.Upper { 29 | str += "_UP" 30 | } else { 31 | str += "_LO" 32 | } 33 | if trans == blas.NoTrans { 34 | str += "_NT" 35 | } else { 36 | str += "_TR" 37 | } 38 | if unit == blas.NonUnit { 39 | str += "_NU" 40 | } else { 41 | str += "_UN" 42 | } 43 | lda := n 44 | b.Run(str, func(b *testing.B) { 45 | testblas.DtrmvBenchmark(b, Implementation{}, n, lda, incX, uplo, trans, unit) 46 | }) 47 | } 48 | } 49 | } 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /blas/netlib/errors.go: -------------------------------------------------------------------------------- 1 | // Code generated by "go generate gonum.org/v1/netlib/blas/netlib”; DO NOT EDIT. 2 | 3 | // Copyright ©2015 The Gonum Authors. All rights reserved. 4 | // Use of this source code is governed by a BSD-style 5 | // license that can be found in the LICENSE file. 6 | 7 | package netlib 8 | 9 | // Copied from gonum/blas/gonum. Keep in sync. 10 | const ( 11 | zeroIncX = "blas: zero x index increment" 12 | zeroIncY = "blas: zero y index increment" 13 | 14 | mLT0 = "blas: m < 0" 15 | nLT0 = "blas: n < 0" 16 | kLT0 = "blas: k < 0" 17 | kLLT0 = "blas: kL < 0" 18 | kULT0 = "blas: kU < 0" 19 | 20 | badUplo = "blas: illegal triangle" 21 | badTranspose = "blas: illegal transpose" 22 | badDiag = "blas: illegal diagonal" 23 | badSide = "blas: illegal side" 24 | badFlag = "blas: illegal rotm flag" 25 | 26 | badLdA = "blas: bad leading dimension of A" 27 | badLdB = "blas: bad leading dimension of B" 28 | badLdC = "blas: bad leading dimension of C" 29 | 30 | shortX = "blas: insufficient length of x" 31 | shortY = "blas: insufficient length of y" 32 | shortAP = "blas: insufficient length of ap" 33 | shortA = "blas: insufficient length of a" 34 | shortB = "blas: insufficient length of b" 35 | shortC = "blas: insufficient length of c" 36 | ) 37 | -------------------------------------------------------------------------------- /blas/netlib/generate_blas.go: -------------------------------------------------------------------------------- 1 | // Copyright ©2016 The Gonum Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build ignore 6 | 7 | // generate_blas creates a blas.go file from the provided C header file 8 | // with optionally added documentation from the documentation package. 9 | package main 10 | 11 | import ( 12 | "bytes" 13 | "fmt" 14 | "go/ast" 15 | "go/format" 16 | "io/ioutil" 17 | "log" 18 | "os" 19 | "os/exec" 20 | "path/filepath" 21 | "strings" 22 | "text/template" 23 | 24 | "modernc.org/cc" 25 | 26 | "gonum.org/v1/netlib/internal/binding" 27 | ) 28 | 29 | const ( 30 | header = "cblas.h" 31 | srcModule = "gonum.org/v1/gonum" 32 | documentation = "blas/gonum" 33 | target = "blas.go" 34 | 35 | typ = "Implementation" 36 | 37 | prefix = "cblas_" 38 | 39 | warning = "Float32 implementations are autogenerated and not directly tested." 40 | ) 41 | 42 | const ( 43 | cribDocs = true 44 | elideRepeat = true 45 | noteOrigin = true 46 | separateFuncs = false 47 | ) 48 | 49 | var skip = map[string]bool{ 50 | "cblas_xerbla": true, 51 | "cblas_srotg": true, 52 | "cblas_srotmg": true, 53 | "cblas_srotm": true, 54 | "cblas_drotg": true, 55 | "cblas_drotmg": true, 56 | "cblas_drotm": true, 57 | "cblas_crotg": true, 58 | "cblas_zrotg": true, 59 | "cblas_cdotu_sub": true, 60 | "cblas_cdotc_sub": true, 61 | "cblas_zdotu_sub": true, 62 | "cblas_zdotc_sub": true, 63 | "cblas_scabs1": true, 64 | "cblas_dcabs1": true, 65 | 66 | // ATLAS extensions. 67 | "cblas_csrot": true, 68 | "cblas_zdrot": true, 69 | } 70 | 71 | var cToGoType = map[string]string{ 72 | "int": "int", 73 | "unsigned long": "int", // For I?amax routines that return CBLAS_INDEX as size_t. 74 | "float": "float32", 75 | "double": "float64", 76 | } 77 | 78 | var blasEnums = map[string]*template.Template{ 79 | "CBLAS_LAYOUT": template.Must(template.New("layout").Parse("layout")), 80 | "CBLAS_DIAG": template.Must(template.New("diag").Parse("blas.Diag")), 81 | "CBLAS_TRANSPOSE": template.Must(template.New("trans").Parse("blas.Transpose")), 82 | "CBLAS_UPLO": template.Must(template.New("uplo").Parse("blas.Uplo")), 83 | "CBLAS_SIDE": template.Must(template.New("side").Parse("blas.Side")), 84 | } 85 | 86 | var cgoEnums = map[string]*template.Template{ 87 | "CBLAS_LAYOUT": template.Must(template.New("layout").Parse("C.CBLAS_LAYOUT(rowMajor)")), 88 | "CBLAS_DIAG": template.Must(template.New("diag").Parse("C.CBLAS_DIAG({{.}})")), 89 | "CBLAS_TRANSPOSE": template.Must(template.New("trans").Parse("C.CBLAS_TRANSPOSE({{.}})")), 90 | "CBLAS_UPLO": template.Must(template.New("uplo").Parse("C.CBLAS_UPLO({{.}})")), 91 | "CBLAS_SIDE": template.Must(template.New("side").Parse("C.CBLAS_SIDE({{.}})")), 92 | } 93 | 94 | var cgoTypes = map[binding.TypeKey]*template.Template{ 95 | {Kind: cc.Float, IsPointer: true}: template.Must(template.New("float*").Parse( 96 | `(*C.float)({{if eq . "alpha" "beta"}}&{{else}}_{{end}}{{.}})`, 97 | )), 98 | {Kind: cc.Double, IsPointer: true}: template.Must(template.New("double*").Parse( 99 | `(*C.double)({{if eq . "alpha" "beta"}}&{{else}}_{{end}}{{.}})`, 100 | )), 101 | {Kind: cc.Void, IsPointer: true}: template.Must(template.New("void*").Parse( 102 | `unsafe.Pointer({{if eq . "alpha" "beta"}}&{{else}}_{{end}}{{.}})`, 103 | )), 104 | } 105 | 106 | var ( 107 | complex64Type = map[binding.TypeKey]*template.Template{ 108 | {Kind: cc.Void, IsPointer: true}: template.Must(template.New("void*").Parse( 109 | `{{if eq . "alpha" "beta"}}complex64{{else}}[]complex64{{end}}`, 110 | ))} 111 | 112 | complex128Type = map[binding.TypeKey]*template.Template{ 113 | {Kind: cc.Void, IsPointer: true}: template.Must(template.New("void*").Parse( 114 | `{{if eq . "alpha" "beta"}}complex128{{else}}[]complex128{{end}}`, 115 | ))} 116 | ) 117 | 118 | var names = map[string]string{ 119 | "uplo": "ul", 120 | "trans": "t", 121 | "transA": "tA", 122 | "transB": "tB", 123 | "side": "s", 124 | "diag": "d", 125 | } 126 | 127 | func shorten(n string) string { 128 | s, ok := names[n] 129 | if ok { 130 | return s 131 | } 132 | return n 133 | } 134 | 135 | func main() { 136 | decls, err := binding.Declarations(header) 137 | if err != nil { 138 | log.Fatal(err) 139 | } 140 | var docs map[string]map[string][]*ast.Comment 141 | if cribDocs { 142 | docs, err = binding.DocComments(pathTo(srcModule, documentation)) 143 | if err != nil { 144 | log.Fatal(err) 145 | } 146 | } 147 | 148 | var buf bytes.Buffer 149 | 150 | h, err := template.New("handwritten").Parse(handwritten) 151 | if err != nil { 152 | log.Fatal(err) 153 | } 154 | err = h.Execute(&buf, header) 155 | if err != nil { 156 | log.Fatal(err) 157 | } 158 | 159 | var n int 160 | for _, d := range decls { 161 | if !strings.HasPrefix(d.Name, prefix) || skip[d.Name] { 162 | continue 163 | } 164 | if n != 0 && (separateFuncs || cribDocs) { 165 | buf.WriteByte('\n') 166 | } 167 | n++ 168 | goSignature(&buf, d, docs[typ]) 169 | if noteOrigin { 170 | fmt.Fprintf(&buf, "\t// declared at %s %s %s ...\n\n", d.Position(), d.Return, d.Name) 171 | } 172 | parameterChecks(&buf, d, parameterCheckRules) 173 | buf.WriteByte('\t') 174 | cgoCall(&buf, d) 175 | buf.WriteString("}\n") 176 | } 177 | 178 | b, err := format.Source(buf.Bytes()) 179 | if err != nil { 180 | log.Fatal(err) 181 | } 182 | err = ioutil.WriteFile(target, b, 0664) 183 | if err != nil { 184 | log.Fatal(err) 185 | } 186 | } 187 | 188 | func goSignature(buf *bytes.Buffer, d binding.Declaration, docs map[string][]*ast.Comment) { 189 | blasName := strings.TrimPrefix(d.Name, prefix) 190 | goName := binding.UpperCaseFirst(blasName) 191 | 192 | if docs != nil { 193 | if doc, ok := docs[goName]; ok { 194 | if strings.Contains(doc[len(doc)-1].Text, warning) { 195 | doc = doc[:len(doc)-2] 196 | } 197 | for _, c := range doc { 198 | buf.WriteString(c.Text) 199 | buf.WriteByte('\n') 200 | } 201 | } 202 | } 203 | 204 | parameters := d.Parameters() 205 | 206 | var voidPtrType map[binding.TypeKey]*template.Template 207 | for _, p := range parameters { 208 | if p.Kind() == cc.Ptr && p.Elem().Kind() == cc.Void { 209 | switch { 210 | case blasName[0] == 'c', blasName[1] == 'c' && blasName[0] != 'z': 211 | voidPtrType = complex64Type 212 | case blasName[0] == 'z', blasName[1] == 'z': 213 | voidPtrType = complex128Type 214 | } 215 | break 216 | } 217 | } 218 | 219 | fmt.Fprintf(buf, "func (%s) %s(", typ, goName) 220 | c := 0 221 | for i, p := range parameters { 222 | if p.Kind() == cc.Enum && binding.GoTypeForEnum(p.Type(), "", blasEnums) == "layout" { 223 | continue 224 | } 225 | if c != 0 { 226 | buf.WriteString(", ") 227 | } 228 | c++ 229 | 230 | n := shorten(binding.LowerCaseFirst(p.Name())) 231 | var this, next string 232 | 233 | if p.Kind() == cc.Enum { 234 | this = binding.GoTypeForEnum(p.Type(), n, blasEnums) 235 | } else { 236 | this = binding.GoTypeFor(p.Type(), n, voidPtrType) 237 | } 238 | 239 | if elideRepeat && i < len(parameters)-1 && p.Type().Kind() == parameters[i+1].Type().Kind() { 240 | p := parameters[i+1] 241 | n := shorten(binding.LowerCaseFirst(p.Name())) 242 | if p.Kind() == cc.Enum { 243 | next = binding.GoTypeForEnum(p.Type(), n, blasEnums) 244 | } else { 245 | next = binding.GoTypeFor(p.Type(), n, voidPtrType) 246 | } 247 | } 248 | if next == this { 249 | buf.WriteString(n) 250 | } else { 251 | fmt.Fprintf(buf, "%s %s", n, this) 252 | } 253 | } 254 | if d.Return.Kind() != cc.Void { 255 | goType, ok := cToGoType[d.Return.String()] 256 | if !ok { 257 | panic(fmt.Sprintf("Unexpected C type \"%s\"", d.Return.String())) 258 | } 259 | fmt.Fprintf(buf, ") %s {\n", goType) 260 | } else { 261 | buf.WriteString(") {\n") 262 | } 263 | } 264 | 265 | func parameterChecks(buf *bytes.Buffer, d binding.Declaration, rules []func(*bytes.Buffer, binding.Declaration, binding.Parameter)) { 266 | for _, r := range rules { 267 | for _, p := range d.Parameters() { 268 | r(buf, d, p) 269 | } 270 | } 271 | } 272 | 273 | func cgoCall(buf *bytes.Buffer, d binding.Declaration) { 274 | if d.Return.Kind() != cc.Void { 275 | goType, ok := cToGoType[d.Return.String()] 276 | if !ok { 277 | panic(fmt.Sprintf("Unexpected C type \"%s\"", d.Return.String())) 278 | } 279 | fmt.Fprintf(buf, "return %s(", goType) 280 | } 281 | fmt.Fprintf(buf, "C.%s(", d.Name) 282 | for i, p := range d.Parameters() { 283 | if i != 0 { 284 | buf.WriteString(", ") 285 | } 286 | if p.Type().Kind() == cc.Enum { 287 | buf.WriteString(binding.CgoConversionForEnum(shorten(binding.LowerCaseFirst(p.Name())), p.Type(), cgoEnums)) 288 | } else { 289 | buf.WriteString(binding.CgoConversionFor(shorten(binding.LowerCaseFirst(p.Name())), p.Type(), cgoTypes)) 290 | } 291 | } 292 | if d.Return.Kind() != cc.Void { 293 | buf.WriteString(")") 294 | } 295 | buf.WriteString(")\n") 296 | } 297 | 298 | var parameterCheckRules = []func(*bytes.Buffer, binding.Declaration, binding.Parameter){ 299 | trans, 300 | uplo, 301 | diag, 302 | side, 303 | shape, 304 | leadingDim, 305 | zeroInc, 306 | noWork, 307 | sliceLength, 308 | address, 309 | } 310 | 311 | func trans(buf *bytes.Buffer, d binding.Declaration, p binding.Parameter) { 312 | switch n := shorten(binding.LowerCaseFirst(p.Name())); n { 313 | case "t", "tA", "tB": 314 | switch { 315 | case strings.HasPrefix(d.Name, "cblas_ch"), strings.HasPrefix(d.Name, "cblas_zh"): 316 | fmt.Fprintf(buf, ` switch %[1]s { 317 | case blas.NoTrans: 318 | %[1]s = C.CblasNoTrans 319 | case blas.ConjTrans: 320 | %[1]s = C.CblasConjTrans 321 | default: 322 | panic(badTranspose) 323 | } 324 | `, n) 325 | case strings.HasPrefix(d.Name, "cblas_cs"), strings.HasPrefix(d.Name, "cblas_zs"): 326 | fmt.Fprintf(buf, ` switch %[1]s { 327 | case blas.NoTrans: 328 | %[1]s = C.CblasNoTrans 329 | case blas.Trans: 330 | %[1]s = C.CblasTrans 331 | default: 332 | panic(badTranspose) 333 | } 334 | `, n) 335 | default: 336 | fmt.Fprintf(buf, ` switch %[1]s { 337 | case blas.NoTrans: 338 | %[1]s = C.CblasNoTrans 339 | case blas.Trans: 340 | %[1]s = C.CblasTrans 341 | case blas.ConjTrans: 342 | %[1]s = C.CblasConjTrans 343 | default: 344 | panic(badTranspose) 345 | } 346 | `, n) 347 | } 348 | } 349 | } 350 | 351 | func uplo(buf *bytes.Buffer, _ binding.Declaration, p binding.Parameter) { 352 | if p.Name() != "Uplo" { 353 | return 354 | } 355 | fmt.Fprint(buf, ` switch ul { 356 | case blas.Upper: 357 | ul = C.CblasUpper 358 | case blas.Lower: 359 | ul = C.CblasLower 360 | default: 361 | panic(badUplo) 362 | } 363 | `) 364 | } 365 | 366 | func diag(buf *bytes.Buffer, _ binding.Declaration, p binding.Parameter) { 367 | if p.Name() != "Diag" { 368 | return 369 | } 370 | fmt.Fprint(buf, ` switch d { 371 | case blas.NonUnit: 372 | d = C.CblasNonUnit 373 | case blas.Unit: 374 | d = C.CblasUnit 375 | default: 376 | panic(badDiag) 377 | } 378 | `) 379 | return 380 | } 381 | 382 | func side(buf *bytes.Buffer, _ binding.Declaration, p binding.Parameter) { 383 | if p.Name() != "Side" { 384 | return 385 | } 386 | fmt.Fprint(buf, ` switch s { 387 | case blas.Left: 388 | s = C.CblasLeft 389 | case blas.Right: 390 | s = C.CblasRight 391 | default: 392 | panic(badSide) 393 | } 394 | `) 395 | } 396 | 397 | func shape(buf *bytes.Buffer, _ binding.Declaration, p binding.Parameter) { 398 | switch n := binding.LowerCaseFirst(p.Name()); n { 399 | case "m", "n", "k", "kL", "kU": 400 | fmt.Fprintf(buf, ` if %[1]s < 0 { 401 | panic(%[1]sLT0) 402 | } 403 | `, n) 404 | } 405 | } 406 | 407 | func leadingDim(buf *bytes.Buffer, d binding.Declaration, p binding.Parameter) { 408 | pname := binding.LowerCaseFirst(p.Name()) 409 | if !strings.HasPrefix(pname, "ld") { 410 | return 411 | } 412 | 413 | if pname == "ldc" { 414 | // C matrix has always n columns. 415 | fmt.Fprintf(buf, ` if ldc < max(1, n) { 416 | panic(badLdC) 417 | } 418 | `) 419 | return 420 | } 421 | 422 | has := make(map[string]bool) 423 | for _, p := range d.Parameters() { 424 | has[shorten(binding.LowerCaseFirst(p.Name()))] = true 425 | } 426 | 427 | switch d.Name { 428 | case "cblas_sgemm", "cblas_dgemm", "cblas_cgemm", "cblas_zgemm": 429 | if pname == "lda" { 430 | fmt.Fprint(buf, ` var rowA, colA, rowB, colB int 431 | if tA == C.CblasNoTrans { 432 | rowA, colA = m, k 433 | } else { 434 | rowA, colA = k, m 435 | } 436 | if tB == C.CblasNoTrans { 437 | rowB, colB = k, n 438 | } else { 439 | rowB, colB = n, k 440 | } 441 | if lda < max(1, colA) { 442 | panic(badLdA) 443 | } 444 | `) 445 | } else { 446 | fmt.Fprint(buf, ` if ldb < max(1, colB) { 447 | panic(badLdB) 448 | } 449 | `) 450 | } 451 | return 452 | 453 | case "cblas_ssyrk", "cblas_dsyrk", "cblas_csyrk", "cblas_zsyrk", 454 | "cblas_ssyr2k", "cblas_dsyr2k", "cblas_csyr2k", "cblas_zsyr2k", 455 | "cblas_cherk", "cblas_zherk", "cblas_cher2k", "cblas_zher2k": 456 | if pname == "lda" { 457 | fmt.Fprint(buf, ` var row, col int 458 | if t == C.CblasNoTrans { 459 | row, col = n, k 460 | } else { 461 | row, col = k, n 462 | } 463 | `) 464 | } 465 | fmt.Fprintf(buf, ` if %s < max(1, col) { 466 | panic(bad%s) 467 | } 468 | `, pname, ldToPanicString(pname)) 469 | return 470 | 471 | case "cblas_sgbmv", "cblas_dgbmv", "cblas_cgbmv", "cblas_zgbmv": 472 | fmt.Fprintf(buf, ` if lda < kL+kU+1 { 473 | panic(badLdA) 474 | } 475 | `) 476 | return 477 | } 478 | 479 | switch { 480 | case has["k"]: 481 | // cblas_stbmv cblas_dtbmv cblas_ctbmv cblas_ztbmv 482 | // cblas_stbsv cblas_dtbsv cblas_ctbsv cblas_ztbsv 483 | // cblas_ssbmv cblas_dsbmv cblas_chbmv cblas_zhbmv 484 | fmt.Fprintf(buf, ` if lda < k+1 { 485 | panic(badLdA) 486 | } 487 | `) 488 | case has["s"] && pname == "lda": 489 | // cblas_ssymm cblas_dsymm cblas_csymm cblas_zsymm 490 | // cblas_strmm cblas_dtrmm cblas_ctrmm cblas_ztrmm 491 | // cblas_strsm cblas_dtrsm cblas_ctrsm cblas_ztrsm 492 | // cblas_chemm cblas_zhemm 493 | fmt.Fprintf(buf, ` var k int 494 | if s == C.CblasLeft { 495 | k = m 496 | } else { 497 | k = n 498 | } 499 | if lda < max(1, k) { 500 | panic(badLdA) 501 | } 502 | `) 503 | default: 504 | fmt.Fprintf(buf, ` if %s < max(1, n) { 505 | panic(bad%s) 506 | } 507 | `, pname, ldToPanicString(pname)) 508 | } 509 | } 510 | 511 | func zeroInc(buf *bytes.Buffer, _ binding.Declaration, p binding.Parameter) { 512 | switch n := binding.LowerCaseFirst(p.Name()); n { 513 | case "incX": 514 | fmt.Fprintf(buf, ` if incX == 0 { 515 | panic(zeroIncX) 516 | } 517 | `) 518 | case "incY": 519 | fmt.Fprintf(buf, ` if incY == 0 { 520 | panic(zeroIncY) 521 | } 522 | `) 523 | } 524 | return 525 | } 526 | 527 | func noWork(buf *bytes.Buffer, d binding.Declaration, p binding.Parameter) { 528 | if d.CParameters[len(d.CParameters)-1] != p.Parameter { 529 | return // Come back later. 530 | } 531 | 532 | switch d.Name { 533 | case "cblas_snrm2", "cblas_dnrm2", "cblas_scnrm2", "cblas_dznrm2", 534 | "cblas_sasum", "cblas_dasum", "cblas_scasum", "cblas_dzasum": 535 | fmt.Fprint(buf, ` 536 | // Quick return if possible. 537 | if n == 0 || incX < 0 { 538 | return 0 539 | } 540 | 541 | // For zero matrix size the following slice length checks are trivially satisfied. 542 | `) 543 | return 544 | 545 | case "cblas_sscal", "cblas_dscal", "cblas_cscal", "cblas_zscal", "cblas_csscal", "cblas_zdscal": 546 | fmt.Fprint(buf, ` 547 | // Quick return if possible. 548 | if n == 0 || incX < 0 { 549 | return 550 | } 551 | 552 | // For zero matrix size the following slice length checks are trivially satisfied. 553 | `) 554 | return 555 | 556 | case "cblas_isamax", "cblas_idamax", "cblas_icamax", "cblas_izamax": 557 | fmt.Fprint(buf, ` 558 | // Quick return if possible. 559 | if n == 0 || incX < 0 { 560 | return -1 561 | } 562 | 563 | // For zero matrix size the following slice length checks are trivially satisfied. 564 | `) 565 | return 566 | } 567 | 568 | var value string 569 | switch d.Return.String() { 570 | case "float", "double": 571 | value = " 0" 572 | } 573 | var hasM bool 574 | for _, p := range d.Parameters() { 575 | if shorten(binding.LowerCaseFirst(p.Name())) == "m" { 576 | hasM = true 577 | } 578 | } 579 | if !hasM { 580 | fmt.Fprintf(buf, ` 581 | // Quick return if possible. 582 | if n == 0 { 583 | return%s 584 | } 585 | 586 | // For zero matrix size the following slice length checks are trivially satisfied. 587 | `, value) 588 | } else { 589 | fmt.Fprintf(buf, ` 590 | // Quick return if possible. 591 | if m == 0 || n == 0 { 592 | return 593 | } 594 | 595 | // For zero matrix size the following slice length checks are trivially satisfied. 596 | `) 597 | } 598 | } 599 | 600 | func sliceLength(buf *bytes.Buffer, d binding.Declaration, p binding.Parameter) { 601 | pname := shorten(binding.LowerCaseFirst(p.Name())) 602 | switch pname { 603 | case "a", "b", "c", "ap", "x", "y": 604 | default: 605 | return 606 | } 607 | 608 | if pname == "ap" { 609 | fmt.Fprint(buf, ` if len(ap) < n*(n+1)/2 { 610 | panic(shortAP) 611 | } 612 | `) 613 | return 614 | } 615 | 616 | has := make(map[string]bool) 617 | for _, p := range d.Parameters() { 618 | has[shorten(binding.LowerCaseFirst(p.Name()))] = true 619 | } 620 | 621 | if pname == "c" { 622 | if p.Type().Kind() != cc.Ptr { 623 | // srot or drot 624 | return 625 | } 626 | if has["m"] { 627 | fmt.Fprint(buf, ` if len(c) < ldc*(m-1)+n { 628 | panic(shortC) 629 | } 630 | `) 631 | return 632 | } 633 | fmt.Fprint(buf, ` if len(c) < ldc*(n-1)+n { 634 | panic(shortC) 635 | } 636 | `) 637 | return 638 | } 639 | 640 | switch d.Name { 641 | case "cblas_snrm2", "cblas_dnrm2", "cblas_scnrm2", "cblas_dznrm2", 642 | "cblas_sasum", "cblas_dasum", "cblas_scasum", "cblas_dzasum", 643 | "cblas_sscal", "cblas_dscal", "cblas_cscal", "cblas_zscal", "cblas_csscal", "cblas_zdscal", 644 | "cblas_isamax", "cblas_idamax", "cblas_icamax", "cblas_izamax": 645 | fmt.Fprint(buf, ` if len(x) <= (n-1)*incX { 646 | panic(shortX) 647 | } 648 | `) 649 | return 650 | 651 | case "cblas_ssyrk", "cblas_dsyrk", "cblas_csyrk", "cblas_zsyrk", 652 | "cblas_ssyr2k", "cblas_dsyr2k", "cblas_csyr2k", "cblas_zsyr2k", 653 | "cblas_cherk", "cblas_zherk", "cblas_cher2k", "cblas_zher2k": 654 | switch pname { 655 | case "a": 656 | // row and col have already been declared in leadingDim. 657 | fmt.Fprintf(buf, ` if len(a) < lda*(row-1)+col { 658 | panic(shortA) 659 | } 660 | `) 661 | case "b": 662 | fmt.Fprintf(buf, ` if len(b) < ldb*(row-1)+col { 663 | panic(shortB) 664 | } 665 | `) 666 | } 667 | return 668 | 669 | case "cblas_sgemm", "cblas_dgemm", "cblas_cgemm", "cblas_zgemm": 670 | switch pname { 671 | case "a": 672 | // rowA and colA have already been declared in leadingDim. 673 | fmt.Fprint(buf, ` if len(a) < lda*(rowA-1)+colA { 674 | panic(shortA) 675 | } 676 | `) 677 | case "b": 678 | fmt.Fprint(buf, ` if len(b) < ldb*(rowB-1)+colB { 679 | panic(shortB) 680 | } 681 | `) 682 | } 683 | return 684 | 685 | case "cblas_sgbmv", "cblas_dgbmv", "cblas_cgbmv", "cblas_zgbmv", 686 | "cblas_sgemv", "cblas_dgemv", "cblas_cgemv", "cblas_zgemv": 687 | switch pname { 688 | case "x": 689 | fmt.Fprint(buf, ` var lenX, lenY int 690 | if tA == C.CblasNoTrans { 691 | lenX, lenY = n, m 692 | } else { 693 | lenX, lenY = m, n 694 | } 695 | if (incX > 0 && len(x) <= (lenX-1)*incX) || (incX < 0 && len(x) <= (1-lenX)*incX) { 696 | panic(shortX) 697 | } 698 | `) 699 | case "y": 700 | fmt.Fprint(buf, ` if (incY > 0 && len(y) <= (lenY-1)*incY) || (incY < 0 && len(y) <= (1-lenY)*incY) { 701 | panic(shortY) 702 | } 703 | `) 704 | case "a": 705 | if has["kL"] { 706 | fmt.Fprintf(buf, ` if len(a) < lda*(min(m, n+kL)-1)+kL+kU+1 { 707 | panic(shortA) 708 | } 709 | `) 710 | } else { 711 | fmt.Fprint(buf, ` if len(a) < lda*(m-1)+n { 712 | panic(shortA) 713 | } 714 | `) 715 | } 716 | } 717 | return 718 | 719 | case "cblas_sspr2", "cblas_dspr2", "cblas_chpr", "cblas_zhpr": 720 | switch pname { 721 | case "a": 722 | fmt.Fprint(buf, ` if len(a) < n*(n+1)/2 { 723 | panic(shortA) 724 | } 725 | `) 726 | return 727 | } 728 | } 729 | 730 | switch pname { 731 | case "x": 732 | var label string 733 | if has["m"] { 734 | label = "m" 735 | } else { 736 | label = "n" 737 | } 738 | fmt.Fprintf(buf, ` if (incX > 0 && len(x) <= (%[1]s-1)*incX) || (incX < 0 && len(x) <= (1-%[1]s)*incX) { 739 | panic(shortX) 740 | } 741 | `, label) 742 | 743 | case "y": 744 | fmt.Fprint(buf, ` if (incY > 0 && len(y) <= (n-1)*incY) || (incY < 0 && len(y) <= (1-n)*incY) { 745 | panic(shortY) 746 | } 747 | `) 748 | 749 | case "a": 750 | switch { 751 | case has["s"]: 752 | fmt.Fprintf(buf, ` if len(a) < lda*(k-1)+k { 753 | panic(shortA) 754 | } 755 | `) 756 | case has["k"]: 757 | fmt.Fprintf(buf, ` if len(a) < lda*(n-1)+k+1 { 758 | panic(shortA) 759 | } 760 | `) 761 | case has["m"]: 762 | fmt.Fprint(buf, ` if len(a) < lda*(m-1)+n { 763 | panic(shortA) 764 | } 765 | `) 766 | default: 767 | fmt.Fprint(buf, ` if len(a) < lda*(n-1)+n { 768 | panic(shortA) 769 | } 770 | `) 771 | } 772 | 773 | case "b": 774 | fmt.Fprint(buf, ` if len(b) < ldb*(m-1)+n { 775 | panic(shortB) 776 | } 777 | `) 778 | } 779 | 780 | return 781 | } 782 | 783 | var addrTypes = map[string]string{ 784 | "char": "byte", 785 | "int": "int32", 786 | "float": "float32", 787 | "double": "float64", 788 | } 789 | 790 | func address(buf *bytes.Buffer, d binding.Declaration, p binding.Parameter) { 791 | n := shorten(binding.LowerCaseFirst(p.Name())) 792 | blasName := strings.TrimPrefix(d.Name, prefix) 793 | switch n { 794 | case "a", "b", "c", "ap", "x", "y": 795 | default: 796 | return 797 | } 798 | if p.Type().Kind() == cc.Ptr { 799 | t := addrTypes[strings.TrimPrefix(p.Type().Element().String(), "const ")] 800 | if t == "" { 801 | switch { 802 | case blasName[0] == 'c', blasName[1] == 'c' && blasName[0] != 'z': 803 | t = "complex64" 804 | case blasName[0] == 'z', blasName[1] == 'z': 805 | t = "complex128" 806 | } 807 | } 808 | fmt.Fprintf(buf, ` var _%[1]s *%[2]s 809 | if len(%[1]s) > 0 { 810 | _%[1]s = &%[1]s[0] 811 | } 812 | `, n, t) 813 | } 814 | return 815 | } 816 | 817 | func ldToPanicString(ld string) string { 818 | switch ld { 819 | case "lda": 820 | return "LdA" 821 | case "ldb": 822 | return "LdB" 823 | case "ldc": 824 | return "LdC" 825 | default: 826 | panic("unexpected ld") 827 | } 828 | } 829 | 830 | // pathTo returns the path to package within the given module. If running 831 | // in module mode, this will look within the module in $GOPATH/pkg/mod 832 | // at the correct version, otherwise it will find the version installed 833 | // at $GOPATH/src/module/pkg. 834 | func pathTo(module, pkg string) string { 835 | gopath, ok := os.LookupEnv("GOPATH") 836 | if !ok { 837 | var err error 838 | gopath, err = os.UserHomeDir() 839 | if err != nil { 840 | log.Fatal(err) 841 | } 842 | gopath = filepath.Join(gopath, "go") 843 | } 844 | 845 | cmd := exec.Command("go", "list", "-m", module) 846 | var buf, stderr bytes.Buffer 847 | cmd.Stdout = &buf 848 | cmd.Stderr = &stderr 849 | err := cmd.Run() 850 | if err != nil { 851 | log.Fatalf("module aware go list failed with stderr output %q: %v", stderr.String(), err) 852 | } 853 | version := strings.TrimSpace(strings.Join(strings.Split(buf.String(), " "), "@")) 854 | return filepath.Join(gopath, "pkg", "mod", version, pkg) 855 | } 856 | 857 | const handwritten = `// Code generated by "go generate gonum.org/v1/netlib/blas/netlib" from {{.}}; DO NOT EDIT. 858 | 859 | // Copyright ©2014 The Gonum Authors. All rights reserved. 860 | // Use of this source code is governed by a BSD-style 861 | // license that can be found in the LICENSE file. 862 | 863 | package netlib 864 | 865 | /* 866 | #cgo CFLAGS: -g -O2 867 | #include "{{.}}" 868 | */ 869 | import "C" 870 | 871 | import ( 872 | "unsafe" 873 | 874 | "gonum.org/v1/gonum/blas" 875 | ) 876 | 877 | // Type check assertions: 878 | var ( 879 | _ blas.Float32 = Implementation{} 880 | _ blas.Float64 = Implementation{} 881 | _ blas.Complex64 = Implementation{} 882 | _ blas.Complex128 = Implementation{} 883 | ) 884 | 885 | // Type layout is used to specify the matrix storage format. We still interact with 886 | // an API that allows client calls to specify layout, so this is here to document that fact. 887 | type layout int 888 | 889 | const rowMajor layout = C.CblasRowMajor 890 | 891 | func min(a, b int) int { 892 | if a < b { 893 | return a 894 | } 895 | return b 896 | } 897 | 898 | func max(a, b int) int { 899 | if a > b { 900 | return a 901 | } 902 | return b 903 | } 904 | 905 | type Implementation struct{} 906 | 907 | // Special cases... 908 | 909 | type srotmParams struct { 910 | flag float32 911 | h [4]float32 912 | } 913 | 914 | type drotmParams struct { 915 | flag float64 916 | h [4]float64 917 | } 918 | 919 | func (Implementation) Srotg(a float32, b float32) (c float32, s float32, r float32, z float32) { 920 | C.cblas_srotg((*C.float)(&a), (*C.float)(&b), (*C.float)(&c), (*C.float)(&s)) 921 | return c, s, a, b 922 | } 923 | func (Implementation) Srotmg(d1 float32, d2 float32, b1 float32, b2 float32) (p blas.SrotmParams, rd1 float32, rd2 float32, rb1 float32) { 924 | var pi srotmParams 925 | C.cblas_srotmg((*C.float)(&d1), (*C.float)(&d2), (*C.float)(&b1), C.float(b2), (*C.float)(unsafe.Pointer(&pi))) 926 | return blas.SrotmParams{Flag: blas.Flag(pi.flag), H: pi.h}, d1, d2, b1 927 | } 928 | func (Implementation) Srotm(n int, x []float32, incX int, y []float32, incY int, p blas.SrotmParams) { 929 | if n < 0 { 930 | panic(nLT0) 931 | } 932 | if incX == 0 { 933 | panic(zeroIncX) 934 | } 935 | if incY == 0 { 936 | panic(zeroIncY) 937 | } 938 | if p.Flag < blas.Identity || p.Flag > blas.Diagonal { 939 | panic(badFlag) 940 | } 941 | 942 | // Quick return if possible. 943 | if n == 0 { 944 | return 945 | } 946 | 947 | // For zero matrix size the following slice length checks are trivially satisfied. 948 | if (incX > 0 && len(x) <= (n-1)*incX) || (incX < 0 && len(x) <= (1-n)*incX) { 949 | panic(shortX) 950 | } 951 | if (incY > 0 && len(y) <= (n-1)*incY) || (incY < 0 && len(y) <= (1-n)*incY) { 952 | panic(shortY) 953 | } 954 | var _x *float32 955 | if len(x) > 0 { 956 | _x = &x[0] 957 | } 958 | var _y *float32 959 | if len(y) > 0 { 960 | _y = &y[0] 961 | } 962 | pi := srotmParams{ 963 | flag: float32(p.Flag), 964 | h: p.H, 965 | } 966 | C.cblas_srotm(C.int(n), (*C.float)(_x), C.int(incX), (*C.float)(_y), C.int(incY), (*C.float)(unsafe.Pointer(&pi))) 967 | } 968 | func (Implementation) Drotg(a float64, b float64) (c float64, s float64, r float64, z float64) { 969 | C.cblas_drotg((*C.double)(&a), (*C.double)(&b), (*C.double)(&c), (*C.double)(&s)) 970 | return c, s, a, b 971 | } 972 | func (Implementation) Drotmg(d1 float64, d2 float64, b1 float64, b2 float64) (p blas.DrotmParams, rd1 float64, rd2 float64, rb1 float64) { 973 | var pi drotmParams 974 | C.cblas_drotmg((*C.double)(&d1), (*C.double)(&d2), (*C.double)(&b1), C.double(b2), (*C.double)(unsafe.Pointer(&pi))) 975 | return blas.DrotmParams{Flag: blas.Flag(pi.flag), H: pi.h}, d1, d2, b1 976 | } 977 | func (Implementation) Drotm(n int, x []float64, incX int, y []float64, incY int, p blas.DrotmParams) { 978 | if n < 0 { 979 | panic(nLT0) 980 | } 981 | if incX == 0 { 982 | panic(zeroIncX) 983 | } 984 | if incY == 0 { 985 | panic(zeroIncY) 986 | } 987 | if p.Flag < blas.Identity || p.Flag > blas.Diagonal { 988 | panic(badFlag) 989 | } 990 | 991 | // Quick return if possible. 992 | if n == 0 { 993 | return 994 | } 995 | 996 | // For zero matrix size the following slice length checks are trivially satisfied. 997 | if (incX > 0 && len(x) <= (n-1)*incX) || (incX < 0 && len(x) <= (1-n)*incX) { 998 | panic(shortX) 999 | } 1000 | if (incY > 0 && len(y) <= (n-1)*incY) || (incY < 0 && len(y) <= (1-n)*incY) { 1001 | panic(shortY) 1002 | } 1003 | var _x *float64 1004 | if len(x) > 0 { 1005 | _x = &x[0] 1006 | } 1007 | var _y *float64 1008 | if len(y) > 0 { 1009 | _y = &y[0] 1010 | } 1011 | pi := drotmParams{ 1012 | flag: float64(p.Flag), 1013 | h: p.H, 1014 | } 1015 | C.cblas_drotm(C.int(n), (*C.double)(_x), C.int(incX), (*C.double)(_y), C.int(incY), (*C.double)(unsafe.Pointer(&pi))) 1016 | } 1017 | func (Implementation) Cdotu(n int, x []complex64, incX int, y []complex64, incY int) (dotu complex64) { 1018 | if n < 0 { 1019 | panic(nLT0) 1020 | } 1021 | if incX == 0 { 1022 | panic(zeroIncX) 1023 | } 1024 | if incY == 0 { 1025 | panic(zeroIncY) 1026 | } 1027 | 1028 | // Quick return if possible. 1029 | if n == 0 { 1030 | return 0 1031 | } 1032 | 1033 | // For zero matrix size the following slice length checks are trivially satisfied. 1034 | if (incX > 0 && len(x) <= (n-1)*incX) || (incX < 0 && len(x) <= (1-n)*incX) { 1035 | panic(shortX) 1036 | } 1037 | if (incY > 0 && len(y) <= (n-1)*incY) || (incY < 0 && len(y) <= (1-n)*incY) { 1038 | panic(shortY) 1039 | } 1040 | var _x *complex64 1041 | if len(x) > 0 { 1042 | _x = &x[0] 1043 | } 1044 | var _y *complex64 1045 | if len(y) > 0 { 1046 | _y = &y[0] 1047 | } 1048 | C.cblas_cdotu_sub(C.int(n), unsafe.Pointer(_x), C.int(incX), unsafe.Pointer(_y), C.int(incY), unsafe.Pointer(&dotu)) 1049 | return dotu 1050 | } 1051 | func (Implementation) Cdotc(n int, x []complex64, incX int, y []complex64, incY int) (dotc complex64) { 1052 | if n < 0 { 1053 | panic(nLT0) 1054 | } 1055 | if incX == 0 { 1056 | panic(zeroIncX) 1057 | } 1058 | if incY == 0 { 1059 | panic(zeroIncY) 1060 | } 1061 | 1062 | // Quick return if possible. 1063 | if n == 0 { 1064 | return 0 1065 | } 1066 | 1067 | // For zero matrix size the following slice length checks are trivially satisfied. 1068 | if (incX > 0 && len(x) <= (n-1)*incX) || (incX < 0 && len(x) <= (1-n)*incX) { 1069 | panic(shortX) 1070 | } 1071 | if (incY > 0 && len(y) <= (n-1)*incY) || (incY < 0 && len(y) <= (1-n)*incY) { 1072 | panic(shortY) 1073 | } 1074 | var _x *complex64 1075 | if len(x) > 0 { 1076 | _x = &x[0] 1077 | } 1078 | var _y *complex64 1079 | if len(y) > 0 { 1080 | _y = &y[0] 1081 | } 1082 | C.cblas_cdotc_sub(C.int(n), unsafe.Pointer(_x), C.int(incX), unsafe.Pointer(_y), C.int(incY), unsafe.Pointer(&dotc)) 1083 | return dotc 1084 | } 1085 | func (Implementation) Zdotu(n int, x []complex128, incX int, y []complex128, incY int) (dotu complex128) { 1086 | if n < 0 { 1087 | panic(nLT0) 1088 | } 1089 | if incX == 0 { 1090 | panic(zeroIncX) 1091 | } 1092 | if incY == 0 { 1093 | panic(zeroIncY) 1094 | } 1095 | 1096 | // Quick return if possible. 1097 | if n == 0 { 1098 | return 0 1099 | } 1100 | 1101 | // For zero matrix size the following slice length checks are trivially satisfied. 1102 | if (incX > 0 && len(x) <= (n-1)*incX) || (incX < 0 && len(x) <= (1-n)*incX) { 1103 | panic(shortX) 1104 | } 1105 | if (incY > 0 && len(y) <= (n-1)*incY) || (incY < 0 && len(y) <= (1-n)*incY) { 1106 | panic(shortY) 1107 | } 1108 | var _x *complex128 1109 | if len(x) > 0 { 1110 | _x = &x[0] 1111 | } 1112 | var _y *complex128 1113 | if len(y) > 0 { 1114 | _y = &y[0] 1115 | } 1116 | C.cblas_zdotu_sub(C.int(n), unsafe.Pointer(_x), C.int(incX), unsafe.Pointer(_y), C.int(incY), unsafe.Pointer(&dotu)) 1117 | return dotu 1118 | } 1119 | func (Implementation) Zdotc(n int, x []complex128, incX int, y []complex128, incY int) (dotc complex128) { 1120 | if n < 0 { 1121 | panic(nLT0) 1122 | } 1123 | if incX == 0 { 1124 | panic(zeroIncX) 1125 | } 1126 | if incY == 0 { 1127 | panic(zeroIncY) 1128 | } 1129 | 1130 | // Quick return if possible. 1131 | if n == 0 { 1132 | return 0 1133 | } 1134 | 1135 | // For zero matrix size the following slice length checks are trivially satisfied. 1136 | if (incX > 0 && len(x) <= (n-1)*incX) || (incX < 0 && len(x) <= (1-n)*incX) { 1137 | panic(shortX) 1138 | } 1139 | if (incY > 0 && len(y) <= (n-1)*incY) || (incY < 0 && len(y) <= (1-n)*incY) { 1140 | panic(shortY) 1141 | } 1142 | var _x *complex128 1143 | if len(x) > 0 { 1144 | _x = &x[0] 1145 | } 1146 | var _y *complex128 1147 | if len(y) > 0 { 1148 | _y = &y[0] 1149 | } 1150 | C.cblas_zdotc_sub(C.int(n), unsafe.Pointer(_x), C.int(incX), unsafe.Pointer(_y), C.int(incY), unsafe.Pointer(&dotc)) 1151 | return dotc 1152 | } 1153 | 1154 | // Generated cases ... 1155 | 1156 | ` 1157 | -------------------------------------------------------------------------------- /blas/netlib/generate_errors.go: -------------------------------------------------------------------------------- 1 | // Copyright ©2018 The Gonum Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build ignore 6 | 7 | package main 8 | 9 | import ( 10 | "bytes" 11 | "fmt" 12 | "go/ast" 13 | "go/parser" 14 | "go/printer" 15 | "go/token" 16 | "log" 17 | "os" 18 | "os/exec" 19 | "path/filepath" 20 | "strings" 21 | ) 22 | 23 | const ( 24 | srcModule = "gonum.org/v1/gonum" 25 | errorFile = "blas/gonum/errors.go" 26 | ) 27 | 28 | func main() { 29 | path, err := pathTo(srcModule, errorFile) 30 | if err != nil { 31 | log.Fatalf("no source for %q: %v", errorFile, err) 32 | } 33 | 34 | fset := token.NewFileSet() 35 | f, err := parser.ParseFile(fset, path, nil, parser.ParseComments) 36 | if err != nil { 37 | log.Fatalf("failed to parse %q: %v", path, err) 38 | } 39 | 40 | dst := filepath.Base(errorFile) 41 | o, err := os.Create(dst) 42 | if err != nil { 43 | log.Fatalf("failed to create %q: %v", dst, err) 44 | } 45 | defer o.Close() 46 | 47 | fmt.Fprintln(o, header) 48 | for _, cg := range f.Comments { 49 | for _, c := range cg.List { 50 | fmt.Fprintln(o, c.Text) 51 | } 52 | break 53 | } 54 | fmt.Fprintln(o, pkg) 55 | p := printer.Config{ 56 | Mode: printer.UseSpaces | printer.TabIndent, 57 | Tabwidth: 8, 58 | } 59 | // Remove comment associated with the const block. 60 | for _, d := range f.Decls { 61 | if d, ok := d.(*ast.GenDecl); ok { 62 | d.Doc = nil 63 | } 64 | } 65 | p.Fprint(o, fset, f.Decls) 66 | fmt.Fprintln(o) 67 | } 68 | 69 | // pathTo returns the path to file within the given module. If running 70 | // in module mode, this will look within the module in $GOPATH/pkg/mod 71 | // at the correct version, otherwise it will find the version installed 72 | // at $GOPATH/src/module/file. 73 | func pathTo(module, file string) (string, error) { 74 | gopath, ok := os.LookupEnv("GOPATH") 75 | if !ok { 76 | var err error 77 | gopath, err = os.UserHomeDir() 78 | if err != nil { 79 | return "", err 80 | } 81 | gopath = filepath.Join(gopath, "go") 82 | } 83 | 84 | cmd := exec.Command("go", "list", "-m", module) 85 | var buf, stderr bytes.Buffer 86 | cmd.Stdout = &buf 87 | cmd.Stderr = &stderr 88 | err := cmd.Run() 89 | if err != nil { 90 | // TODO(kortschak): Make this an error when go1.10 support is dropped. 91 | log.Printf("module aware go list failed with stderr output %q: %v", stderr.String(), err) 92 | return filepath.Join(gopath, "src", module, file), nil 93 | } 94 | version := strings.TrimSpace(strings.Join(strings.Split(buf.String(), " "), "@")) 95 | return filepath.Join(gopath, "pkg", "mod", version, file), nil 96 | } 97 | 98 | const ( 99 | header = `// Code generated by "go generate gonum.org/v1/netlib/blas/netlib”; DO NOT EDIT. 100 | ` 101 | pkg = ` 102 | package netlib 103 | 104 | // Copied from gonum/blas/gonum. Keep in sync.` 105 | ) 106 | -------------------------------------------------------------------------------- /blas/netlib/level1cmplx128_test.go: -------------------------------------------------------------------------------- 1 | // Copyright ©2017 The Gonum Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package netlib 6 | 7 | import ( 8 | "testing" 9 | 10 | "gonum.org/v1/gonum/blas/testblas" 11 | ) 12 | 13 | func TestDzasum(t *testing.T) { 14 | testblas.DzasumTest(t, impl) 15 | } 16 | 17 | func TestDznrm2(t *testing.T) { 18 | testblas.Dznrm2Test(t, impl) 19 | } 20 | 21 | func TestIzamax(t *testing.T) { 22 | testblas.IzamaxTest(t, impl) 23 | } 24 | 25 | func TestZaxpy(t *testing.T) { 26 | testblas.ZaxpyTest(t, impl) 27 | } 28 | 29 | func TestZcopy(t *testing.T) { 30 | testblas.ZcopyTest(t, impl) 31 | } 32 | 33 | func TestZdotc(t *testing.T) { 34 | testblas.ZdotcTest(t, impl) 35 | } 36 | 37 | func TestZdotu(t *testing.T) { 38 | testblas.ZdotuTest(t, impl) 39 | } 40 | 41 | func TestZdscal(t *testing.T) { 42 | testblas.ZdscalTest(t, impl) 43 | } 44 | 45 | func TestZscal(t *testing.T) { 46 | testblas.ZscalTest(t, impl) 47 | } 48 | 49 | func TestZswap(t *testing.T) { 50 | testblas.ZswapTest(t, impl) 51 | } 52 | -------------------------------------------------------------------------------- /blas/netlib/level1double_test.go: -------------------------------------------------------------------------------- 1 | // Copyright ©2014 The Gonum Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package netlib 6 | 7 | import ( 8 | "testing" 9 | 10 | "gonum.org/v1/gonum/blas/testblas" 11 | ) 12 | 13 | var impl Implementation 14 | 15 | func TestDasum(t *testing.T) { 16 | testblas.DasumTest(t, impl) 17 | } 18 | 19 | func TestDaxpy(t *testing.T) { 20 | testblas.DaxpyTest(t, impl) 21 | } 22 | 23 | func TestDdot(t *testing.T) { 24 | testblas.DdotTest(t, impl) 25 | } 26 | 27 | func TestDnrm2(t *testing.T) { 28 | testblas.Dnrm2Test(t, impl) 29 | } 30 | 31 | func TestIdamax(t *testing.T) { 32 | testblas.IdamaxTest(t, impl) 33 | } 34 | 35 | func TestDswap(t *testing.T) { 36 | testblas.DswapTest(t, impl) 37 | } 38 | 39 | func TestDcopy(t *testing.T) { 40 | testblas.DcopyTest(t, impl) 41 | } 42 | 43 | func TestDrotg(t *testing.T) { 44 | testblas.DrotgTest(t, impl, true) 45 | } 46 | 47 | func TestDrotmg(t *testing.T) { 48 | testblas.DrotmgTest(t, impl) 49 | } 50 | 51 | func TestDrot(t *testing.T) { 52 | testblas.DrotTest(t, impl) 53 | } 54 | 55 | func TestDrotm(t *testing.T) { 56 | testblas.DrotmTest(t, impl) 57 | } 58 | 59 | func TestDscal(t *testing.T) { 60 | testblas.DscalTest(t, impl) 61 | } 62 | -------------------------------------------------------------------------------- /blas/netlib/level2cmplx128_test.go: -------------------------------------------------------------------------------- 1 | // Copyright ©2017 The Gonum Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package netlib 6 | 7 | import ( 8 | "testing" 9 | 10 | "gonum.org/v1/gonum/blas/testblas" 11 | ) 12 | 13 | func TestZgbmv(t *testing.T) { 14 | testblas.ZgbmvTest(t, impl) 15 | } 16 | 17 | func TestZgemv(t *testing.T) { 18 | testblas.ZgemvTest(t, impl) 19 | } 20 | 21 | func TestZgerc(t *testing.T) { 22 | testblas.ZgercTest(t, impl) 23 | } 24 | 25 | func TestZgeru(t *testing.T) { 26 | testblas.ZgeruTest(t, impl) 27 | } 28 | 29 | func TestZhbmv(t *testing.T) { 30 | testblas.ZhbmvTest(t, impl) 31 | } 32 | 33 | func TestZhemv(t *testing.T) { 34 | testblas.ZhemvTest(t, impl) 35 | } 36 | 37 | func TestZher(t *testing.T) { 38 | testblas.ZherTest(t, impl) 39 | } 40 | 41 | func TestZher2(t *testing.T) { 42 | testblas.Zher2Test(t, impl) 43 | } 44 | 45 | func TestZhpmv(t *testing.T) { 46 | testblas.ZhpmvTest(t, impl) 47 | } 48 | 49 | func TestZhpr(t *testing.T) { 50 | testblas.ZhprTest(t, impl) 51 | } 52 | 53 | func TestZhpr2(t *testing.T) { 54 | testblas.Zhpr2Test(t, impl) 55 | } 56 | 57 | func TestZtbmv(t *testing.T) { 58 | testblas.ZtbmvTest(t, impl) 59 | } 60 | 61 | func TestZtbsv(t *testing.T) { 62 | testblas.ZtbsvTest(t, impl) 63 | } 64 | 65 | func TestZtpmv(t *testing.T) { 66 | testblas.ZtpmvTest(t, impl) 67 | } 68 | 69 | func TestZtpsv(t *testing.T) { 70 | testblas.ZtpsvTest(t, impl) 71 | } 72 | 73 | func TestZtrmv(t *testing.T) { 74 | testblas.ZtrmvTest(t, impl) 75 | } 76 | 77 | func TestZtrsv(t *testing.T) { 78 | testblas.ZtrsvTest(t, impl) 79 | } 80 | -------------------------------------------------------------------------------- /blas/netlib/level2double_test.go: -------------------------------------------------------------------------------- 1 | // Copyright ©2014 The Gonum Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package netlib 6 | 7 | import ( 8 | "testing" 9 | 10 | "gonum.org/v1/gonum/blas/testblas" 11 | ) 12 | 13 | func TestDgemv(t *testing.T) { 14 | testblas.DgemvTest(t, impl) 15 | } 16 | 17 | func TestDger(t *testing.T) { 18 | testblas.DgerTest(t, impl) 19 | } 20 | 21 | func TestDtbmv(t *testing.T) { 22 | testblas.DtbmvTest(t, impl) 23 | } 24 | 25 | func TestDtxmv(t *testing.T) { 26 | testblas.DtxmvTest(t, impl) 27 | } 28 | 29 | func TestDgbmv(t *testing.T) { 30 | testblas.DgbmvTest(t, impl) 31 | } 32 | 33 | func TestDtbsv(t *testing.T) { 34 | testblas.DtbsvTest(t, impl) 35 | } 36 | 37 | func TestDsbmv(t *testing.T) { 38 | testblas.DsbmvTest(t, impl) 39 | } 40 | 41 | func TestDtrsv(t *testing.T) { 42 | testblas.DtrsvTest(t, impl) 43 | } 44 | 45 | func TestDsyr(t *testing.T) { 46 | testblas.DsyrTest(t, impl) 47 | } 48 | 49 | func TestDsymv(t *testing.T) { 50 | testblas.DsymvTest(t, impl) 51 | } 52 | 53 | func TestDtrmv(t *testing.T) { 54 | testblas.DtrmvTest(t, impl) 55 | } 56 | 57 | func TestDsyr2(t *testing.T) { 58 | testblas.Dsyr2Test(t, impl) 59 | } 60 | 61 | func TestDspr2(t *testing.T) { 62 | testblas.Dspr2Test(t, impl) 63 | } 64 | 65 | func TestDspr(t *testing.T) { 66 | testblas.DsprTest(t, impl) 67 | } 68 | 69 | func TestDspmv(t *testing.T) { 70 | testblas.DspmvTest(t, impl) 71 | } 72 | 73 | func TestDtpsv(t *testing.T) { 74 | testblas.DtpsvTest(t, impl) 75 | } 76 | 77 | func TestDtmpv(t *testing.T) { 78 | testblas.DtpmvTest(t, impl) 79 | } 80 | -------------------------------------------------------------------------------- /blas/netlib/level3cmplx128_test.go: -------------------------------------------------------------------------------- 1 | // Copyright ©2019 The Gonum Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package netlib 6 | 7 | import ( 8 | "testing" 9 | 10 | "gonum.org/v1/gonum/blas/testblas" 11 | ) 12 | 13 | func TestZgemm(t *testing.T) { testblas.ZgemmTest(t, impl) } 14 | func TestZhemm(t *testing.T) { testblas.ZhemmTest(t, impl) } 15 | func TestZherk(t *testing.T) { testblas.ZherkTest(t, impl) } 16 | func TestZher2k(t *testing.T) { testblas.Zher2kTest(t, impl) } 17 | func TestZsymm(t *testing.T) { testblas.ZsymmTest(t, impl) } 18 | func TestZsyrk(t *testing.T) { testblas.ZsyrkTest(t, impl) } 19 | func TestZsyr2k(t *testing.T) { testblas.Zsyr2kTest(t, impl) } 20 | func TestZtrmm(t *testing.T) { testblas.ZtrmmTest(t, impl) } 21 | func TestZtrsm(t *testing.T) { testblas.ZtrsmTest(t, impl) } 22 | -------------------------------------------------------------------------------- /blas/netlib/level3double_test.go: -------------------------------------------------------------------------------- 1 | // Copyright ©2014 The Gonum Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package netlib 6 | 7 | import ( 8 | "testing" 9 | 10 | "gonum.org/v1/gonum/blas/testblas" 11 | ) 12 | 13 | func TestDgemm(t *testing.T) { 14 | testblas.TestDgemm(t, impl) 15 | } 16 | 17 | func TestDsymm(t *testing.T) { 18 | testblas.DsymmTest(t, impl) 19 | } 20 | 21 | func TestDtrsm(t *testing.T) { 22 | testblas.DtrsmTest(t, impl) 23 | } 24 | 25 | func TestDsyrk(t *testing.T) { 26 | testblas.DsyrkTest(t, impl) 27 | } 28 | 29 | func TestDsyr2k(t *testing.T) { 30 | testblas.Dsyr2kTest(t, impl) 31 | } 32 | 33 | func TestDtrmm(t *testing.T) { 34 | testblas.DtrmmTest(t, impl) 35 | } 36 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module gonum.org/v1/netlib 2 | 3 | go 1.17 4 | 5 | require ( 6 | golang.org/x/exp v0.0.0-20230321023759-10a507213a29 7 | gonum.org/v1/gonum v0.13.1-0.20230729095443-194082cf5ba1 8 | modernc.org/cc v1.0.0 9 | modernc.org/xc v1.0.0 10 | ) 11 | 12 | require ( 13 | github.com/remyoudompheng/bigfft v0.0.0-20190728182440-6a916e37a237 // indirect 14 | modernc.org/golex v1.0.0 // indirect 15 | modernc.org/mathutil v1.0.0 // indirect 16 | modernc.org/strutil v1.1.0 // indirect 17 | ) 18 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= 2 | gioui.org v0.0.0-20210308172011-57750fc8a0a6/go.mod h1:RSH6KIUZ0p2xy5zHDxgAM4zumjgTw83q2ge/PI+yyw8= 3 | git.sr.ht/~sbinet/gg v0.3.1/go.mod h1:KGYtlADtqsqANL9ueOFkWymvzUvLMQllU5Ixo+8v3pc= 4 | github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= 5 | github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= 6 | github.com/ajstarks/deck v0.0.0-20200831202436-30c9fc6549a9/go.mod h1:JynElWSGnm/4RlzPXRlREEwqTHAN3T56Bv2ITsFT3gY= 7 | github.com/ajstarks/deck/generate v0.0.0-20210309230005-c3f852c02e19/go.mod h1:T13YZdzov6OU0A1+RfKZiZN9ca6VeKdBdyDV+BY97Tk= 8 | github.com/ajstarks/svgo v0.0.0-20180226025133-644b8db467af/go.mod h1:K08gAheRH3/J6wwsYMMT4xOr94bZjxIelGM0+d/wbFw= 9 | github.com/ajstarks/svgo v0.0.0-20211024235047-1546f124cd8b/go.mod h1:1KcenG0jGWcpt8ov532z81sp/kMMUG485J2InIOyADM= 10 | github.com/boombuler/barcode v1.0.0/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8= 11 | github.com/boombuler/barcode v1.0.1/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8= 12 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 13 | github.com/fogleman/gg v1.2.1-0.20190220221249-0403632d5b90/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k= 14 | github.com/fogleman/gg v1.3.0/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k= 15 | github.com/go-fonts/dejavu v0.1.0/go.mod h1:4Wt4I4OU2Nq9asgDCteaAaWZOV24E+0/Pwo0gppep4g= 16 | github.com/go-fonts/latin-modern v0.2.0/go.mod h1:rQVLdDMK+mK1xscDwsqM5J8U2jrRa3T0ecnM9pNujks= 17 | github.com/go-fonts/latin-modern v0.3.0/go.mod h1:ysEQXnuT/sCDOAONxC7ImeEDVINbltClhasMAqEtRK0= 18 | github.com/go-fonts/liberation v0.1.1/go.mod h1:K6qoJYypsmfVjWg8KOVDQhLc8UDgIK2HYqyqAO9z7GY= 19 | github.com/go-fonts/liberation v0.2.0/go.mod h1:K6qoJYypsmfVjWg8KOVDQhLc8UDgIK2HYqyqAO9z7GY= 20 | github.com/go-fonts/liberation v0.3.0/go.mod h1:jdJ+cqF+F4SUL2V+qxBth8fvBpBDS7yloUL5Fi8GTGY= 21 | github.com/go-fonts/stix v0.1.0/go.mod h1:w/c1f0ldAUlJmLBvlbkvVXLAD+tAMqobIIQpmnUIzUY= 22 | github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= 23 | github.com/go-latex/latex v0.0.0-20210118124228-b3d85cf34e07/go.mod h1:CO1AlKB2CSIqUrmQPqA0gdRIlnLEY0gK5JGjh37zN5U= 24 | github.com/go-latex/latex v0.0.0-20210823091927-c0d11ff05a81/go.mod h1:SX0U8uGpxhq9o2S/CELCSUxEWWAuoCUcVCQWv7G2OCk= 25 | github.com/go-latex/latex v0.0.0-20230307184459-12ec69307ad9/go.mod h1:gWuR/CrFDDeVRFQwHPvsv9soJVB/iqymhuZQuJ3a9OM= 26 | github.com/go-pdf/fpdf v0.5.0/go.mod h1:HzcnA+A23uwogo0tp9yU+l3V+KXhiESpt1PMayhOh5M= 27 | github.com/go-pdf/fpdf v0.6.0/go.mod h1:HzcnA+A23uwogo0tp9yU+l3V+KXhiESpt1PMayhOh5M= 28 | github.com/goccmack/gocc v0.0.0-20230228185258-2292f9e40198/go.mod h1:DTh/Y2+NbnOVVoypCCQrovMPDKUGp4yZpSbWg5D0XIM= 29 | github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k= 30 | github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= 31 | github.com/jung-kurt/gofpdf v1.0.0/go.mod h1:7Id9E/uU8ce6rXgefFLlgrJj/GYY22cpxn+r32jIOes= 32 | github.com/jung-kurt/gofpdf v1.0.3-0.20190309125859-24315acbbda5/go.mod h1:7Id9E/uU8ce6rXgefFLlgrJj/GYY22cpxn+r32jIOes= 33 | github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= 34 | github.com/phpdave11/gofpdf v1.4.2/go.mod h1:zpO6xFn9yxo3YLyMvW8HcKWVdbNqgIfOOp2dXMnm1mY= 35 | github.com/phpdave11/gofpdi v1.0.12/go.mod h1:vBmVV0Do6hSBHC8uKUQ71JGW+ZGQq74llk/7bXwjDoI= 36 | github.com/phpdave11/gofpdi v1.0.13/go.mod h1:vBmVV0Do6hSBHC8uKUQ71JGW+ZGQq74llk/7bXwjDoI= 37 | github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 38 | github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 39 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 40 | github.com/remyoudompheng/bigfft v0.0.0-20190728182440-6a916e37a237 h1:HQagqIiBmr8YXawX/le3+O26N+vPPC1PtjaF3mwnook= 41 | github.com/remyoudompheng/bigfft v0.0.0-20190728182440-6a916e37a237/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo= 42 | github.com/ruudk/golang-pdf417 v0.0.0-20181029194003-1af4ab5afa58/go.mod h1:6lfFZQK844Gfx8o5WFuvpxWRwnSoipWe/p622j1v06w= 43 | github.com/ruudk/golang-pdf417 v0.0.0-20201230142125-a7e3863a1245/go.mod h1:pQAZKsJ8yyVxGRWYNEm9oFB8ieLgKFnamEyDmSA0BRk= 44 | github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= 45 | github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= 46 | github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= 47 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 48 | golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= 49 | golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= 50 | golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= 51 | golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= 52 | golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw= 53 | golang.org/x/exp v0.0.0-20180321215751-8460e604b9de/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= 54 | golang.org/x/exp v0.0.0-20180807140117-3d87b88a115f/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= 55 | golang.org/x/exp v0.0.0-20190125153040-c74c464bbbf2/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= 56 | golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= 57 | golang.org/x/exp v0.0.0-20191002040644-a1355ae1e2c3/go.mod h1:NOZ3BPKG0ec/BKJQgnvsSFpcKLM5xXVWnvZS97DWHgE= 58 | golang.org/x/exp v0.0.0-20230321023759-10a507213a29 h1:ooxPy7fPvB4kwsA2h+iBNHkAbp/4JxTSwCmvdjEYmug= 59 | golang.org/x/exp v0.0.0-20230321023759-10a507213a29/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc= 60 | golang.org/x/image v0.0.0-20180708004352-c73c2afc3b81/go.mod h1:ux5Hcp/YLpHSI86hEcLt0YII63i6oz57MZXIpbrjZUs= 61 | golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= 62 | golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= 63 | golang.org/x/image v0.0.0-20190910094157-69e4b8554b2a/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= 64 | golang.org/x/image v0.0.0-20200119044424-58c23975cae1/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= 65 | golang.org/x/image v0.0.0-20200430140353-33d19683fad8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= 66 | golang.org/x/image v0.0.0-20200618115811-c13761719519/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= 67 | golang.org/x/image v0.0.0-20201208152932-35266b937fa6/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= 68 | golang.org/x/image v0.0.0-20210216034530-4410531fe030/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= 69 | golang.org/x/image v0.0.0-20210607152325-775e3b0c77b9/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM= 70 | golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM= 71 | golang.org/x/image v0.0.0-20211028202545-6944b10bf410/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM= 72 | golang.org/x/image v0.5.0/go.mod h1:FVC7BI/5Ym8R25iw5OLsgshdUBbT1h5jZTpA+mvAdZ4= 73 | golang.org/x/image v0.6.0/go.mod h1:MXLdDR43H7cDJq5GEGXEVeeNhPgi+YYEQ2pC1byI1x0= 74 | golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= 75 | golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= 76 | golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= 77 | golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= 78 | golang.org/x/mod v0.6.0/go.mod h1:4mET923SAdbXp2ki8ey+zGs1SLqsuM2Y0uvdZR/fUNI= 79 | golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= 80 | golang.org/x/mod v0.9.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= 81 | golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 82 | golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 83 | golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= 84 | golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= 85 | golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= 86 | golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco= 87 | golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= 88 | golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= 89 | golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 90 | golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 91 | golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 92 | golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 93 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 94 | golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 95 | golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 96 | golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 97 | golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 98 | golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 99 | golang.org/x/sys v0.0.0-20210304124612-50617c2ba197/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 100 | golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 101 | golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 102 | golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 103 | golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 104 | golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 105 | golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 106 | golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= 107 | golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= 108 | golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= 109 | golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= 110 | golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U= 111 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 112 | golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= 113 | golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= 114 | golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= 115 | golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= 116 | golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= 117 | golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= 118 | golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= 119 | golang.org/x/tools v0.0.0-20180525024113-a5b4c53f6e8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 120 | golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 121 | golang.org/x/tools v0.0.0-20190206041539-40960b6deb8e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 122 | golang.org/x/tools v0.0.0-20190927191325-030b2cf1153e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= 123 | golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= 124 | golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= 125 | golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= 126 | golang.org/x/tools v0.2.0/go.mod h1:y4OqIKeOV/fWJetJ8bXPU1sEVniLMIyDAZWeHdV+NTA= 127 | golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= 128 | golang.org/x/tools v0.7.0/go.mod h1:4pg6aUX35JBAogB10C9AtvVL+qowtN4pT3CGSQex14s= 129 | golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 130 | golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 131 | golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 132 | gonum.org/v1/gonum v0.0.0-20180816165407-929014505bf4/go.mod h1:Y+Yx5eoAFn32cQvJDxZx5Dpnq+c3wtXuadVZAcxbbBo= 133 | gonum.org/v1/gonum v0.8.2/go.mod h1:oe/vMfY3deqTw+1EZJhuvEW2iwGF1bW9wwu7XCu0+v0= 134 | gonum.org/v1/gonum v0.9.3/go.mod h1:TZumC3NeyVQskjXqmyWt4S3bINhy7B4eYwW69EbyX+0= 135 | gonum.org/v1/gonum v0.13.1-0.20230729095443-194082cf5ba1 h1:aJsuJW1HKpB/bJqnt4kuUfy9WABagWCV/e/EQyPKt1Y= 136 | gonum.org/v1/gonum v0.13.1-0.20230729095443-194082cf5ba1/go.mod h1:ppQyMDTW6evXNiTZGYPPo4bJltmVNrKFeCnOhp1cbSQ= 137 | gonum.org/v1/netlib v0.0.0-20190313105609-8cb42192e0e0/go.mod h1:wa6Ws7BG/ESfp6dHfk7C6KdzKA7wR7u/rKwOGE66zvw= 138 | gonum.org/v1/plot v0.0.0-20190515093506-e2840ee46a6b/go.mod h1:Wt8AAjI+ypCyYX3nZBvf6cAIx93T+c/OS2HFAYskSZc= 139 | gonum.org/v1/plot v0.9.0/go.mod h1:3Pcqqmp6RHvJI72kgb8fThyUnav364FOsdDo2aGW5lY= 140 | gonum.org/v1/plot v0.10.1/go.mod h1:VZW5OlhkL1mysU9vaqNHnsy86inf6Ot+jB3r+BczCEo= 141 | honnef.co/go/tools v0.1.3/go.mod h1:NgwopIslSNH47DimFoV78dnkksY2EFtX0ajyb3K/las= 142 | modernc.org/cc v1.0.0 h1:nPibNuDEx6tvYrUAtvDTTw98rx5juGsa5zuDnKwEEQQ= 143 | modernc.org/cc v1.0.0/go.mod h1:1Sk4//wdnYJiUIxnW8ddKpaOJCF37yAdqYnkxUpaYxw= 144 | modernc.org/golex v1.0.0 h1:wWpDlbK8ejRfSyi0frMyhilD3JBvtcx2AdGDnU+JtsE= 145 | modernc.org/golex v1.0.0/go.mod h1:b/QX9oBD/LhixY6NDh+IdGv17hgB+51fET1i2kPSmvk= 146 | modernc.org/mathutil v1.0.0 h1:93vKjrJopTPrtTNpZ8XIovER7iCIH1QU7wNbOQXC60I= 147 | modernc.org/mathutil v1.0.0/go.mod h1:wU0vUrJsVWBZ4P6e7xtFJEhFSNsfRLJ8H458uRjg03k= 148 | modernc.org/strutil v1.1.0 h1:+1/yCzZxY2pZwwrsbH+4T7BQMoLQ9QiBshRC9eicYsc= 149 | modernc.org/strutil v1.1.0/go.mod h1:lstksw84oURvj9y3tn8lGvRxyRC1S2+g5uuIzNfIOBs= 150 | modernc.org/xc v1.0.0 h1:7ccXrupWZIS3twbUGrtKmHS2DXY6xegFua+6O3xgAFU= 151 | modernc.org/xc v1.0.0/go.mod h1:mRNCo0bvLjGhHO9WsyuKVU4q0ceiDDDoEeWDJHrNx8I= 152 | rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4= 153 | -------------------------------------------------------------------------------- /internal/binding/binding.go: -------------------------------------------------------------------------------- 1 | // Copyright ©2016 The Gonum Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package binding provides helpers for building autogenerated cgo bindings. 6 | package binding 7 | 8 | import ( 9 | "bytes" 10 | "fmt" 11 | "go/ast" 12 | "go/parser" 13 | "go/token" 14 | "sort" 15 | "text/template" 16 | "unsafe" 17 | 18 | "modernc.org/cc" 19 | "modernc.org/xc" 20 | ) 21 | 22 | func model() *cc.Model { 23 | p := int(unsafe.Sizeof(uintptr(0))) 24 | i := int(unsafe.Sizeof(int(0))) 25 | return &cc.Model{ 26 | Items: map[cc.Kind]cc.ModelItem{ 27 | cc.Ptr: {Size: p, Align: p, StructAlign: p}, 28 | cc.UintPtr: {Size: p, Align: p, StructAlign: p}, 29 | cc.Void: {Size: 0, Align: 1, StructAlign: 1}, 30 | cc.Char: {Size: 1, Align: 1, StructAlign: 1}, 31 | cc.SChar: {Size: 1, Align: 1, StructAlign: 1}, 32 | cc.UChar: {Size: 1, Align: 1, StructAlign: 1}, 33 | cc.Short: {Size: 2, Align: 2, StructAlign: 2}, 34 | cc.UShort: {Size: 2, Align: 2, StructAlign: 2}, 35 | cc.Int: {Size: 4, Align: 4, StructAlign: 4}, 36 | cc.UInt: {Size: 4, Align: 4, StructAlign: 4}, 37 | cc.Long: {Size: i, Align: i, StructAlign: i}, 38 | cc.ULong: {Size: i, Align: i, StructAlign: i}, 39 | cc.LongLong: {Size: 8, Align: 8, StructAlign: 8}, 40 | cc.ULongLong: {Size: 8, Align: 8, StructAlign: 8}, 41 | cc.Float: {Size: 4, Align: 4, StructAlign: 4}, 42 | cc.Double: {Size: 8, Align: 8, StructAlign: 8}, 43 | cc.LongDouble: {Size: 8, Align: 8, StructAlign: 8}, 44 | cc.Bool: {Size: 1, Align: 1, StructAlign: 1}, 45 | cc.FloatComplex: {Size: 8, Align: 8, StructAlign: 8}, 46 | cc.DoubleComplex: {Size: 16, Align: 16, StructAlign: 16}, 47 | cc.LongDoubleComplex: {Size: 16, Align: 16, StructAlign: 16}, 48 | }, 49 | } 50 | } 51 | 52 | // TypeKey is a terse C type description. 53 | type TypeKey struct { 54 | IsPointer bool 55 | Kind cc.Kind 56 | } 57 | 58 | var goTypes = map[TypeKey]*template.Template{ 59 | {Kind: cc.Undefined}: template.Must(template.New("").Parse("")), 60 | {Kind: cc.Int}: template.Must(template.New("int").Parse("int")), 61 | {Kind: cc.Float}: template.Must(template.New("float32").Parse("float32")), 62 | {Kind: cc.Float, IsPointer: true}: template.Must(template.New("[]float32").Parse("[]float32")), 63 | {Kind: cc.Double}: template.Must(template.New("float64").Parse("float64")), 64 | {Kind: cc.Double, IsPointer: true}: template.Must(template.New("[]float64").Parse("[]float64")), 65 | {Kind: cc.Bool}: template.Must(template.New("bool").Parse("bool")), 66 | {Kind: cc.FloatComplex}: template.Must(template.New("complex64").Parse("complex64")), 67 | {Kind: cc.DoubleComplex}: template.Must(template.New("complex128").Parse("complex128")), 68 | } 69 | 70 | // GoTypeFor returns a string representation of the given type using a mapping in 71 | // types. GoTypeFor will panic if no type mapping is found after searching the 72 | // user-provided types mappings and then the following mapping: 73 | // {Kind: cc.Int}: "int", 74 | // {Kind: cc.Float}: "float32", 75 | // {Kind: cc.Float, IsPointer: true}: "[]float32", 76 | // {Kind: cc.Double}: "float64", 77 | // {Kind: cc.Double, IsPointer: true}: "[]float64", 78 | // {Kind: cc.Bool}: "bool", 79 | // {Kind: cc.FloatComplex}: "complex64", 80 | // {Kind: cc.DoubleComplex}: "complex128", 81 | func GoTypeFor(typ cc.Type, name string, types ...map[TypeKey]*template.Template) string { 82 | if typ == nil { 83 | return "" 84 | } 85 | k := typ.Kind() 86 | isPtr := typ.Kind() == cc.Ptr 87 | if isPtr { 88 | k = typ.Element().Kind() 89 | } 90 | var buf bytes.Buffer 91 | for _, t := range types { 92 | if s, ok := t[TypeKey{Kind: k, IsPointer: isPtr}]; ok { 93 | err := s.Execute(&buf, name) 94 | if err != nil { 95 | panic(err) 96 | } 97 | return buf.String() 98 | } 99 | } 100 | s, ok := goTypes[TypeKey{Kind: k, IsPointer: isPtr}] 101 | if ok { 102 | err := s.Execute(&buf, name) 103 | if err != nil { 104 | panic(err) 105 | } 106 | return buf.String() 107 | } 108 | panic(fmt.Sprintf("unknown type key: %+v", TypeKey{Kind: k, IsPointer: isPtr})) 109 | } 110 | 111 | // GoTypeForEnum returns a string representation of the given enum type using a mapping 112 | // in types. GoTypeForEnum will panic if no type mapping is found after searching the 113 | // user-provided types mappings or the type is not an enum. 114 | func GoTypeForEnum(typ cc.Type, name string, types ...map[string]*template.Template) string { 115 | if typ == nil { 116 | return "" 117 | } 118 | if typ.Kind() != cc.Enum { 119 | panic(fmt.Sprintf("invalid type: %v", typ)) 120 | } 121 | tag := typ.Tag() 122 | if tag != 0 { 123 | n := string(xc.Dict.S(tag)) 124 | for _, t := range types { 125 | if s, ok := t[n]; ok { 126 | var buf bytes.Buffer 127 | err := s.Execute(&buf, name) 128 | if err != nil { 129 | panic(err) 130 | } 131 | return buf.String() 132 | } 133 | } 134 | } 135 | panic(fmt.Sprintf("unknown type: %+v", typ)) 136 | } 137 | 138 | var cgoTypes = map[TypeKey]*template.Template{ 139 | {Kind: cc.Void, IsPointer: true}: template.Must(template.New("void*").Parse("unsafe.Pointer(&{{.}}[0])")), 140 | 141 | {Kind: cc.Int}: template.Must(template.New("int").Parse("C.int({{.}})")), 142 | 143 | {Kind: cc.Float}: template.Must(template.New("float").Parse("C.float({{.}})")), 144 | {Kind: cc.Double}: template.Must(template.New("double").Parse("C.double({{.}})")), 145 | 146 | {Kind: cc.Float, IsPointer: true}: template.Must(template.New("float*").Parse("(*C.float)(&{{.}}[0])")), 147 | {Kind: cc.Double, IsPointer: true}: template.Must(template.New("double*").Parse("(*C.double)(&{{.}}[0])")), 148 | 149 | {Kind: cc.Bool}: template.Must(template.New("bool").Parse("C.bool({{.}})")), 150 | 151 | {Kind: cc.FloatComplex}: template.Must(template.New("floatcomplex").Parse("unsafe.Pointer({{.}})")), 152 | {Kind: cc.DoubleComplex}: template.Must(template.New("doublecomplex").Parse("unsafe.Pointer({{.}})")), 153 | {Kind: cc.FloatComplex, IsPointer: true}: template.Must(template.New("floatcomplex*").Parse("unsafe.Pointer(&{{.}}[0])")), 154 | {Kind: cc.DoubleComplex, IsPointer: true}: template.Must(template.New("doublecomplex*").Parse("unsafe.Pointer(&{{.}}[0])")), 155 | } 156 | 157 | // CgoConversionFor returns a string representation of the given type using a mapping in 158 | // types. CgoConversionFor will panic if no type mapping is found after searching the 159 | // user-provided types mappings and then the following mapping: 160 | // {Kind: cc.Void, IsPointer: true}: "unsafe.Pointer(&{{.}}[0])", 161 | // {Kind: cc.Int}: "C.int({{.}})", 162 | // {Kind: cc.Float}: "C.float({{.}})", 163 | // {Kind: cc.Float, IsPointer: true}: "(*C.float)({{.}})", 164 | // {Kind: cc.Double}: "C.double({{.}})", 165 | // {Kind: cc.Double, IsPointer: true}: "(*C.double)({{.}})", 166 | // {Kind: cc.Bool}: "C.bool({{.}})", 167 | // {Kind: cc.FloatComplex}: "unsafe.Pointer(&{{.}})", 168 | // {Kind: cc.DoubleComplex}: "unsafe.Pointer(&{{.}})", 169 | // {Kind: cc.FloatComplex, IsPointer: true}: "unsafe.Pointer(&{{.}}[0])", 170 | // {Kind: cc.DoubleComplex, IsPointer: true}: "unsafe.Pointer(&{{.}}[0])", 171 | func CgoConversionFor(name string, typ cc.Type, types ...map[TypeKey]*template.Template) string { 172 | if typ == nil { 173 | return "" 174 | } 175 | k := typ.Kind() 176 | isPtr := typ.Kind() == cc.Ptr 177 | if isPtr { 178 | k = typ.Element().Kind() 179 | } 180 | for _, t := range types { 181 | if s, ok := t[TypeKey{Kind: k, IsPointer: isPtr}]; ok { 182 | var buf bytes.Buffer 183 | err := s.Execute(&buf, name) 184 | if err != nil { 185 | panic(err) 186 | } 187 | return buf.String() 188 | } 189 | } 190 | s, ok := cgoTypes[TypeKey{Kind: k, IsPointer: isPtr}] 191 | if ok { 192 | var buf bytes.Buffer 193 | err := s.Execute(&buf, name) 194 | if err != nil { 195 | panic(err) 196 | } 197 | return buf.String() 198 | } 199 | panic(fmt.Sprintf("unknown type key: %+v", TypeKey{Kind: k, IsPointer: isPtr})) 200 | } 201 | 202 | // CgoConversionForEnum returns a string representation of the given enum type using a mapping 203 | // in types. GoTypeForEnum will panic if no type mapping is found after searching the 204 | // user-provided types mappings or the type is not an enum. 205 | func CgoConversionForEnum(name string, typ cc.Type, types ...map[string]*template.Template) string { 206 | if typ == nil { 207 | return "" 208 | } 209 | if typ.Kind() != cc.Enum { 210 | panic(fmt.Sprintf("invalid type: %v", typ)) 211 | } 212 | tag := typ.Tag() 213 | if tag != 0 { 214 | n := string(xc.Dict.S(tag)) 215 | for _, t := range types { 216 | if s, ok := t[n]; ok { 217 | var buf bytes.Buffer 218 | err := s.Execute(&buf, name) 219 | if err != nil { 220 | panic(err) 221 | } 222 | return buf.String() 223 | } 224 | } 225 | } 226 | panic(fmt.Sprintf("unknown type: %+v", typ)) 227 | } 228 | 229 | // LowerCaseFirst returns s with the first character lower-cased. LowerCaseFirst 230 | // assumes s is an ASCII-represented string. 231 | func LowerCaseFirst(s string) string { 232 | if len(s) == 0 { 233 | return s 234 | } 235 | return string(s[0]|' ') + s[1:] 236 | } 237 | 238 | // UpperCaseFirst returns s with the first character upper-cased. UpperCaseFirst 239 | // assumes s is an ASCII-represented string. 240 | func UpperCaseFirst(s string) string { 241 | if len(s) == 0 { 242 | return s 243 | } 244 | return string(s[0]&^' ') + s[1:] 245 | } 246 | 247 | // DocComments returns a map of method documentation comments for the package at the 248 | // given path. The first key of the returned map is the type name and the second 249 | // is the method name. Non-method function documentation are in docs[""]. 250 | func DocComments(path string) (docs map[string]map[string][]*ast.Comment, err error) { 251 | fset := token.NewFileSet() 252 | pkgs, err := parser.ParseDir(fset, path, nil, parser.ParseComments) 253 | if err != nil { 254 | return nil, err 255 | } 256 | 257 | docs = make(map[string]map[string][]*ast.Comment) 258 | for _, p := range pkgs { 259 | for _, f := range p.Files { 260 | for _, n := range f.Decls { 261 | fn, ok := n.(*ast.FuncDecl) 262 | if !ok || fn.Doc == nil { 263 | continue 264 | } 265 | 266 | var typ string 267 | if fn.Recv != nil && len(fn.Recv.List) > 0 { 268 | id, ok := fn.Recv.List[0].Type.(*ast.Ident) 269 | if ok { 270 | typ = id.Name 271 | } 272 | } 273 | doc, ok := docs[typ] 274 | if !ok { 275 | doc = make(map[string][]*ast.Comment) 276 | docs[typ] = doc 277 | } 278 | doc[fn.Name.String()] = fn.Doc.List 279 | } 280 | } 281 | } 282 | 283 | return docs, nil 284 | } 285 | 286 | // Declaration is a description of a C function declaration. 287 | type Declaration struct { 288 | Pos token.Pos 289 | Name string 290 | Return cc.Type 291 | CParameters []cc.Parameter 292 | Variadic bool 293 | } 294 | 295 | // Position returns the token position of the declaration. 296 | func (d *Declaration) Position() token.Position { return xc.FileSet.Position(d.Pos) } 297 | 298 | // Parameter is a C function parameter. 299 | type Parameter struct{ Parameter cc.Parameter } 300 | 301 | // Name returns the name of the parameter. 302 | func (p *Parameter) Name() string { return string(xc.Dict.S(p.Parameter.Name)) } 303 | 304 | // Type returns the C type of the parameter. 305 | func (p *Parameter) Type() cc.Type { return p.Parameter.Type } 306 | 307 | // Kind returns the C kind of the parameter. 308 | func (p *Parameter) Kind() cc.Kind { return p.Parameter.Type.Kind() } 309 | 310 | // Elem returns the pointer type of a pointer parameter or the element type of an 311 | // array parameter. 312 | func (p *Parameter) Elem() cc.Type { return p.Parameter.Type.Element() } 313 | 314 | // Parameters returns the declaration's CParameters converted to a []Parameter. 315 | func (d *Declaration) Parameters() []Parameter { 316 | p := make([]Parameter, len(d.CParameters)) 317 | for i, c := range d.CParameters { 318 | p[i] = Parameter{c} 319 | } 320 | return p 321 | } 322 | 323 | // Declarations returns the C function declarations in the given set of file paths. 324 | func Declarations(paths ...string) ([]Declaration, error) { 325 | predefined, includePaths, sysIncludePaths, err := cc.HostConfig() 326 | if err != nil { 327 | return nil, fmt.Errorf("binding: failed to get host config: %v", err) 328 | } 329 | 330 | t, err := cc.Parse( 331 | predefined+` 332 | #define __const const 333 | #define __attribute__(...) 334 | #define __extension__ 335 | #define __inline 336 | #define __restrict 337 | unsigned __builtin_bswap32 (unsigned x); 338 | unsigned __builtin_bswap16 (unsigned x); 339 | unsigned long long __builtin_bswap64 (unsigned long long x); 340 | `, 341 | paths, 342 | model(), 343 | cc.IncludePaths(includePaths), 344 | cc.SysIncludePaths(sysIncludePaths), 345 | cc.EnableAnonymousStructFields(), 346 | ) 347 | if err != nil { 348 | return nil, fmt.Errorf("binding: failed to parse %q: %v", paths, err) 349 | } 350 | 351 | var decls []Declaration 352 | for ; t != nil; t = t.TranslationUnit { 353 | if t.ExternalDeclaration.Case != 1 /* Declaration */ { 354 | continue 355 | } 356 | 357 | d := t.ExternalDeclaration.Declaration 358 | if d.Case != 0 { 359 | // Other case is 1: StaticAssertDeclaration. 360 | continue 361 | } 362 | 363 | init := d.InitDeclaratorListOpt 364 | if init == nil { 365 | continue 366 | } 367 | idl := init.InitDeclaratorList 368 | if idl.InitDeclaratorList != nil { 369 | // We do not want comma-separated lists. 370 | continue 371 | } 372 | id := idl.InitDeclarator 373 | if id.Case != 0 { 374 | // We do not want assignments. 375 | continue 376 | } 377 | 378 | declarator := id.Declarator 379 | if declarator.Type.Kind() != cc.Function { 380 | // We want only functions. 381 | continue 382 | } 383 | params, variadic := declarator.Type.Parameters() 384 | name, _ := declarator.Identifier() 385 | decls = append(decls, Declaration{ 386 | Pos: declarator.Pos(), 387 | Name: string(xc.Dict.S(name)), 388 | Return: declarator.Type.Result(), 389 | CParameters: params, 390 | Variadic: variadic, 391 | }) 392 | } 393 | 394 | sort.Sort(byPosition(decls)) 395 | 396 | return decls, nil 397 | } 398 | 399 | type byPosition []Declaration 400 | 401 | func (d byPosition) Len() int { return len(d) } 402 | func (d byPosition) Less(i, j int) bool { 403 | iPos := d[i].Position() 404 | jPos := d[j].Position() 405 | if iPos.Filename == jPos.Filename { 406 | return iPos.Line < jPos.Line 407 | } 408 | return iPos.Filename < jPos.Filename 409 | } 410 | func (d byPosition) Swap(i, j int) { d[i], d[j] = d[j], d[i] } 411 | -------------------------------------------------------------------------------- /lapack/lapacke/generate.go: -------------------------------------------------------------------------------- 1 | // Copyright ©2016 The Gonum Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:generate go run generate_lapacke.go 6 | 7 | package lapacke 8 | -------------------------------------------------------------------------------- /lapack/lapacke/generate_lapacke.go: -------------------------------------------------------------------------------- 1 | // Copyright ©2016 The Gonum Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build ignore 6 | 7 | // generate_lapacke creates a lapacke.go file from the provided C header file 8 | // with optionally added documentation from the documentation package. 9 | package main 10 | 11 | import ( 12 | "bytes" 13 | "fmt" 14 | "go/format" 15 | "io/ioutil" 16 | "log" 17 | "os" 18 | "strings" 19 | "text/template" 20 | 21 | "modernc.org/cc" 22 | 23 | "gonum.org/v1/netlib/internal/binding" 24 | ) 25 | 26 | const ( 27 | header = "lapacke.h" 28 | target = "lapacke.go" 29 | 30 | prefix = "LAPACKE_" 31 | suffix = "_work" 32 | ) 33 | 34 | const ( 35 | elideRepeat = true 36 | noteOrigin = false 37 | ) 38 | 39 | var skip = map[string]bool{ 40 | // Deprecated. 41 | "LAPACKE_cggsvp_work": true, 42 | "LAPACKE_dggsvp_work": true, 43 | "LAPACKE_sggsvp_work": true, 44 | "LAPACKE_zggsvp_work": true, 45 | "LAPACKE_cggsvd_work": true, 46 | "LAPACKE_dggsvd_work": true, 47 | "LAPACKE_sggsvd_work": true, 48 | "LAPACKE_zggsvd_work": true, 49 | "LAPACKE_cgeqpf_work": true, 50 | "LAPACKE_dgeqpf_work": true, 51 | "LAPACKE_sgeqpf_work": true, 52 | "LAPACKE_zgeqpf_work": true, 53 | } 54 | 55 | // needsInt is a list of routines that need to return the integer info value and 56 | // and cannot convert to a success boolean. 57 | var needsInt = map[string]bool{ 58 | "hseqr": true, 59 | "geev": true, 60 | "geevx": true, 61 | } 62 | 63 | // allUplo is a list of routines that allow any value for their uplo argument. 64 | // The list keys are truncated by one character to cover all four numeric types. 65 | var allUplo = map[string]bool{ 66 | "lacpy": true, 67 | "laset": true, 68 | } 69 | 70 | var cToGoType = map[string]string{ 71 | "char": "byte", 72 | "int_must": "int", 73 | "int_must32": "int32", 74 | "int": "bool", 75 | "float": "float32", 76 | "double": "float64", 77 | "float complex": "complex64", 78 | "double complex": "complex128", 79 | } 80 | 81 | var cToGoTypeConv = map[string]string{ 82 | "int_must": "int", 83 | "int": "isZero", 84 | "float": "float32", 85 | "double": "float64", 86 | "float complex": "complex64", 87 | "double complex": "complex128", 88 | } 89 | 90 | var cgoEnums = map[string]*template.Template{} 91 | 92 | var intTypes = map[string]string{ 93 | "forwrd": "int32", 94 | 95 | "ijob": "byte", 96 | 97 | "wantq": "int32", 98 | "wantz": "int32", 99 | } 100 | 101 | func typeForInt(n string) string { 102 | t, ok := intTypes[n] 103 | if !ok { 104 | return "int" 105 | } 106 | return t 107 | } 108 | 109 | // TODO(kortschak): convForInt* are for #define types, 110 | // so they could go away. Kept here now for diff reduction. 111 | 112 | func convForInt(n string) string { 113 | switch n { 114 | case "rowMajor": 115 | return "C.int" 116 | case "forwrd", "wantq", "wantz": 117 | return "C.lapack_logical" 118 | default: 119 | return "C.lapack_int" 120 | } 121 | } 122 | 123 | func convForIntSlice(n string) string { 124 | switch n { 125 | case "bwork", "tryrac": 126 | return "*C.lapack_logical" 127 | default: 128 | return "*C.lapack_int" 129 | } 130 | } 131 | 132 | var goTypes = map[binding.TypeKey]*template.Template{ 133 | {Kind: cc.Int}: template.Must(template.New("int").Funcs(map[string]interface{}{"typefor": typeForInt}).Parse("{{typefor .}}")), 134 | {Kind: cc.Char}: template.Must(template.New("byte").Parse("byte")), 135 | {Kind: cc.Char, IsPointer: true}: template.Must(template.New("[]byte").Parse("[]byte")), 136 | {Kind: cc.Int, IsPointer: true}: template.Must(template.New("[]int32").Parse("[]int32")), 137 | {Kind: cc.FloatComplex, IsPointer: true}: template.Must(template.New("[]complex64").Parse("[]complex64")), 138 | {Kind: cc.DoubleComplex, IsPointer: true}: template.Must(template.New("[]complex128").Parse("[]complex128")), 139 | } 140 | 141 | var cgoTypes = map[binding.TypeKey]*template.Template{ 142 | {Kind: cc.Char}: template.Must(template.New("char").Parse("(C.char)({{.}})")), 143 | {Kind: cc.Int}: template.Must(template.New("int").Funcs(map[string]interface{}{"conv": convForInt}).Parse(`({{conv .}})({{.}})`)), 144 | {Kind: cc.Float}: template.Must(template.New("float").Parse("(C.float)({{.}})")), 145 | {Kind: cc.Double}: template.Must(template.New("double").Parse("(C.double)({{.}})")), 146 | {Kind: cc.FloatComplex}: template.Must(template.New("lapack_complex_float").Parse("(C.lapack_complex_float)({{.}})")), 147 | {Kind: cc.DoubleComplex}: template.Must(template.New("lapack_complex_double").Parse("(C.lapack_complex_double)({{.}})")), 148 | {Kind: cc.Char, IsPointer: true}: template.Must(template.New("char*").Parse("(*C.char)(unsafe.Pointer(_{{.}}))")), 149 | {Kind: cc.Int, IsPointer: true}: template.Must(template.New("int*").Funcs(map[string]interface{}{"conv": convForIntSlice}).Parse("({{conv .}})(_{{.}})")), 150 | {Kind: cc.Float, IsPointer: true}: template.Must(template.New("float").Parse("(*C.float)(_{{.}})")), 151 | {Kind: cc.Double, IsPointer: true}: template.Must(template.New("double").Parse("(*C.double)(_{{.}})")), 152 | {Kind: cc.FloatComplex, IsPointer: true}: template.Must(template.New("lapack_complex_float*").Parse("(*C.lapack_complex_float)(_{{.}})")), 153 | {Kind: cc.DoubleComplex, IsPointer: true}: template.Must(template.New("lapack_complex_double*").Parse("(*C.lapack_complex_double)(_{{.}})")), 154 | } 155 | 156 | var names = map[string]string{ 157 | "matrix_layout": "rowMajor", 158 | "uplo": "ul", 159 | "range": "rng", 160 | "diag": "d", 161 | "select": "sel", 162 | "type": "typ", 163 | } 164 | 165 | func shorten(n string) string { 166 | s, ok := names[n] 167 | if ok { 168 | return s 169 | } 170 | return n 171 | } 172 | 173 | func join(a []string) string { 174 | return strings.Join(a, " ") 175 | } 176 | 177 | func main() { 178 | decls, err := binding.Declarations(header) 179 | if err != nil { 180 | log.Fatal(err) 181 | } 182 | 183 | var buf bytes.Buffer 184 | 185 | h, err := template.New("handwritten"). 186 | Funcs(map[string]interface{}{"join": join}). 187 | Parse(handwritten) 188 | if err != nil { 189 | log.Fatal(err) 190 | } 191 | err = h.Execute(&buf, struct { 192 | Header string 193 | Lib []string 194 | }{ 195 | Header: header, 196 | Lib: os.Args[1:], 197 | }) 198 | if err != nil { 199 | log.Fatal(err) 200 | } 201 | 202 | for _, d := range decls { 203 | if !strings.HasPrefix(d.Name, prefix) || !strings.HasSuffix(d.Name, suffix) || skip[d.Name] { 204 | continue 205 | } 206 | lapackeName := strings.TrimSuffix(strings.TrimPrefix(d.Name, prefix), suffix) 207 | switch { 208 | case strings.HasSuffix(lapackeName, "fsx"): 209 | continue 210 | case strings.HasSuffix(lapackeName, "vxx"): 211 | continue 212 | case strings.HasSuffix(lapackeName, "rook"): 213 | continue 214 | } 215 | if hasFuncParameter(d) { 216 | continue 217 | } 218 | 219 | goSignature(&buf, d) 220 | if noteOrigin { 221 | fmt.Fprintf(&buf, "\t// %s %s %s ...\n\n", d.Position(), d.Return, d.Name) 222 | } 223 | parameterChecks(&buf, d, parameterCheckRules) 224 | buf.WriteByte('\t') 225 | cgoCall(&buf, d) 226 | buf.WriteString("}\n") 227 | } 228 | 229 | b, err := format.Source(buf.Bytes()) 230 | if err != nil { 231 | log.Fatal(err) 232 | } 233 | err = ioutil.WriteFile(target, b, 0664) 234 | if err != nil { 235 | log.Fatal(err) 236 | } 237 | } 238 | 239 | // This removes select and selctg parameterised functions. 240 | func hasFuncParameter(d binding.Declaration) bool { 241 | for _, p := range d.Parameters() { 242 | if p.Kind() != cc.Ptr { 243 | continue 244 | } 245 | if p.Elem().Kind() == cc.Function { 246 | return true 247 | } 248 | } 249 | return false 250 | } 251 | 252 | func goSignature(buf *bytes.Buffer, d binding.Declaration) { 253 | lapackeName := strings.TrimSuffix(strings.TrimPrefix(d.Name, prefix), suffix) 254 | goName := binding.UpperCaseFirst(lapackeName) 255 | 256 | parameters := d.Parameters() 257 | 258 | fmt.Fprintf(buf, "\n// See http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/%s.f.\n", lapackeName) 259 | fmt.Fprintf(buf, "func %s(", goName) 260 | c := 0 261 | for i, p := range parameters { 262 | if p.Name() == "matrix_layout" { 263 | continue 264 | } 265 | if c != 0 { 266 | buf.WriteString(", ") 267 | } 268 | c++ 269 | 270 | n := shorten(binding.LowerCaseFirst(p.Name())) 271 | var this, next string 272 | 273 | if p.Kind() == cc.Enum { 274 | this = binding.GoTypeForEnum(p.Type(), n) 275 | } else { 276 | this = binding.GoTypeFor(p.Type(), n, goTypes) 277 | } 278 | 279 | if elideRepeat && i < len(parameters)-1 && p.Type().Kind() == parameters[i+1].Type().Kind() { 280 | p := parameters[i+1] 281 | n := shorten(binding.LowerCaseFirst(p.Name())) 282 | if p.Kind() == cc.Enum { 283 | next = binding.GoTypeForEnum(p.Type(), n) 284 | } else { 285 | next = binding.GoTypeFor(p.Type(), n, goTypes) 286 | } 287 | } 288 | if next == this { 289 | buf.WriteString(n) 290 | } else { 291 | fmt.Fprintf(buf, "%s %s", n, this) 292 | } 293 | } 294 | if d.Return.Kind() != cc.Void { 295 | var must string 296 | if needsInt[lapackeName[1:]] { 297 | must = "_must" 298 | } 299 | fmt.Fprintf(buf, ") %s {\n", cToGoType[d.Return.String()+must]) 300 | } else { 301 | buf.WriteString(") {\n") 302 | } 303 | } 304 | 305 | func parameterChecks(buf *bytes.Buffer, d binding.Declaration, rules []func(*bytes.Buffer, binding.Declaration, binding.Parameter) bool) { 306 | done := make(map[int]bool) 307 | for _, p := range d.Parameters() { 308 | for i, r := range rules { 309 | if done[i] { 310 | continue 311 | } 312 | done[i] = r(buf, d, p) 313 | } 314 | } 315 | } 316 | 317 | func cgoCall(buf *bytes.Buffer, d binding.Declaration) { 318 | if d.Return.Kind() != cc.Void { 319 | lapackeName := strings.TrimSuffix(strings.TrimPrefix(d.Name, prefix), suffix) 320 | var must string 321 | if needsInt[lapackeName[1:]] { 322 | must = "_must" 323 | } 324 | fmt.Fprintf(buf, "return %s(", cToGoTypeConv[d.Return.String()+must]) 325 | } 326 | fmt.Fprintf(buf, "C.%s(", d.Name) 327 | for i, p := range d.Parameters() { 328 | if i != 0 { 329 | buf.WriteString(", ") 330 | } 331 | if p.Type().Kind() == cc.Enum { 332 | buf.WriteString(binding.CgoConversionForEnum(shorten(binding.LowerCaseFirst(p.Name())), p.Type())) 333 | } else { 334 | buf.WriteString(binding.CgoConversionFor(shorten(binding.LowerCaseFirst(p.Name())), p.Type(), cgoTypes)) 335 | } 336 | } 337 | if d.Return.Kind() != cc.Void { 338 | buf.WriteString(")") 339 | } 340 | buf.WriteString(")\n") 341 | } 342 | 343 | var parameterCheckRules = []func(*bytes.Buffer, binding.Declaration, binding.Parameter) bool{ 344 | uplo, 345 | diag, 346 | side, 347 | trans, 348 | address, 349 | } 350 | 351 | func uplo(buf *bytes.Buffer, d binding.Declaration, p binding.Parameter) bool { 352 | if p.Name() != "uplo" { 353 | return false 354 | } 355 | lapackeName := strings.TrimSuffix(strings.TrimPrefix(d.Name, prefix), suffix) 356 | if !allUplo[lapackeName[1:]] { 357 | fmt.Fprint(buf, ` switch ul { 358 | case 'U', 'L': 359 | default: 360 | panic("lapack: bad triangle") 361 | } 362 | `) 363 | } 364 | return true 365 | } 366 | 367 | func diag(buf *bytes.Buffer, d binding.Declaration, p binding.Parameter) bool { 368 | if p.Name() != "diag" { 369 | return false 370 | } 371 | fmt.Fprint(buf, ` switch d { 372 | case 'U', 'N': 373 | default: 374 | panic("lapack: bad diagonal") 375 | } 376 | `) 377 | return true 378 | } 379 | 380 | func side(buf *bytes.Buffer, d binding.Declaration, p binding.Parameter) bool { 381 | if p.Name() != "side" { 382 | return false 383 | } 384 | fmt.Fprint(buf, ` switch side { 385 | case 'L', 'R': 386 | default: 387 | panic("lapack: bad side") 388 | } 389 | `) 390 | return true 391 | } 392 | 393 | func trans(buf *bytes.Buffer, d binding.Declaration, p binding.Parameter) bool { 394 | n := shorten(binding.LowerCaseFirst(p.Name())) 395 | if !strings.HasPrefix(n, "tran") { 396 | return false 397 | } 398 | fmt.Fprintf(buf, ` switch %[1]s { 399 | case 'N', 'T', 'C': 400 | default: 401 | panic("lapack: bad %[1]s") 402 | } 403 | `, n) 404 | return false 405 | } 406 | 407 | var addrTypes = map[string]string{ 408 | "char": "byte", 409 | "int": "int32", 410 | "float": "float32", 411 | "double": "float64", 412 | "float complex": "complex64", 413 | "double complex": "complex128", 414 | } 415 | 416 | func address(buf *bytes.Buffer, d binding.Declaration, p binding.Parameter) bool { 417 | n := shorten(binding.LowerCaseFirst(p.Name())) 418 | if p.Type().Kind() == cc.Ptr { 419 | t := strings.TrimPrefix(p.Type().Element().String(), "const ") 420 | fmt.Fprintf(buf, ` var _%[1]s *%[2]s 421 | if len(%[1]s) > 0 { 422 | _%[1]s = &%[1]s[0] 423 | } 424 | `, n, addrTypes[t]) 425 | } 426 | return false 427 | } 428 | 429 | const handwritten = `// Code generated by "go generate gonum.org/v1/netlib/lapack/lapacke" from {{.Header}}; DO NOT EDIT. 430 | 431 | // Copyright ©2014 The Gonum Authors. All rights reserved. 432 | // Use of this source code is governed by a BSD-style 433 | // license that can be found in the LICENSE file. 434 | 435 | // Package lapacke provides bindings to the LAPACKE C Interface to LAPACK. 436 | // 437 | // Links are provided to the NETLIB fortran implementation/dependencies for each function. 438 | package lapacke 439 | 440 | /* 441 | #cgo CFLAGS: -g -O2{{if .Lib}} 442 | #cgo LDFLAGS: {{join .Lib}}{{end}} 443 | #include "{{.Header}}" 444 | */ 445 | import "C" 446 | 447 | import "unsafe" 448 | 449 | // Type order is used to specify the matrix storage format. We still interact with 450 | // an API that allows client calls to specify order, so this is here to document that fact. 451 | type order int 452 | 453 | const ( 454 | rowMajor order = 101 + iota 455 | colMajor 456 | ) 457 | 458 | func isZero(ret C.int) bool { return ret == 0 } 459 | ` 460 | -------------------------------------------------------------------------------- /lapack/lapacke/lapacke_config.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | Copyright (c) 2010, Intel Corp. 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | * Neither the name of Intel Corporation nor the names of its contributors 14 | may be used to endorse or promote products derived from this software 15 | without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 27 | THE POSSIBILITY OF SUCH DAMAGE. 28 | ****************************************************************************** 29 | * Contents: Native C interface to LAPACK 30 | * Author: Intel Corporation 31 | * Generated May, 2011 32 | *****************************************************************************/ 33 | 34 | #ifndef _LAPACKE_CONFIG_H_ 35 | #define _LAPACKE_CONFIG_H_ 36 | 37 | #ifdef __cplusplus 38 | #if defined(LAPACK_COMPLEX_CPP) 39 | #include 40 | #endif 41 | extern "C" { 42 | #endif /* __cplusplus */ 43 | 44 | #include 45 | 46 | #ifndef lapack_int 47 | #if defined(LAPACK_ILP64) 48 | #define lapack_int long 49 | #else 50 | #define lapack_int int 51 | #endif 52 | #endif 53 | 54 | #ifndef lapack_logical 55 | #define lapack_logical lapack_int 56 | #endif 57 | 58 | #ifndef LAPACK_COMPLEX_CUSTOM 59 | 60 | #if defined(LAPACK_COMPLEX_STRUCTURE) 61 | 62 | typedef struct { float real, imag; } _lapack_complex_float; 63 | typedef struct { double real, imag; } _lapack_complex_double; 64 | #define lapack_complex_float _lapack_complex_float 65 | #define lapack_complex_double _lapack_complex_double 66 | #define lapack_complex_float_real(z) ((z).real) 67 | #define lapack_complex_float_imag(z) ((z).imag) 68 | #define lapack_complex_double_real(z) ((z).real) 69 | #define lapack_complex_double_imag(z) ((z).imag) 70 | 71 | #elif defined(LAPACK_COMPLEX_C99) 72 | 73 | #include 74 | #define lapack_complex_float float _Complex 75 | #define lapack_complex_double double _Complex 76 | #define lapack_complex_float_real(z) (creal(z)) 77 | #define lapack_complex_float_imag(z) (cimag(z)) 78 | #define lapack_complex_double_real(z) (creal(z)) 79 | #define lapack_complex_double_imag(z) (cimag(z)) 80 | 81 | #elif defined(LAPACK_COMPLEX_CPP) 82 | 83 | #define lapack_complex_float std::complex 84 | #define lapack_complex_double std::complex 85 | #define lapack_complex_float_real(z) ((z).real()) 86 | #define lapack_complex_float_imag(z) ((z).imag()) 87 | #define lapack_complex_double_real(z) ((z).real()) 88 | #define lapack_complex_double_imag(z) ((z).imag()) 89 | 90 | #else 91 | 92 | #include 93 | #define lapack_complex_float float _Complex 94 | #define lapack_complex_double double _Complex 95 | #define lapack_complex_float_real(z) (creal(z)) 96 | #define lapack_complex_float_imag(z) (cimag(z)) 97 | #define lapack_complex_double_real(z) (creal(z)) 98 | #define lapack_complex_double_imag(z) (cimag(z)) 99 | 100 | #endif 101 | 102 | lapack_complex_float lapack_make_complex_float( float re, float im ); 103 | lapack_complex_double lapack_make_complex_double( double re, double im ); 104 | 105 | #endif 106 | 107 | #ifndef LAPACK_malloc 108 | #define LAPACK_malloc( size ) malloc( size ) 109 | #endif 110 | 111 | #ifndef LAPACK_free 112 | #define LAPACK_free( p ) free( p ) 113 | #endif 114 | 115 | #ifdef __cplusplus 116 | } 117 | #endif /* __cplusplus */ 118 | 119 | #endif /* _LAPACKE_CONFIG_H_ */ 120 | -------------------------------------------------------------------------------- /lapack/lapacke/lapacke_mangling.h: -------------------------------------------------------------------------------- 1 | #ifndef LAPACK_HEADER_INCLUDED 2 | #define LAPACK_HEADER_INCLUDED 3 | 4 | #ifndef LAPACK_GLOBAL 5 | #if defined(LAPACK_GLOBAL_PATTERN_LC) || defined(ADD_) 6 | #define LAPACK_GLOBAL(lcname,UCNAME) lcname##_ 7 | #elif defined(LAPACK_GLOBAL_PATTERN_UC) || defined(UPPER) 8 | #define LAPACK_GLOBAL(lcname,UCNAME) UCNAME 9 | #elif defined(LAPACK_GLOBAL_PATTERN_MC) || defined(NOCHANGE) 10 | #define LAPACK_GLOBAL(lcname,UCNAME) lcname 11 | #else 12 | #define LAPACK_GLOBAL(lcname,UCNAME) lcname##_ 13 | #endif 14 | #endif 15 | 16 | #endif 17 | 18 | -------------------------------------------------------------------------------- /lapack/lapacke/lapacke_utils.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | Copyright (c) 2014, Intel Corp. 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | * Neither the name of Intel Corporation nor the names of its contributors 14 | may be used to endorse or promote products derived from this software 15 | without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 27 | THE POSSIBILITY OF SUCH DAMAGE. 28 | ****************************************************************************** 29 | * Contents: Native C interface to LAPACK utility functions 30 | * Author: Intel Corporation 31 | * Created in January, 2010 32 | *****************************************************************************/ 33 | 34 | #ifndef _LAPACKE_UTILS_H_ 35 | #define _LAPACKE_UTILS_H_ 36 | 37 | #include "lapacke.h" 38 | 39 | #ifdef __cplusplus 40 | extern "C" { 41 | #endif /* __cplusplus */ 42 | 43 | #ifndef ABS 44 | #define ABS(x) (((x) < 0) ? -(x) : (x)) 45 | #endif 46 | #ifndef MAX 47 | #define MAX(x,y) (((x) > (y)) ? (x) : (y)) 48 | #endif 49 | #ifndef MIN 50 | #define MIN(x,y) (((x) < (y)) ? (x) : (y)) 51 | #endif 52 | #ifndef MAX3 53 | #define MAX3(x,y,z) (((x) > MAX(y,z)) ? (x) : MAX(y,z)) 54 | #endif 55 | #ifndef MIN3 56 | #define MIN3(x,y,z) (((x) < MIN(y,z)) ? (x) : MIN(y,z)) 57 | #endif 58 | 59 | #define IS_S_NONZERO(x) ( (x) < 0 || (x) > 0 ) 60 | #define IS_D_NONZERO(x) ( (x) < 0 || (x) > 0 ) 61 | #define IS_C_NONZERO(x) ( IS_S_NONZERO(*((float*)&x)) || \ 62 | IS_S_NONZERO(*(((float*)&x)+1)) ) 63 | #define IS_Z_NONZERO(x) ( IS_D_NONZERO(*((double*)&x)) || \ 64 | IS_D_NONZERO(*(((double*)&x)+1)) ) 65 | 66 | /* Error handler */ 67 | void LAPACKE_xerbla( const char *name, lapack_int info ); 68 | 69 | /* Compare two chars (case-insensitive) */ 70 | lapack_logical LAPACKE_lsame( char ca, char cb ); 71 | 72 | /* Functions to convert column-major to row-major 2d arrays and vice versa. */ 73 | void LAPACKE_cgb_trans( int matrix_layout, lapack_int m, lapack_int n, 74 | lapack_int kl, lapack_int ku, 75 | const lapack_complex_float *in, lapack_int ldin, 76 | lapack_complex_float *out, lapack_int ldout ); 77 | void LAPACKE_cge_trans( int matrix_layout, lapack_int m, lapack_int n, 78 | const lapack_complex_float* in, lapack_int ldin, 79 | lapack_complex_float* out, lapack_int ldout ); 80 | void LAPACKE_cgg_trans( int matrix_layout, lapack_int m, lapack_int n, 81 | const lapack_complex_float* in, lapack_int ldin, 82 | lapack_complex_float* out, lapack_int ldout ); 83 | void LAPACKE_chb_trans( int matrix_layout, char uplo, lapack_int n, 84 | lapack_int kd, 85 | const lapack_complex_float *in, lapack_int ldin, 86 | lapack_complex_float *out, lapack_int ldout ); 87 | void LAPACKE_che_trans( int matrix_layout, char uplo, lapack_int n, 88 | const lapack_complex_float *in, lapack_int ldin, 89 | lapack_complex_float *out, lapack_int ldout ); 90 | void LAPACKE_chp_trans( int matrix_layout, char uplo, lapack_int n, 91 | const lapack_complex_float *in, 92 | lapack_complex_float *out ); 93 | void LAPACKE_chs_trans( int matrix_layout, lapack_int n, 94 | const lapack_complex_float *in, lapack_int ldin, 95 | lapack_complex_float *out, lapack_int ldout ); 96 | void LAPACKE_cpb_trans( int matrix_layout, char uplo, lapack_int n, 97 | lapack_int kd, 98 | const lapack_complex_float *in, lapack_int ldin, 99 | lapack_complex_float *out, lapack_int ldout ); 100 | void LAPACKE_cpf_trans( int matrix_layout, char transr, char uplo, 101 | lapack_int n, const lapack_complex_float *in, 102 | lapack_complex_float *out ); 103 | void LAPACKE_cpo_trans( int matrix_layout, char uplo, lapack_int n, 104 | const lapack_complex_float *in, lapack_int ldin, 105 | lapack_complex_float *out, lapack_int ldout ); 106 | void LAPACKE_cpp_trans( int matrix_layout, char uplo, lapack_int n, 107 | const lapack_complex_float *in, 108 | lapack_complex_float *out ); 109 | void LAPACKE_csp_trans( int matrix_layout, char uplo, lapack_int n, 110 | const lapack_complex_float *in, 111 | lapack_complex_float *out ); 112 | void LAPACKE_csy_trans( int matrix_layout, char uplo, lapack_int n, 113 | const lapack_complex_float *in, lapack_int ldin, 114 | lapack_complex_float *out, lapack_int ldout ); 115 | void LAPACKE_ctb_trans( int matrix_layout, char uplo, char diag, 116 | lapack_int n, lapack_int kd, 117 | const lapack_complex_float *in, lapack_int ldin, 118 | lapack_complex_float *out, lapack_int ldout ); 119 | void LAPACKE_ctf_trans( int matrix_layout, char transr, char uplo, char diag, 120 | lapack_int n, const lapack_complex_float *in, 121 | lapack_complex_float *out ); 122 | void LAPACKE_ctp_trans( int matrix_layout, char uplo, char diag, 123 | lapack_int n, const lapack_complex_float *in, 124 | lapack_complex_float *out ); 125 | void LAPACKE_ctr_trans( int matrix_layout, char uplo, char diag, lapack_int n, 126 | const lapack_complex_float *in, lapack_int ldin, 127 | lapack_complex_float *out, lapack_int ldout ); 128 | 129 | void LAPACKE_dgb_trans( int matrix_layout, lapack_int m, lapack_int n, 130 | lapack_int kl, lapack_int ku, 131 | const double *in, lapack_int ldin, 132 | double *out, lapack_int ldout ); 133 | void LAPACKE_dge_trans( int matrix_layout, lapack_int m, lapack_int n, 134 | const double* in, lapack_int ldin, 135 | double* out, lapack_int ldout ); 136 | void LAPACKE_dgg_trans( int matrix_layout, lapack_int m, lapack_int n, 137 | const double* in, lapack_int ldin, 138 | double* out, lapack_int ldout ); 139 | void LAPACKE_dhs_trans( int matrix_layout, lapack_int n, 140 | const double *in, lapack_int ldin, 141 | double *out, lapack_int ldout ); 142 | void LAPACKE_dpb_trans( int matrix_layout, char uplo, lapack_int n, 143 | lapack_int kd, 144 | const double *in, lapack_int ldin, 145 | double *out, lapack_int ldout ); 146 | void LAPACKE_dpf_trans( int matrix_layout, char transr, char uplo, 147 | lapack_int n, const double *in, 148 | double *out ); 149 | void LAPACKE_dpo_trans( int matrix_layout, char uplo, lapack_int n, 150 | const double *in, lapack_int ldin, 151 | double *out, lapack_int ldout ); 152 | void LAPACKE_dpp_trans( int matrix_layout, char uplo, lapack_int n, 153 | const double *in, 154 | double *out ); 155 | void LAPACKE_dsb_trans( int matrix_layout, char uplo, lapack_int n, 156 | lapack_int kd, 157 | const double *in, lapack_int ldin, 158 | double *out, lapack_int ldout ); 159 | void LAPACKE_dsp_trans( int matrix_layout, char uplo, lapack_int n, 160 | const double *in, 161 | double *out ); 162 | void LAPACKE_dsy_trans( int matrix_layout, char uplo, lapack_int n, 163 | const double *in, lapack_int ldin, 164 | double *out, lapack_int ldout ); 165 | void LAPACKE_dtb_trans( int matrix_layout, char uplo, char diag, 166 | lapack_int n, lapack_int kd, 167 | const double *in, lapack_int ldin, 168 | double *out, lapack_int ldout ); 169 | void LAPACKE_dtf_trans( int matrix_layout, char transr, char uplo, char diag, 170 | lapack_int n, const double *in, 171 | double *out ); 172 | void LAPACKE_dtp_trans( int matrix_layout, char uplo, char diag, 173 | lapack_int n, const double *in, 174 | double *out ); 175 | void LAPACKE_dtr_trans( int matrix_layout, char uplo, char diag, lapack_int n, 176 | const double *in, lapack_int ldin, 177 | double *out, lapack_int ldout ); 178 | 179 | void LAPACKE_sgb_trans( int matrix_layout, lapack_int m, lapack_int n, 180 | lapack_int kl, lapack_int ku, 181 | const float *in, lapack_int ldin, 182 | float *out, lapack_int ldout ); 183 | void LAPACKE_sge_trans( int matrix_layout, lapack_int m, lapack_int n, 184 | const float* in, lapack_int ldin, 185 | float* out, lapack_int ldout ); 186 | void LAPACKE_sgg_trans( int matrix_layout, lapack_int m, lapack_int n, 187 | const float* in, lapack_int ldin, 188 | float* out, lapack_int ldout ); 189 | void LAPACKE_shs_trans( int matrix_layout, lapack_int n, 190 | const float *in, lapack_int ldin, 191 | float *out, lapack_int ldout ); 192 | void LAPACKE_spb_trans( int matrix_layout, char uplo, lapack_int n, 193 | lapack_int kd, 194 | const float *in, lapack_int ldin, 195 | float *out, lapack_int ldout ); 196 | void LAPACKE_spf_trans( int matrix_layout, char transr, char uplo, 197 | lapack_int n, const float *in, 198 | float *out ); 199 | void LAPACKE_spo_trans( int matrix_layout, char uplo, lapack_int n, 200 | const float *in, lapack_int ldin, 201 | float *out, lapack_int ldout ); 202 | void LAPACKE_spp_trans( int matrix_layout, char uplo, lapack_int n, 203 | const float *in, 204 | float *out ); 205 | void LAPACKE_ssb_trans( int matrix_layout, char uplo, lapack_int n, 206 | lapack_int kd, 207 | const float *in, lapack_int ldin, 208 | float *out, lapack_int ldout ); 209 | void LAPACKE_ssp_trans( int matrix_layout, char uplo, lapack_int n, 210 | const float *in, 211 | float *out ); 212 | void LAPACKE_ssy_trans( int matrix_layout, char uplo, lapack_int n, 213 | const float *in, lapack_int ldin, 214 | float *out, lapack_int ldout ); 215 | void LAPACKE_stb_trans( int matrix_layout, char uplo, char diag, 216 | lapack_int n, lapack_int kd, 217 | const float *in, lapack_int ldin, 218 | float *out, lapack_int ldout ); 219 | void LAPACKE_stf_trans( int matrix_layout, char transr, char uplo, char diag, 220 | lapack_int n, const float *in, 221 | float *out ); 222 | void LAPACKE_stp_trans( int matrix_layout, char uplo, char diag, 223 | lapack_int n, const float *in, 224 | float *out ); 225 | void LAPACKE_str_trans( int matrix_layout, char uplo, char diag, lapack_int n, 226 | const float *in, lapack_int ldin, 227 | float *out, lapack_int ldout ); 228 | 229 | void LAPACKE_zgb_trans( int matrix_layout, lapack_int m, lapack_int n, 230 | lapack_int kl, lapack_int ku, 231 | const lapack_complex_double *in, lapack_int ldin, 232 | lapack_complex_double *out, lapack_int ldout ); 233 | void LAPACKE_zge_trans( int matrix_layout, lapack_int m, lapack_int n, 234 | const lapack_complex_double* in, lapack_int ldin, 235 | lapack_complex_double* out, lapack_int ldout ); 236 | void LAPACKE_zgg_trans( int matrix_layout, lapack_int m, lapack_int n, 237 | const lapack_complex_double* in, lapack_int ldin, 238 | lapack_complex_double* out, lapack_int ldout ); 239 | void LAPACKE_zhb_trans( int matrix_layout, char uplo, lapack_int n, 240 | lapack_int kd, 241 | const lapack_complex_double *in, lapack_int ldin, 242 | lapack_complex_double *out, lapack_int ldout ); 243 | void LAPACKE_zhe_trans( int matrix_layout, char uplo, lapack_int n, 244 | const lapack_complex_double *in, lapack_int ldin, 245 | lapack_complex_double *out, lapack_int ldout ); 246 | void LAPACKE_zhp_trans( int matrix_layout, char uplo, lapack_int n, 247 | const lapack_complex_double *in, 248 | lapack_complex_double *out ); 249 | void LAPACKE_zhs_trans( int matrix_layout, lapack_int n, 250 | const lapack_complex_double *in, lapack_int ldin, 251 | lapack_complex_double *out, lapack_int ldout ); 252 | void LAPACKE_zpb_trans( int matrix_layout, char uplo, lapack_int n, 253 | lapack_int kd, 254 | const lapack_complex_double *in, lapack_int ldin, 255 | lapack_complex_double *out, lapack_int ldout ); 256 | void LAPACKE_zpf_trans( int matrix_layout, char transr, char uplo, 257 | lapack_int n, const lapack_complex_double *in, 258 | lapack_complex_double *out ); 259 | void LAPACKE_zpo_trans( int matrix_layout, char uplo, lapack_int n, 260 | const lapack_complex_double *in, lapack_int ldin, 261 | lapack_complex_double *out, lapack_int ldout ); 262 | void LAPACKE_zpp_trans( int matrix_layout, char uplo, lapack_int n, 263 | const lapack_complex_double *in, 264 | lapack_complex_double *out ); 265 | void LAPACKE_zsp_trans( int matrix_layout, char uplo, lapack_int n, 266 | const lapack_complex_double *in, 267 | lapack_complex_double *out ); 268 | void LAPACKE_zsy_trans( int matrix_layout, char uplo, lapack_int n, 269 | const lapack_complex_double *in, lapack_int ldin, 270 | lapack_complex_double *out, lapack_int ldout ); 271 | void LAPACKE_ztb_trans( int matrix_layout, char uplo, char diag, 272 | lapack_int n, lapack_int kd, 273 | const lapack_complex_double *in, lapack_int ldin, 274 | lapack_complex_double *out, lapack_int ldout ); 275 | void LAPACKE_ztf_trans( int matrix_layout, char transr, char uplo, char diag, 276 | lapack_int n, const lapack_complex_double *in, 277 | lapack_complex_double *out ); 278 | void LAPACKE_ztp_trans( int matrix_layout, char uplo, char diag, 279 | lapack_int n, const lapack_complex_double *in, 280 | lapack_complex_double *out ); 281 | void LAPACKE_ztr_trans( int matrix_layout, char uplo, char diag, lapack_int n, 282 | const lapack_complex_double *in, lapack_int ldin, 283 | lapack_complex_double *out, lapack_int ldout ); 284 | 285 | /* NaN checkers */ 286 | #define LAPACK_SISNAN( x ) ( x != x ) 287 | #define LAPACK_DISNAN( x ) ( x != x ) 288 | #define LAPACK_CISNAN( x ) ( LAPACK_SISNAN(*((float*) &x)) || \ 289 | LAPACK_SISNAN(*(((float*) &x)+1)) ) 290 | #define LAPACK_ZISNAN( x ) ( LAPACK_DISNAN(*((double*)&x)) || \ 291 | LAPACK_DISNAN(*(((double*)&x)+1)) ) 292 | 293 | /* NaN checkers for vectors */ 294 | lapack_logical LAPACKE_c_nancheck( lapack_int n, 295 | const lapack_complex_float *x, 296 | lapack_int incx ); 297 | lapack_logical LAPACKE_d_nancheck( lapack_int n, 298 | const double *x, 299 | lapack_int incx ); 300 | lapack_logical LAPACKE_s_nancheck( lapack_int n, 301 | const float *x, 302 | lapack_int incx ); 303 | lapack_logical LAPACKE_z_nancheck( lapack_int n, 304 | const lapack_complex_double *x, 305 | lapack_int incx ); 306 | /* NaN checkers for matrices */ 307 | lapack_logical LAPACKE_cgb_nancheck( int matrix_layout, lapack_int m, 308 | lapack_int n, lapack_int kl, 309 | lapack_int ku, 310 | const lapack_complex_float *ab, 311 | lapack_int ldab ); 312 | lapack_logical LAPACKE_cge_nancheck( int matrix_layout, lapack_int m, 313 | lapack_int n, 314 | const lapack_complex_float *a, 315 | lapack_int lda ); 316 | lapack_logical LAPACKE_cgg_nancheck( int matrix_layout, lapack_int m, 317 | lapack_int n, 318 | const lapack_complex_float *a, 319 | lapack_int lda ); 320 | lapack_logical LAPACKE_cgt_nancheck( lapack_int n, 321 | const lapack_complex_float *dl, 322 | const lapack_complex_float *d, 323 | const lapack_complex_float *du ); 324 | lapack_logical LAPACKE_chb_nancheck( int matrix_layout, char uplo, 325 | lapack_int n, lapack_int kd, 326 | const lapack_complex_float* ab, 327 | lapack_int ldab ); 328 | lapack_logical LAPACKE_che_nancheck( int matrix_layout, char uplo, 329 | lapack_int n, 330 | const lapack_complex_float *a, 331 | lapack_int lda ); 332 | lapack_logical LAPACKE_chp_nancheck( lapack_int n, 333 | const lapack_complex_float *ap ); 334 | lapack_logical LAPACKE_chs_nancheck( int matrix_layout, lapack_int n, 335 | const lapack_complex_float *a, 336 | lapack_int lda ); 337 | lapack_logical LAPACKE_cpb_nancheck( int matrix_layout, char uplo, 338 | lapack_int n, lapack_int kd, 339 | const lapack_complex_float* ab, 340 | lapack_int ldab ); 341 | lapack_logical LAPACKE_cpf_nancheck( lapack_int n, 342 | const lapack_complex_float *a ); 343 | lapack_logical LAPACKE_cpo_nancheck( int matrix_layout, char uplo, 344 | lapack_int n, 345 | const lapack_complex_float *a, 346 | lapack_int lda ); 347 | lapack_logical LAPACKE_cpp_nancheck( lapack_int n, 348 | const lapack_complex_float *ap ); 349 | lapack_logical LAPACKE_cpt_nancheck( lapack_int n, 350 | const float *d, 351 | const lapack_complex_float *e ); 352 | lapack_logical LAPACKE_csp_nancheck( lapack_int n, 353 | const lapack_complex_float *ap ); 354 | lapack_logical LAPACKE_cst_nancheck( lapack_int n, 355 | const lapack_complex_float *d, 356 | const lapack_complex_float *e ); 357 | lapack_logical LAPACKE_csy_nancheck( int matrix_layout, char uplo, 358 | lapack_int n, 359 | const lapack_complex_float *a, 360 | lapack_int lda ); 361 | lapack_logical LAPACKE_ctb_nancheck( int matrix_layout, char uplo, char diag, 362 | lapack_int n, lapack_int kd, 363 | const lapack_complex_float* ab, 364 | lapack_int ldab ); 365 | lapack_logical LAPACKE_ctf_nancheck( int matrix_layout, char transr, 366 | char uplo, char diag, 367 | lapack_int n, 368 | const lapack_complex_float *a ); 369 | lapack_logical LAPACKE_ctp_nancheck( int matrix_layout, char uplo, char diag, 370 | lapack_int n, 371 | const lapack_complex_float *ap ); 372 | lapack_logical LAPACKE_ctr_nancheck( int matrix_layout, char uplo, char diag, 373 | lapack_int n, 374 | const lapack_complex_float *a, 375 | lapack_int lda ); 376 | 377 | lapack_logical LAPACKE_dgb_nancheck( int matrix_layout, lapack_int m, 378 | lapack_int n, lapack_int kl, 379 | lapack_int ku, 380 | const double *ab, 381 | lapack_int ldab ); 382 | lapack_logical LAPACKE_dge_nancheck( int matrix_layout, lapack_int m, 383 | lapack_int n, 384 | const double *a, 385 | lapack_int lda ); 386 | lapack_logical LAPACKE_dgg_nancheck( int matrix_layout, lapack_int m, 387 | lapack_int n, 388 | const double *a, 389 | lapack_int lda ); 390 | lapack_logical LAPACKE_dgt_nancheck( lapack_int n, 391 | const double *dl, 392 | const double *d, 393 | const double *du ); 394 | lapack_logical LAPACKE_dhs_nancheck( int matrix_layout, lapack_int n, 395 | const double *a, 396 | lapack_int lda ); 397 | lapack_logical LAPACKE_dpb_nancheck( int matrix_layout, char uplo, 398 | lapack_int n, lapack_int kd, 399 | const double* ab, 400 | lapack_int ldab ); 401 | lapack_logical LAPACKE_dpf_nancheck( lapack_int n, 402 | const double *a ); 403 | lapack_logical LAPACKE_dpo_nancheck( int matrix_layout, char uplo, 404 | lapack_int n, 405 | const double *a, 406 | lapack_int lda ); 407 | lapack_logical LAPACKE_dpp_nancheck( lapack_int n, 408 | const double *ap ); 409 | lapack_logical LAPACKE_dpt_nancheck( lapack_int n, 410 | const double *d, 411 | const double *e ); 412 | lapack_logical LAPACKE_dsb_nancheck( int matrix_layout, char uplo, 413 | lapack_int n, lapack_int kd, 414 | const double* ab, 415 | lapack_int ldab ); 416 | lapack_logical LAPACKE_dsp_nancheck( lapack_int n, 417 | const double *ap ); 418 | lapack_logical LAPACKE_dst_nancheck( lapack_int n, 419 | const double *d, 420 | const double *e ); 421 | lapack_logical LAPACKE_dsy_nancheck( int matrix_layout, char uplo, 422 | lapack_int n, 423 | const double *a, 424 | lapack_int lda ); 425 | lapack_logical LAPACKE_dtb_nancheck( int matrix_layout, char uplo, char diag, 426 | lapack_int n, lapack_int kd, 427 | const double* ab, 428 | lapack_int ldab ); 429 | lapack_logical LAPACKE_dtf_nancheck( int matrix_layout, char transr, 430 | char uplo, char diag, 431 | lapack_int n, 432 | const double *a ); 433 | lapack_logical LAPACKE_dtp_nancheck( int matrix_layout, char uplo, char diag, 434 | lapack_int n, 435 | const double *ap ); 436 | lapack_logical LAPACKE_dtr_nancheck( int matrix_layout, char uplo, char diag, 437 | lapack_int n, 438 | const double *a, 439 | lapack_int lda ); 440 | 441 | lapack_logical LAPACKE_sgb_nancheck( int matrix_layout, lapack_int m, 442 | lapack_int n, lapack_int kl, 443 | lapack_int ku, 444 | const float *ab, 445 | lapack_int ldab ); 446 | lapack_logical LAPACKE_sge_nancheck( int matrix_layout, lapack_int m, 447 | lapack_int n, 448 | const float *a, 449 | lapack_int lda ); 450 | lapack_logical LAPACKE_sgg_nancheck( int matrix_layout, lapack_int m, 451 | lapack_int n, 452 | const float *a, 453 | lapack_int lda ); 454 | lapack_logical LAPACKE_sgt_nancheck( lapack_int n, 455 | const float *dl, 456 | const float *d, 457 | const float *du ); 458 | lapack_logical LAPACKE_shs_nancheck( int matrix_layout, lapack_int n, 459 | const float *a, 460 | lapack_int lda ); 461 | lapack_logical LAPACKE_spb_nancheck( int matrix_layout, char uplo, 462 | lapack_int n, lapack_int kd, 463 | const float* ab, 464 | lapack_int ldab ); 465 | lapack_logical LAPACKE_spf_nancheck( lapack_int n, 466 | const float *a ); 467 | lapack_logical LAPACKE_spo_nancheck( int matrix_layout, char uplo, 468 | lapack_int n, 469 | const float *a, 470 | lapack_int lda ); 471 | lapack_logical LAPACKE_spp_nancheck( lapack_int n, 472 | const float *ap ); 473 | lapack_logical LAPACKE_spt_nancheck( lapack_int n, 474 | const float *d, 475 | const float *e ); 476 | lapack_logical LAPACKE_ssb_nancheck( int matrix_layout, char uplo, 477 | lapack_int n, lapack_int kd, 478 | const float* ab, 479 | lapack_int ldab ); 480 | lapack_logical LAPACKE_ssp_nancheck( lapack_int n, 481 | const float *ap ); 482 | lapack_logical LAPACKE_sst_nancheck( lapack_int n, 483 | const float *d, 484 | const float *e ); 485 | lapack_logical LAPACKE_ssy_nancheck( int matrix_layout, char uplo, 486 | lapack_int n, 487 | const float *a, 488 | lapack_int lda ); 489 | lapack_logical LAPACKE_stb_nancheck( int matrix_layout, char uplo, char diag, 490 | lapack_int n, lapack_int kd, 491 | const float* ab, 492 | lapack_int ldab ); 493 | lapack_logical LAPACKE_stf_nancheck( int matrix_layout, char transr, 494 | char uplo, char diag, 495 | lapack_int n, 496 | const float *a ); 497 | lapack_logical LAPACKE_stp_nancheck( int matrix_layout, char uplo, char diag, 498 | lapack_int n, 499 | const float *ap ); 500 | lapack_logical LAPACKE_str_nancheck( int matrix_layout, char uplo, char diag, 501 | lapack_int n, 502 | const float *a, 503 | lapack_int lda ); 504 | 505 | lapack_logical LAPACKE_zgb_nancheck( int matrix_layout, lapack_int m, 506 | lapack_int n, lapack_int kl, 507 | lapack_int ku, 508 | const lapack_complex_double *ab, 509 | lapack_int ldab ); 510 | lapack_logical LAPACKE_zge_nancheck( int matrix_layout, lapack_int m, 511 | lapack_int n, 512 | const lapack_complex_double *a, 513 | lapack_int lda ); 514 | lapack_logical LAPACKE_zgg_nancheck( int matrix_layout, lapack_int m, 515 | lapack_int n, 516 | const lapack_complex_double *a, 517 | lapack_int lda ); 518 | lapack_logical LAPACKE_zgt_nancheck( lapack_int n, 519 | const lapack_complex_double *dl, 520 | const lapack_complex_double *d, 521 | const lapack_complex_double *du ); 522 | lapack_logical LAPACKE_zhb_nancheck( int matrix_layout, char uplo, 523 | lapack_int n, lapack_int kd, 524 | const lapack_complex_double* ab, 525 | lapack_int ldab ); 526 | lapack_logical LAPACKE_zhe_nancheck( int matrix_layout, char uplo, 527 | lapack_int n, 528 | const lapack_complex_double *a, 529 | lapack_int lda ); 530 | lapack_logical LAPACKE_zhp_nancheck( lapack_int n, 531 | const lapack_complex_double *ap ); 532 | lapack_logical LAPACKE_zhs_nancheck( int matrix_layout, lapack_int n, 533 | const lapack_complex_double *a, 534 | lapack_int lda ); 535 | lapack_logical LAPACKE_zpb_nancheck( int matrix_layout, char uplo, 536 | lapack_int n, lapack_int kd, 537 | const lapack_complex_double* ab, 538 | lapack_int ldab ); 539 | lapack_logical LAPACKE_zpf_nancheck( lapack_int n, 540 | const lapack_complex_double *a ); 541 | lapack_logical LAPACKE_zpo_nancheck( int matrix_layout, char uplo, 542 | lapack_int n, 543 | const lapack_complex_double *a, 544 | lapack_int lda ); 545 | lapack_logical LAPACKE_zpp_nancheck( lapack_int n, 546 | const lapack_complex_double *ap ); 547 | lapack_logical LAPACKE_zpt_nancheck( lapack_int n, 548 | const double *d, 549 | const lapack_complex_double *e ); 550 | lapack_logical LAPACKE_zsp_nancheck( lapack_int n, 551 | const lapack_complex_double *ap ); 552 | lapack_logical LAPACKE_zst_nancheck( lapack_int n, 553 | const lapack_complex_double *d, 554 | const lapack_complex_double *e ); 555 | lapack_logical LAPACKE_zsy_nancheck( int matrix_layout, char uplo, 556 | lapack_int n, 557 | const lapack_complex_double *a, 558 | lapack_int lda ); 559 | lapack_logical LAPACKE_ztb_nancheck( int matrix_layout, char uplo, char diag, 560 | lapack_int n, lapack_int kd, 561 | const lapack_complex_double* ab, 562 | lapack_int ldab ); 563 | lapack_logical LAPACKE_ztf_nancheck( int matrix_layout, char transr, 564 | char uplo, char diag, 565 | lapack_int n, 566 | const lapack_complex_double *a ); 567 | lapack_logical LAPACKE_ztp_nancheck( int matrix_layout, char uplo, char diag, 568 | lapack_int n, 569 | const lapack_complex_double *ap ); 570 | lapack_logical LAPACKE_ztr_nancheck( int matrix_layout, char uplo, char diag, 571 | lapack_int n, 572 | const lapack_complex_double *a, 573 | lapack_int lda ); 574 | 575 | #ifdef __cplusplus 576 | } 577 | #endif /* __cplusplus */ 578 | 579 | #endif /* _LAPACKE_UTILS_H_ */ 580 | -------------------------------------------------------------------------------- /lapack/netlib/bench_test.go: -------------------------------------------------------------------------------- 1 | // Copyright ©2016 The Gonum Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package netlib 6 | 7 | import ( 8 | "testing" 9 | 10 | "gonum.org/v1/gonum/lapack/testlapack" 11 | ) 12 | 13 | func BenchmarkDgeev(b *testing.B) { testlapack.DgeevBenchmark(b, impl) } 14 | -------------------------------------------------------------------------------- /lapack/netlib/conv.go: -------------------------------------------------------------------------------- 1 | // Copyright ©2019 The Gonum Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package netlib 6 | 7 | import "gonum.org/v1/gonum/blas" 8 | 9 | // bandTriToLapacke converts a triangular or symmetric band matrix A in CBLAS 10 | // row-major layout to LAPACKE row-major layout and stores the result in B. 11 | // 12 | // For example, when n = 6, kd = 2 and uplo == 'U', bandTriToLapacke converts 13 | // A = a00 a01 a02 14 | // a11 a12 a13 15 | // a22 a23 a24 16 | // a33 a34 a35 17 | // a44 a45 * 18 | // a55 * * 19 | // stored in a slice as 20 | // a = [a00 a01 a02 a11 a12 a13 a22 a23 a24 a33 a34 a35 a44 a45 * a55 * *] 21 | // to 22 | // B = * * a02 a13 a24 a35 23 | // * a01 a12 a23 a34 a45 24 | // a00 a11 a22 a33 a44 a55 25 | // stored in a slice as 26 | // b = [* * a02 a13 a24 a35 * a01 a12 a23 a34 a45 a00 a11 a22 a33 a44 a55] 27 | // 28 | // When n = 6, kd = 2 and uplo == 'L', bandTriToLapacke converts 29 | // A = * * a00 30 | // * a10 a11 31 | // a20 a21 a22 32 | // a31 a32 a33 33 | // a42 a43 a44 34 | // a53 a54 a55 35 | // stored in a slice as 36 | // a = [* * a00 * a10 a11 a20 a21 a22 a31 a32 a33 a42 a43 a44 a53 a54 a55] 37 | // to 38 | // B = a00 a11 a22 a33 a44 a55 39 | // a10 a21 a32 a43 a54 * 40 | // a20 a31 a42 a53 * * 41 | // stored in a slice as 42 | // b = [a00 a11 a22 a33 a44 a55 a10 a21 a32 a43 a54 * a20 a31 a42 a53 * * ] 43 | // 44 | // In these example elements marked as * are not referenced. 45 | func bandTriToLapacke(uplo blas.Uplo, n, kd int, a []float64, lda int, b []float64, ldb int) { 46 | if uplo == blas.Upper { 47 | for i := 0; i < n; i++ { 48 | for jb := 0; jb < min(n-i, kd+1); jb++ { 49 | j := i + jb // Column index in the full matrix 50 | b[(kd-jb)*ldb+j] = a[i*lda+jb] 51 | } 52 | } 53 | } else { 54 | for i := 0; i < n; i++ { 55 | for jb := max(0, kd-i); jb < kd+1; jb++ { 56 | j := i - kd + jb // Column index in the full matrix 57 | b[(kd-jb)*ldb+j] = a[i*lda+jb] 58 | } 59 | } 60 | } 61 | } 62 | 63 | // bandTriToGonum converts a triangular or symmetric band matrix A in LAPACKE 64 | // row-major layout to CBLAS row-major layout and stores the result in B. In 65 | // other words, it performs the inverse conversion to bandTriToLapacke. 66 | func bandTriToGonum(uplo blas.Uplo, n, kd int, a []float64, lda int, b []float64, ldb int) { 67 | if uplo == blas.Upper { 68 | for j := 0; j < n; j++ { 69 | for ib := max(0, kd-j); ib < kd+1; ib++ { 70 | i := j - kd + ib // Row index in the full matrix 71 | b[i*ldb+kd-ib] = a[ib*lda+j] 72 | } 73 | } 74 | } else { 75 | for j := 0; j < n; j++ { 76 | for ib := 0; ib < min(n-j, kd+1); ib++ { 77 | i := j + ib // Row index in the full matrix 78 | b[i*ldb+kd-ib] = a[ib*lda+j] 79 | } 80 | } 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /lapack/netlib/conv_test.go: -------------------------------------------------------------------------------- 1 | // Copyright ©2019 The Gonum Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package netlib 6 | 7 | import ( 8 | "fmt" 9 | "testing" 10 | 11 | "golang.org/x/exp/rand" 12 | 13 | "gonum.org/v1/gonum/blas" 14 | "gonum.org/v1/gonum/floats" 15 | ) 16 | 17 | func TestConvBandTri(t *testing.T) { 18 | for ti, test := range []struct { 19 | uplo blas.Uplo 20 | n, kd int 21 | a, b []float64 22 | }{ 23 | { 24 | uplo: blas.Upper, 25 | n: 6, 26 | kd: 2, 27 | a: []float64{ 28 | 1, 2, 3, // 1. row 29 | 4, 5, 6, 30 | 7, 8, 9, 31 | 10, 11, 12, 32 | 13, 14, -1, 33 | 15, -1, -1, // 6. row 34 | }, 35 | b: []float64{ 36 | -1, -1, 3, 6, 9, 12, // 2. super-diagonal 37 | -1, 2, 5, 8, 11, 14, 38 | 1, 4, 7, 10, 13, 15, // main diagonal 39 | }, 40 | }, 41 | { 42 | uplo: blas.Lower, 43 | n: 6, 44 | kd: 2, 45 | a: []float64{ 46 | -1, -1, 1, // 1. row 47 | -1, 2, 3, 48 | 4, 5, 6, 49 | 7, 8, 9, 50 | 10, 11, 12, 51 | 13, 14, 15, // 6. row 52 | }, 53 | b: []float64{ 54 | 1, 3, 6, 9, 12, 15, // main diagonal 55 | 2, 5, 8, 11, 14, -1, 56 | 4, 7, 10, 13, -1, -1, // 2. sub-diagonal 57 | }, 58 | }, 59 | } { 60 | uplo := test.uplo 61 | n := test.n 62 | kd := test.kd 63 | name := fmt.Sprintf("Case %v (uplo=%c,n=%v,kd=%v)", ti, uplo, n, kd) 64 | 65 | a := make([]float64, len(test.a)) 66 | copy(a, test.a) 67 | lda := kd + 1 68 | 69 | got := make([]float64, len(test.b)) 70 | for i := range got { 71 | got[i] = -1 72 | } 73 | ldb := max(1, n) 74 | 75 | bandTriToLapacke(uplo, n, kd, a, lda, got, ldb) 76 | if !floats.Equal(test.a, a) { 77 | t.Errorf("%v: unexpected modification of A in conversion to LAPACKE row-major", name) 78 | } 79 | if !floats.Equal(test.b, got) { 80 | t.Errorf("%v: unexpected conversion to LAPACKE row-major;\ngot %v\nwant %v", name, got, test.b) 81 | } 82 | 83 | b := make([]float64, len(test.b)) 84 | copy(b, test.b) 85 | 86 | got = make([]float64, len(test.a)) 87 | for i := range got { 88 | got[i] = -1 89 | } 90 | 91 | bandTriToGonum(uplo, n, kd, b, ldb, got, lda) 92 | if !floats.Equal(test.b, b) { 93 | t.Errorf("%v: unexpected modification of B in conversion to Gonum row-major", name) 94 | } 95 | if !floats.Equal(test.a, got) { 96 | t.Errorf("%v: unexpected conversion to Gonum row-major;\ngot %v\nwant %v", name, got, test.b) 97 | } 98 | } 99 | 100 | rnd := rand.New(rand.NewSource(1)) 101 | for _, n := range []int{0, 1, 2, 3, 4, 5, 10} { 102 | for _, kd := range []int{0, (n + 1) / 4, (3*n - 1) / 4, (5*n + 1) / 4} { 103 | for _, uplo := range []blas.Uplo{blas.Upper, blas.Lower} { 104 | for _, ldextra := range []int{0, 3} { 105 | name := fmt.Sprintf("uplo=%c,n=%v,kd=%v", uplo, n, kd) 106 | 107 | lda := kd + 1 + ldextra 108 | a := make([]float64, n*lda) 109 | for i := range a { 110 | a[i] = rnd.NormFloat64() 111 | } 112 | aCopy := make([]float64, len(a)) 113 | copy(aCopy, a) 114 | 115 | ldb := max(1, n) + ldextra 116 | b := make([]float64, (kd+1)*ldb) 117 | for i := range b { 118 | b[i] = rnd.NormFloat64() 119 | } 120 | 121 | bandTriToLapacke(uplo, n, kd, a, lda, b, ldb) 122 | bandTriToGonum(uplo, n, kd, b, ldb, a, lda) 123 | 124 | if !floats.Equal(a, aCopy) { 125 | t.Errorf("%v: conversion does not roundtrip", name) 126 | } 127 | } 128 | } 129 | } 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /lapack/netlib/errors.go: -------------------------------------------------------------------------------- 1 | // Code generated by "go generate gonum.org/v1/netlib/lapack/netlib”; DO NOT EDIT. 2 | 3 | // Copyright ©2015 The Gonum Authors. All rights reserved. 4 | // Use of this source code is governed by a BSD-style 5 | // license that can be found in the LICENSE file. 6 | 7 | package netlib 8 | 9 | // Copied from gonum/lapack/gonum. Keep in sync. 10 | const ( 11 | // Panic strings for bad enumeration values. 12 | badApplyOrtho = "lapack: bad ApplyOrtho" 13 | badBalanceJob = "lapack: bad BalanceJob" 14 | badDiag = "lapack: bad Diag" 15 | badDirect = "lapack: bad Direct" 16 | badEVComp = "lapack: bad EVComp" 17 | badEVHowMany = "lapack: bad EVHowMany" 18 | badEVJob = "lapack: bad EVJob" 19 | badEVSide = "lapack: bad EVSide" 20 | badGSVDJob = "lapack: bad GSVDJob" 21 | badGenOrtho = "lapack: bad GenOrtho" 22 | badLeftEVJob = "lapack: bad LeftEVJob" 23 | badMatrixType = "lapack: bad MatrixType" 24 | badMaximizeNormXJob = "lapack: bad MaximizeNormXJob" 25 | badNorm = "lapack: bad Norm" 26 | badPivot = "lapack: bad Pivot" 27 | badRightEVJob = "lapack: bad RightEVJob" 28 | badSVDJob = "lapack: bad SVDJob" 29 | badSchurComp = "lapack: bad SchurComp" 30 | badSchurJob = "lapack: bad SchurJob" 31 | badSide = "lapack: bad Side" 32 | badSort = "lapack: bad Sort" 33 | badStoreV = "lapack: bad StoreV" 34 | badTrans = "lapack: bad Trans" 35 | badUpdateSchurComp = "lapack: bad UpdateSchurComp" 36 | badUplo = "lapack: bad Uplo" 37 | bothSVDOver = "lapack: both jobU and jobVT are lapack.SVDOverwrite" 38 | 39 | // Panic strings for bad numerical and string values. 40 | badIfst = "lapack: ifst out of range" 41 | badIhi = "lapack: ihi out of range" 42 | badIhiz = "lapack: ihiz out of range" 43 | badIlo = "lapack: ilo out of range" 44 | badIloz = "lapack: iloz out of range" 45 | badIlst = "lapack: ilst out of range" 46 | badIsave = "lapack: bad isave value" 47 | badIspec = "lapack: bad ispec value" 48 | badJ1 = "lapack: j1 out of range" 49 | badJpvt = "lapack: bad element of jpvt" 50 | badK1 = "lapack: k1 out of range" 51 | badK2 = "lapack: k2 out of range" 52 | badKacc22 = "lapack: invalid value of kacc22" 53 | badKbot = "lapack: kbot out of range" 54 | badKtop = "lapack: ktop out of range" 55 | badLWork = "lapack: insufficient declared workspace length" 56 | badMm = "lapack: mm out of range" 57 | badN1 = "lapack: bad value of n1" 58 | badN2 = "lapack: bad value of n2" 59 | badNa = "lapack: bad value of na" 60 | badName = "lapack: bad name" 61 | badNh = "lapack: bad value of nh" 62 | badNw = "lapack: bad value of nw" 63 | badPp = "lapack: bad value of pp" 64 | badShifts = "lapack: bad shifts" 65 | i0LT0 = "lapack: i0 < 0" 66 | kGTM = "lapack: k > m" 67 | kGTN = "lapack: k > n" 68 | kLT0 = "lapack: k < 0" 69 | kLT1 = "lapack: k < 1" 70 | kdLT0 = "lapack: kd < 0" 71 | klLT0 = "lapack: kl < 0" 72 | kuLT0 = "lapack: ku < 0" 73 | mGTN = "lapack: m > n" 74 | mLT0 = "lapack: m < 0" 75 | mmLT0 = "lapack: mm < 0" 76 | n0LT0 = "lapack: n0 < 0" 77 | nGTM = "lapack: n > m" 78 | nLT0 = "lapack: n < 0" 79 | nLT1 = "lapack: n < 1" 80 | nLTM = "lapack: n < m" 81 | nanCFrom = "lapack: cfrom is NaN" 82 | nanCTo = "lapack: cto is NaN" 83 | nbGTM = "lapack: nb > m" 84 | nbGTN = "lapack: nb > n" 85 | nbLT0 = "lapack: nb < 0" 86 | nccLT0 = "lapack: ncc < 0" 87 | ncvtLT0 = "lapack: ncvt < 0" 88 | negANorm = "lapack: anorm < 0" 89 | negZ = "lapack: negative z value" 90 | nhLT0 = "lapack: nh < 0" 91 | notIsolated = "lapack: block is not isolated" 92 | nrhsLT0 = "lapack: nrhs < 0" 93 | nruLT0 = "lapack: nru < 0" 94 | nshftsLT0 = "lapack: nshfts < 0" 95 | nshftsOdd = "lapack: nshfts must be even" 96 | nvLT0 = "lapack: nv < 0" 97 | offsetGTM = "lapack: offset > m" 98 | offsetLT0 = "lapack: offset < 0" 99 | pLT0 = "lapack: p < 0" 100 | recurLT0 = "lapack: recur < 0" 101 | zeroCFrom = "lapack: zero cfrom" 102 | 103 | // Panic strings for bad slice lengths. 104 | badLenAlpha = "lapack: bad length of alpha" 105 | badLenBeta = "lapack: bad length of beta" 106 | badLenIpiv = "lapack: bad length of ipiv" 107 | badLenJpiv = "lapack: bad length of jpiv" 108 | badLenJpvt = "lapack: bad length of jpvt" 109 | badLenK = "lapack: bad length of k" 110 | badLenPiv = "lapack: bad length of piv" 111 | badLenSelected = "lapack: bad length of selected" 112 | badLenSi = "lapack: bad length of si" 113 | badLenSr = "lapack: bad length of sr" 114 | badLenTau = "lapack: bad length of tau" 115 | badLenWi = "lapack: bad length of wi" 116 | badLenWr = "lapack: bad length of wr" 117 | 118 | // Panic strings for insufficient slice lengths. 119 | shortA = "lapack: insufficient length of a" 120 | shortAB = "lapack: insufficient length of ab" 121 | shortAuxv = "lapack: insufficient length of auxv" 122 | shortB = "lapack: insufficient length of b" 123 | shortC = "lapack: insufficient length of c" 124 | shortCNorm = "lapack: insufficient length of cnorm" 125 | shortD = "lapack: insufficient length of d" 126 | shortDL = "lapack: insufficient length of dl" 127 | shortDU = "lapack: insufficient length of du" 128 | shortE = "lapack: insufficient length of e" 129 | shortF = "lapack: insufficient length of f" 130 | shortH = "lapack: insufficient length of h" 131 | shortIWork = "lapack: insufficient length of iwork" 132 | shortIsgn = "lapack: insufficient length of isgn" 133 | shortQ = "lapack: insufficient length of q" 134 | shortRHS = "lapack: insufficient length of rhs" 135 | shortS = "lapack: insufficient length of s" 136 | shortScale = "lapack: insufficient length of scale" 137 | shortT = "lapack: insufficient length of t" 138 | shortTau = "lapack: insufficient length of tau" 139 | shortTauP = "lapack: insufficient length of tauP" 140 | shortTauQ = "lapack: insufficient length of tauQ" 141 | shortU = "lapack: insufficient length of u" 142 | shortV = "lapack: insufficient length of v" 143 | shortVL = "lapack: insufficient length of vl" 144 | shortVR = "lapack: insufficient length of vr" 145 | shortVT = "lapack: insufficient length of vt" 146 | shortVn1 = "lapack: insufficient length of vn1" 147 | shortVn2 = "lapack: insufficient length of vn2" 148 | shortW = "lapack: insufficient length of w" 149 | shortWH = "lapack: insufficient length of wh" 150 | shortWV = "lapack: insufficient length of wv" 151 | shortWi = "lapack: insufficient length of wi" 152 | shortWork = "lapack: insufficient length of work" 153 | shortWr = "lapack: insufficient length of wr" 154 | shortX = "lapack: insufficient length of x" 155 | shortY = "lapack: insufficient length of y" 156 | shortZ = "lapack: insufficient length of z" 157 | 158 | // Panic strings for bad leading dimensions of matrices. 159 | badLdA = "lapack: bad leading dimension of A" 160 | badLdB = "lapack: bad leading dimension of B" 161 | badLdC = "lapack: bad leading dimension of C" 162 | badLdF = "lapack: bad leading dimension of F" 163 | badLdH = "lapack: bad leading dimension of H" 164 | badLdQ = "lapack: bad leading dimension of Q" 165 | badLdT = "lapack: bad leading dimension of T" 166 | badLdU = "lapack: bad leading dimension of U" 167 | badLdV = "lapack: bad leading dimension of V" 168 | badLdVL = "lapack: bad leading dimension of VL" 169 | badLdVR = "lapack: bad leading dimension of VR" 170 | badLdVT = "lapack: bad leading dimension of VT" 171 | badLdW = "lapack: bad leading dimension of W" 172 | badLdWH = "lapack: bad leading dimension of WH" 173 | badLdWV = "lapack: bad leading dimension of WV" 174 | badLdWork = "lapack: bad leading dimension of Work" 175 | badLdX = "lapack: bad leading dimension of X" 176 | badLdY = "lapack: bad leading dimension of Y" 177 | badLdZ = "lapack: bad leading dimension of Z" 178 | 179 | // Panic strings for bad vector increments. 180 | absIncNotOne = "lapack: increment not one or negative one" 181 | badIncX = "lapack: incX <= 0" 182 | badIncY = "lapack: incY <= 0" 183 | zeroIncV = "lapack: incv == 0" 184 | ) 185 | -------------------------------------------------------------------------------- /lapack/netlib/generate.go: -------------------------------------------------------------------------------- 1 | // Copyright ©2018 The Gonum Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:generate go run generate_errors.go 6 | 7 | package netlib 8 | -------------------------------------------------------------------------------- /lapack/netlib/generate_errors.go: -------------------------------------------------------------------------------- 1 | // Copyright ©2018 The Gonum Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build ignore 6 | 7 | package main 8 | 9 | import ( 10 | "bytes" 11 | "fmt" 12 | "go/ast" 13 | "go/parser" 14 | "go/printer" 15 | "go/token" 16 | "log" 17 | "os" 18 | "os/exec" 19 | "path/filepath" 20 | "strings" 21 | ) 22 | 23 | const ( 24 | srcModule = "gonum.org/v1/gonum" 25 | errorFile = "lapack/gonum/errors.go" 26 | ) 27 | 28 | func main() { 29 | path, err := pathTo(srcModule, errorFile) 30 | if err != nil { 31 | log.Fatalf("no source for %q: %v", errorFile, err) 32 | } 33 | 34 | fset := token.NewFileSet() 35 | f, err := parser.ParseFile(fset, path, nil, parser.ParseComments) 36 | if err != nil { 37 | log.Fatalf("failed to parse %q: %v", path, err) 38 | } 39 | 40 | dst := filepath.Base(errorFile) 41 | o, err := os.Create(dst) 42 | if err != nil { 43 | log.Fatalf("failed to create %q: %v", dst, err) 44 | } 45 | defer o.Close() 46 | 47 | fmt.Fprintln(o, header) 48 | for _, cg := range f.Comments { 49 | for _, c := range cg.List { 50 | fmt.Fprintln(o, c.Text) 51 | } 52 | break 53 | } 54 | fmt.Fprintln(o, pkg) 55 | p := printer.Config{ 56 | Mode: printer.UseSpaces | printer.TabIndent, 57 | Tabwidth: 8, 58 | } 59 | // Remove comment associated with the const block. 60 | for _, d := range f.Decls { 61 | if d, ok := d.(*ast.GenDecl); ok { 62 | d.Doc = nil 63 | } 64 | } 65 | p.Fprint(o, fset, f.Decls) 66 | fmt.Fprintln(o) 67 | } 68 | 69 | // pathTo returns the path to file within the given module. If running 70 | // in module mode, this will look within the module in $GOPATH/pkg/mod 71 | // at the correct version, otherwise it will find the version installed 72 | // at $GOPATH/src/module/file. 73 | func pathTo(module, file string) (string, error) { 74 | gopath, ok := os.LookupEnv("GOPATH") 75 | if !ok { 76 | var err error 77 | gopath, err = os.UserHomeDir() 78 | if err != nil { 79 | return "", err 80 | } 81 | gopath = filepath.Join(gopath, "go") 82 | } 83 | 84 | cmd := exec.Command("go", "list", "-m", module) 85 | var buf, stderr bytes.Buffer 86 | cmd.Stdout = &buf 87 | cmd.Stderr = &stderr 88 | err := cmd.Run() 89 | if err != nil { 90 | return "", fmt.Errorf("module aware go list failed with stderr output %q: %w", stderr.String(), err) 91 | } 92 | version := strings.TrimSpace(strings.Join(strings.Split(buf.String(), " "), "@")) 93 | return filepath.Join(gopath, "pkg", "mod", version, file), nil 94 | } 95 | 96 | const ( 97 | header = `// Code generated by "go generate gonum.org/v1/netlib/lapack/netlib”; DO NOT EDIT. 98 | ` 99 | pkg = ` 100 | package netlib 101 | 102 | // Copied from gonum/lapack/gonum. Keep in sync.` 103 | ) 104 | -------------------------------------------------------------------------------- /lapack/netlib/lapack_test.go: -------------------------------------------------------------------------------- 1 | // Copyright ©2015 The Gonum Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package netlib 6 | 7 | import ( 8 | "testing" 9 | 10 | "gonum.org/v1/gonum/blas" 11 | "gonum.org/v1/gonum/lapack/testlapack" 12 | ) 13 | 14 | var impl = Implementation{} 15 | 16 | // blockedTranslate transforms some blocked C calls to be the unblocked algorithms 17 | // for testing, as several of the unblocked algorithms are not defined by the C 18 | // interface. 19 | type blockedTranslate struct { 20 | Implementation 21 | } 22 | 23 | func TestDbdsqr(t *testing.T) { 24 | testlapack.DbdsqrTest(t, impl) 25 | } 26 | 27 | func (bl blockedTranslate) Dgebd2(m, n int, a []float64, lda int, d, e, tauQ, tauP, work []float64) { 28 | impl.Dgebrd(m, n, a, lda, d, e, tauQ, tauP, work, len(work)) 29 | } 30 | 31 | func (bl blockedTranslate) Dorm2r(side blas.Side, trans blas.Transpose, m, n, k int, a []float64, lda int, tau, c []float64, ldc int, work []float64) { 32 | impl.Dormqr(side, trans, m, n, k, a, lda, tau, c, ldc, work, len(work)) 33 | } 34 | 35 | func (bl blockedTranslate) Dorml2(side blas.Side, trans blas.Transpose, m, n, k int, a []float64, lda int, tau, c []float64, ldc int, work []float64) { 36 | impl.Dormlq(side, trans, m, n, k, a, lda, tau, c, ldc, work, len(work)) 37 | } 38 | 39 | func (bl blockedTranslate) Dorg2r(m, n, k int, a []float64, lda int, tau, work []float64) { 40 | impl.Dorgqr(m, n, k, a, lda, tau, work, len(work)) 41 | } 42 | 43 | func (bl blockedTranslate) Dorgl2(m, n, k int, a []float64, lda int, tau, work []float64) { 44 | impl.Dorglq(m, n, k, a, lda, tau, work, len(work)) 45 | } 46 | 47 | func TestDgeqp3(t *testing.T) { 48 | testlapack.Dgeqp3Test(t, impl) 49 | } 50 | 51 | func TestDlacn2(t *testing.T) { 52 | testlapack.Dlacn2Test(t, impl) 53 | } 54 | 55 | func TestDlascl(t *testing.T) { 56 | testlapack.DlasclTest(t, impl) 57 | } 58 | 59 | func TestDlacpy(t *testing.T) { 60 | testlapack.DlacpyTest(t, impl) 61 | } 62 | 63 | func TestDlange(t *testing.T) { 64 | testlapack.DlangeTest(t, impl) 65 | } 66 | 67 | func TestDlansy(t *testing.T) { 68 | testlapack.DlansyTest(t, impl) 69 | } 70 | 71 | func TestDlantr(t *testing.T) { 72 | testlapack.DlantrTest(t, impl) 73 | } 74 | 75 | func TestDlarfb(t *testing.T) { 76 | testlapack.DlarfbTest(t, impl) 77 | } 78 | 79 | func TestDlarfg(t *testing.T) { 80 | testlapack.DlarfgTest(t, impl) 81 | } 82 | 83 | func TestDlarft(t *testing.T) { 84 | testlapack.DlarftTest(t, impl) 85 | } 86 | 87 | func TestDlapmr(t *testing.T) { 88 | testlapack.DlapmrTest(t, impl) 89 | } 90 | 91 | func TestDlapmt(t *testing.T) { 92 | testlapack.DlapmtTest(t, impl) 93 | } 94 | 95 | func TestDlapy2(t *testing.T) { 96 | testlapack.Dlapy2Test(t, impl) 97 | } 98 | 99 | func TestDlarfx(t *testing.T) { 100 | testlapack.DlarfxTest(t, impl) 101 | } 102 | 103 | func TestDlaset(t *testing.T) { 104 | testlapack.DlasetTest(t, impl) 105 | } 106 | 107 | func TestDlasrt(t *testing.T) { 108 | testlapack.DlasrtTest(t, impl) 109 | } 110 | 111 | func TestDlaswp(t *testing.T) { 112 | testlapack.DlaswpTest(t, impl) 113 | } 114 | 115 | func TestDpbcon(t *testing.T) { 116 | testlapack.DpbconTest(t, impl) 117 | } 118 | 119 | func TestDpbtrf(t *testing.T) { 120 | testlapack.DpbtrfTest(t, impl) 121 | } 122 | 123 | func TestDpbtrs(t *testing.T) { 124 | testlapack.DpbtrsTest(t, impl) 125 | } 126 | 127 | func TestDpotrf(t *testing.T) { 128 | testlapack.DpotrfTest(t, impl) 129 | } 130 | 131 | func TestDpotri(t *testing.T) { 132 | testlapack.DpotriTest(t, impl) 133 | } 134 | 135 | func TestDpotrs(t *testing.T) { 136 | testlapack.DpotrsTest(t, impl) 137 | } 138 | 139 | func TestDpstrf(t *testing.T) { 140 | testlapack.DpstrfTest(t, impl) 141 | } 142 | 143 | func TestDgebak(t *testing.T) { 144 | testlapack.DgebakTest(t, impl) 145 | } 146 | 147 | func TestDgebal(t *testing.T) { 148 | testlapack.DgebalTest(t, impl) 149 | } 150 | 151 | func TestDgebd2(t *testing.T) { 152 | testlapack.Dgebd2Test(t, blockedTranslate{impl}) 153 | } 154 | 155 | func TestDgecon(t *testing.T) { 156 | testlapack.DgeconTest(t, impl) 157 | } 158 | 159 | func TestDgeev(t *testing.T) { 160 | testlapack.DgeevTest(t, impl) 161 | } 162 | 163 | func TestDgehrd(t *testing.T) { 164 | testlapack.DgehrdTest(t, impl) 165 | } 166 | 167 | func TestDgelq2(t *testing.T) { 168 | testlapack.Dgelq2Test(t, impl) 169 | } 170 | 171 | func TestDgels(t *testing.T) { 172 | testlapack.DgelsTest(t, impl) 173 | } 174 | 175 | func TestDgelqf(t *testing.T) { 176 | testlapack.DgelqfTest(t, impl) 177 | } 178 | 179 | func TestDgeqr2(t *testing.T) { 180 | testlapack.Dgeqr2Test(t, impl) 181 | } 182 | 183 | func TestDgeqrf(t *testing.T) { 184 | testlapack.DgeqrfTest(t, impl) 185 | } 186 | 187 | func TestDgerqf(t *testing.T) { 188 | testlapack.DgerqfTest(t, impl) 189 | } 190 | 191 | func TestDgesvd(t *testing.T) { 192 | const tol = 1e-12 193 | testlapack.DgesvdTest(t, impl, tol) 194 | } 195 | 196 | func TestDgetf2(t *testing.T) { 197 | testlapack.Dgetf2Test(t, impl) 198 | } 199 | 200 | func TestDgetrf(t *testing.T) { 201 | testlapack.DgetrfTest(t, impl) 202 | } 203 | 204 | func TestDgetri(t *testing.T) { 205 | testlapack.DgetriTest(t, impl) 206 | } 207 | 208 | func TestDgetrs(t *testing.T) { 209 | testlapack.DgetrsTest(t, impl) 210 | } 211 | 212 | func TestDggsvd3(t *testing.T) { 213 | testlapack.Dggsvd3Test(t, impl) 214 | } 215 | 216 | func TestDggsvp3(t *testing.T) { 217 | testlapack.Dggsvp3Test(t, impl) 218 | } 219 | 220 | func TestDhseqr(t *testing.T) { 221 | testlapack.DhseqrTest(t, impl) 222 | } 223 | 224 | func TestDorglq(t *testing.T) { 225 | testlapack.DorglqTest(t, blockedTranslate{impl}) 226 | } 227 | 228 | func TestDorgql(t *testing.T) { 229 | testlapack.DorgqlTest(t, impl) 230 | } 231 | 232 | func TestDorgqr(t *testing.T) { 233 | testlapack.DorgqrTest(t, blockedTranslate{impl}) 234 | } 235 | 236 | func TestDorgtr(t *testing.T) { 237 | testlapack.DorgtrTest(t, impl) 238 | } 239 | 240 | func TestDorgl2(t *testing.T) { 241 | testlapack.Dorgl2Test(t, blockedTranslate{impl}) 242 | } 243 | 244 | func TestDorg2r(t *testing.T) { 245 | testlapack.Dorg2rTest(t, blockedTranslate{impl}) 246 | } 247 | 248 | func TestDormbr(t *testing.T) { 249 | testlapack.DormbrTest(t, blockedTranslate{impl}) 250 | } 251 | 252 | func TestDormhr(t *testing.T) { 253 | testlapack.DormhrTest(t, impl) 254 | } 255 | 256 | func TestDorgbr(t *testing.T) { 257 | testlapack.DorgbrTest(t, blockedTranslate{impl}) 258 | } 259 | 260 | func TestDorghr(t *testing.T) { 261 | testlapack.DorghrTest(t, impl) 262 | } 263 | 264 | func TestDormqr(t *testing.T) { 265 | testlapack.Dorm2rTest(t, blockedTranslate{impl}) 266 | } 267 | 268 | func TestDormlq(t *testing.T) { 269 | testlapack.Dorml2Test(t, blockedTranslate{impl}) 270 | } 271 | 272 | func TestDpocon(t *testing.T) { 273 | testlapack.DpoconTest(t, impl) 274 | } 275 | 276 | func TestDsteqr(t *testing.T) { 277 | testlapack.DsteqrTest(t, impl) 278 | } 279 | 280 | func TestDsterf(t *testing.T) { 281 | testlapack.DsterfTest(t, impl) 282 | } 283 | 284 | func TestDsyev(t *testing.T) { 285 | testlapack.DsyevTest(t, impl) 286 | } 287 | 288 | func TestDsytrd(t *testing.T) { 289 | testlapack.DsytrdTest(t, impl) 290 | } 291 | 292 | func TestDtgsja(t *testing.T) { 293 | testlapack.DtgsjaTest(t, impl) 294 | } 295 | 296 | func TestDtbtrs(t *testing.T) { 297 | t.Parallel() 298 | testlapack.DtbtrsTest(t, impl) 299 | } 300 | 301 | func TestDtrexc(t *testing.T) { 302 | testlapack.DtrexcTest(t, impl) 303 | } 304 | 305 | func TestDtrcon(t *testing.T) { 306 | testlapack.DtrconTest(t, impl) 307 | } 308 | 309 | func TestDtrtri(t *testing.T) { 310 | testlapack.DtrtriTest(t, impl) 311 | } 312 | --------------------------------------------------------------------------------