#!/usr/bin/env python
#
# Pablo Munoz (c) 2018
#
# Example use of fortran wrapper
#
import numpy as np
from fib import *

# Print doc generated by f2py
print(fib.__doc__)

# Use
print(fib(10))
print()

# Use matrix multiplication
N = 100
A = np.eye(N)
B = np.random.rand(N, N)

if not np.testing.assert_array_equal(np.dot(A, B), B):
    print('PYTHON  matrix multiplication test OK')

# Explicit or implicit matrix dimensions
if not np.testing.assert_array_equal(matmul(A, B, N, N, N), B):
    print('FORTRAN OK matrix multiplication explicit dimension test ')

if not np.testing.assert_array_equal(matmul(A, B), B):
    print('FORTRAN OK matrix multiplication implicit dimension test ')

# Transpose
if not np.testing.assert_array_equal(transpose(A), A):
    print('FORTRAN OK matrix identity transpose is itself test ')

if not np.testing.assert_array_equal(transpose(transpose(B)), B):
    print('FORTRAN OK test:: transpose**2 === identity ')

if transpose(np.random.rand(100,200)).shape == (200, 100):
    print('FORTRAN OK transpose shape test ')

# Get shape (do i need to "think transposed" in fortran? Answer is not
# as in getshape1 )
shape = getshape1(np.random.rand(100, 200))
if shape != (100, 200):
    print('getshape1 gives wrong shape')
    print('    expected  (100, 200)')
    print('    getshape1 {}'.format(shape))
else:
    print('FORTRAN OK getshape1 gives correct shape')

shape = getshape2(np.random.rand(100, 200))
if shape != (100, 200):
    print('FORTRAN X  getshape2 gives wrong shape')
    print('    expected  (100, 200)')
    print('    getshape2 {}'.format(shape))
else:
    print('FORTRAN OK getshape2 gives correct shape')
