{% set name = "numpy" %}
{% set version = "1.15.4" %}
{% set mkl_random_version = "1.0.2" %}
{% set mkl_random_buildnumber = 0 %}
{% set mkl_fft_version = "1.0.6" %}
{% set mkl_fft_buildnumber = 0 %}

package:
  name: numpy_and_dev
  version: {{ version }}

source:
  - url: https://pypi.io/packages/source/{{ name[0] }}/{{ name }}/{{ name }}-{{ version }}.zip
    sha256: 3d734559db35aa3697dadcea492a423118c5c55d176da2f3be9c98d4803fc2a7
    patches:
      - 0001-fix-windows-case-sensitivity.patch
      - 0002-simplify-arch-flags.patch
      - 0003-Obtain-and-prefer-custom-gfortran-from-env-variable.patch
      - 0004-disable-memmap-filename-test-due-to-CI-link-confusio.patch
      - 0005-disable-broken-tests.patch
      {% if blas_impl == "mkl" and (not win or vc|int >= 14) -%}
      # patches for MKL based enhancements
      - 0006-use-mklfft-when-available.patch
      - 0007-define-mkl_version-in-__init__.py.patch
      - 0008-intel-umath-optimizations.patch
      - 0009-intel-mkl_mem-all.patch
      - 0010-intel-init_mkl.patch
      - 0011-intel-mkl_random.patch
      # patch up MKL patches
      - 0012-Remove-ICC-specific-flags.patch
      - 0013-Remove-np.invsqrt.patch
      - 0014-Rewrite-inlining.patch
      {%- endif %}
      # precision issue with longdouble on ppc64le
      # https://github.com/numpy/numpy/pull/8566
      - 0015-skip-test_loss_of_precision_longcomplex-test.patch  # [ppc64le]
  {% if blas_impl == "mkl" %}
  # because of the cyclical nature of numpy and mkl_fft/mkl_random, they all need to be built in this one recipe
  - url: https://github.com/IntelPython/mkl_random/archive/v{{mkl_random_version}}.tar.gz
    sha256: 2270ef2834f6552850533aad01500d27c8e056f2cfbdbdb751593000aea1159e
    folder: mkl_random
  - url: https://github.com/IntelPython/mkl_fft/archive/v{{mkl_fft_version}}.tar.gz
    sha256: 3c7ed29e203c5b664ecafb11d767d62f9cae4aa56f9a95737e121192a66673bf
    folder: mkl_fft
  {% endif %}

build:
  number: 0
  skip: True  # [blas_impl == 'openblas' and win]
  force_use_keys:
    - python

outputs:
  # this one has all the actual contents
  - name: numpy-base
    script: install_base.sh   # [unix]
    script: install_base.bat  # [win]
    requirements:
      build:
        - {{ compiler("c") }}
        - {{ compiler("fortran") }}
        # HACK: need this for libquadmath.  Should fix the gcc package
        - libgcc-ng                  # [linux]
      host:
        - cython
        - python
        - setuptools
        - mkl-devel  {{ mkl }}  # [blas_impl == "mkl"]
        - openblas-devel {{ openblas }}  # [blas_impl == "openblas"]
      run:
        - python
    test:
      commands:
        - test -e $SP_DIR/numpy/distutils/site.cfg     # [unix]
        - IF NOT EXIST %SP_DIR%\numpy\distutils\site.cfg exit 1  # [win]

  # devel exists mostly to add the run_exports info.
  - name: numpy-devel
    build:
      run_exports:
        - {{ pin_subpackage('numpy') }}
    requirements:
      host:
        - python
        # these import blas metapackages to ensure consistency with downstream libs that also use blas
        - mkl-devel  {{ mkl }}  # [blas_impl == 'mkl']
        - openblas-devel {{ openblas }}  # [blas_impl == 'openblas']
      run:
        - python
        - {{ pin_subpackage('numpy-base', exact=True) }}

  # metapackage for things that don't use numpy's C interface, or things
  - name: numpy
    requirements:
      build:
        # for runtime alignment
        - {{ compiler('c') }}
        - {{ compiler('fortran') }}
      host:
        - python
        # these import blas metapackages to ensure consistency with downstream libs that also use blas
        - mkl-devel  {{ mkl }}  # [blas_impl == 'mkl']
        - openblas-devel {{ openblas }}  # [blas_impl == 'openblas']
      run:
        - python
        - {{ pin_subpackage('numpy-base', exact=True) }}
        # openblas or mkl runtime included with run_exports
        - {{ pin_subpackage("mkl_fft") }}  # [blas_impl == 'mkl']
        - {{ pin_subpackage("mkl_random") }} # [blas_impl == 'mkl' and (not win or vc>=14)]

    test:
      script: numpy_test.py
      requires:
        - pytest
        - {{ compiler('c') }}
        - {{ compiler('fortran') }}
        - nomkl  # [x86 and blas_impl != 'mkl']
      commands:
        - f2py -h
        - python -c "import numpy; numpy.show_config()"
      imports:
        - numpy
        - numpy.linalg.lapack_lite

    about:
      home: http://numpy.scipy.org/
      license: BSD 3-Clause
      license_file: LICENSE.txt
      summary: 'Array processing for numbers, strings, records, and objects.'
      description: |
        NumPy is the fundamental package needed for scientific computing with Python.
      doc_url: https://docs.scipy.org/doc/numpy-{{ version }}/reference/
      dev_url: https://github.com/numpy/numpy
      dev_source_url: https://github.com/numpy/numpy/tree/master/doc

  {% if blas_impl == "mkl" %}
  - name: mkl_random
    version: {{ mkl_random_version }}
    build:
        number: {{mkl_random_buildnumber}}
        # not compatible with vs2008.
        skip: True  # [blas_impl != "mkl" or (win and vc<14)]
        script: pushd mkl_random && python setup.py config build install --old-and-unmanageable

    requirements:
        build:
          - {{ compiler('c') }}
          - {{ compiler('cxx') }}
        host:
          - python
          - setuptools
          - mkl-devel  {{ mkl }}
          - cython
          - numpy-base  {{ numpy }}
        run:
          - python
          - {{ pin_compatible("numpy-base") }}

    test:
        commands:
          - nosetests -v mkl_random
        requires:
          - nose
          - numpy-base >=1.13
        imports:
          - mkl_random
          - mkl_random.mklrand

    about:
        home: http://github.com/IntelPython/mkl_random
        license: BSD 3-Clause
        license_file: mkl_random/LICENSE.txt
        description:
            NumPy-based implementation of random number generation sampling using Intel (R) Math Kernel Library,
            mirroring numpy.random, but exposing all choices of sampling algorithms available in MKL.
        summary:
            Intel (R) MKL-powered package for sampling from common probability distributions into NumPy arrays.

  - name: mkl_fft
    version: {{ mkl_fft_version }}
    source:
        url: https://github.com/IntelPython/mkl_fft/archive/v{{mkl_fft_version}}.tar.gz
        sha256: 3c7ed29e203c5b664ecafb11d767d62f9cae4aa56f9a95737e121192a66673bf

    build:
      number: {{ mkl_fft_buildnumber }}
      skip: True  # [blas_impl != "mkl"]
      script: pushd mkl_fft && python setup.py build install --single-version-externally-managed --record=record.txt

    requirements:
        build:
          - {{ compiler('c') }}
          - {{ compiler('cxx') }}
        host:
          - python
          - setuptools
          - mkl-devel  {{ mkl }}
          - cython
          - numpy-base  {{ numpy }}
        run:
          - python
          - {{ pin_compatible("numpy-base") }}

    test:
        commands:
          - nosetests -v mkl_fft
        requires:
          - nose
        imports:
          - mkl_fft
          - mkl_fft._numpy_fft
          - mkl_fft._scipy_fft

    about:
        home: http://github.com/IntelPython/mkl_fft
        license: BSD 3-Clause
        license_file: LICENSE.txt
        description:
            NumPy-based implementation of Fast Fourier Transform using Intel (R) Math Kernel Library.
            Supports in-place and out-of-place, 1D and ND complex FFT on arrays of single and double precision
            with arbitrary memory layout, so long as array strides are multiples of its itemsize.
        summary: NumPy-based implementation of Fast Fourier Transform using Intel (R) Math Kernel Library.
  {% endif %}

extra:
  recipe-maintainers:
    - jakirkham
    - msarahan
    - pelson
    - rgommers
    - ocefpaf
