#!/usr/bin/env python
# (C) 2000 Huaiyu Zhu <hzhu@users.sourceforge.net>. Licence: GPL
# $Id: test_tensor.py,v 1.2 2000/06/22 23:56:15 hzhu Exp $
"""
Test Tensor module
"""
from MatPy.Tensor import *
from MatPy import formats
formats.format = lambda x:"% -5.2g"%x
A = B = Tensor([[[1.,2],[3,4]],[[5,6],[7,8]]])
print A, A.shape
print A[0], A[0].shape
print A[0,1], A[0,1].shape
print A[0,1,1], A[0,1,1].shape
print "-"*40
A[0,0,0] = 9
print A, A.shape
print "-"*40
A = Tensor([[1,2],[3,4]])
print A, A.shape
print "-"*40
A = Tensor([[1,2,3,4]])
print A, A.shape
print "-"*40
A = Tensor([1,2,3,4])
print A, A.shape
print "-"*40
A = Tensor([1])
print A, A.shape
print "-"*40
A = Tensor(1)
print A, A.shape
print "-"*40
A = Tensor([])
print A, A.shape
print "-"*40
from MLab import rand
B[0,0,:] = rand(2)
print B, B.shape
print "========================================================"
print "Testing changing format"
a = MLab.arange(4)/3.
print formats.strF(a)
print formats.reprF(a), "\n", "-"*40
a = MLab.array([a+1, a-1])
formats.formatF = lambda x:"% -7.4g"%x
print formats.strF(a)
print formats.reprF(a), "\n", "-"*40
a = MLab.array([a*4,a+10,a-1])
formats.formatF = lambda x:"% -5.2g"%x
print formats.strF(a)
print formats.reprF(a), "\n", "-"*40
|