Skip to content
Permalink
Browse files

feat(tests): add unittest for PCAEncoder

  • Loading branch information...
raccoonliukai committed Sep 5, 2019
1 parent 5a745b1 commit 16fa80bdc2862b3009f0c391d21b2a4ba3a74c08
Showing with 38 additions and 0 deletions.
  1. +30 −0 tests/test_pca_encoder.py
  2. +8 −0 tests/yaml/pca.yml
@@ -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)
@@ -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.
You can’t perform that action at this time.