Skip to content
This repository has been archived by the owner on Feb 22, 2020. It is now read-only.

Commit

Permalink
feat(tests): add unittest for PCAEncoder
Browse files Browse the repository at this point in the history
  • Loading branch information
raccoonliukai committed Sep 5, 2019
1 parent 5a745b1 commit 16fa80b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
30 changes: 30 additions & 0 deletions tests/test_pca_encoder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import os
import unittest
import numpy as np

from gnes.encoder.base import BaseEncoder


class TestPCAEncoder(unittest.TestCase):

def setUp(self):
dirname = os.path.dirname(__file__)
self.dump_path = os.path.join(dirname, 'pca_encoder.bin')
self.yaml_path = os.path.join(dirname, 'yaml', 'pca.yml')
self.test_numeric = np.random.randint(0, 255, (1000, 1024)).astype('float32')

def test_encoding(self):
self.encoder = BaseEncoder.load_yaml(self.yaml_path)
# train before encode to create pca_components
self.encoder.train(self.test_numeric)
vec = self.encoder.encode(self.test_numeric)
self.assertEqual(vec.shape, (1000, 300))
# dump after train with valied pca_components
self.encoder.dump(self.dump_path)
encoder2 = BaseEncoder.load(self.dump_path)
vec = encoder2.encode(self.test_numeric)
self.assertEqual(vec.shape, (1000, 300))

def tearDown(self):
if os.path.exists(self.dump_path):
os.remove(self.dump_path)
8 changes: 8 additions & 0 deletions tests/yaml/pca.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
!PCAEncoder
parameters:
output_dim: 300
gnes_config:
name: pca_encoder
on_gpu: false
work_dir: ./

0 comments on commit 16fa80b

Please sign in to comment.