import torch


def eval_BLSTM(model, train_loader, test_loader, device):
    """Evaluates model on provided training and testing set.
       Due to memory limits, must take in data loaders and predict in batches.
       Returns float values (train_acc, test_acc)"""
    
    # Set the model to evaluation mode to ignore non-deterministic effects like dropout
    model.eval()
    train_checks, test_checks = [], []
    
    # Train predict
    for X, y, mask in train_loader:
        X = X.clone().to(device)
        y = y.clone().to(device)
        y_predict = model.predict(X)
        train_checks.append(y[mask] == y_predict[mask])
    train_checks = torch.cat(train_checks).float()
    train_acc = torch.mean(train_checks).cpu().item()
    
    # Test predict
    for X, y, mask in test_loader:
        X = X.clone().to(device)
        y = y.clone().to(device)
        y_predict = model.predict(X)
        test_checks.append(y[mask] == y_predict[mask])
    test_checks = torch.cat(test_checks).float()
    test_acc = torch.mean(test_checks).cpu().item()
    
    return train_acc, test_acc